1 | #!/bin/bash |
---|
2 | |
---|
3 | ##################################################################### |
---|
4 | ####### Script instalador OpenGnSys |
---|
5 | ####### autor: Luis Guillén <lguillen@unizar.es> |
---|
6 | ##################################################################### |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | #### AVISO: Editar configuración de acceso por defecto. |
---|
11 | #### WARNING: Edit default access configuration. |
---|
12 | MYSQL_ROOT_PASSWORD="passwordroot" # Clave root de MySQL |
---|
13 | OPENGNSYS_DB_USER="usuog" # Usuario de acceso a la base de datos |
---|
14 | OPENGNSYS_DB_PASSWD="passusuog" # Clave de acceso a la base de datos |
---|
15 | OPENGNSYS_CLIENT_PASSWD="og" # Clave de acceso del cliente |
---|
16 | |
---|
17 | |
---|
18 | #### AVISO: NO EDITAR. |
---|
19 | #### WARNING: DO NOT EDIT. |
---|
20 | OPENGNSYS_DATABASE="ogAdmBD" # Nombre de la base datos |
---|
21 | OPENGNSYS_CLIENT_USER="opengnsys" # Usuario del cliente para acceso remoto |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | # Sólo ejecutable por usuario root |
---|
26 | if [ "$(whoami)" != 'root' ]; then |
---|
27 | echo "ERROR: this program must run under root privileges!!" |
---|
28 | exit 1 |
---|
29 | fi |
---|
30 | # Solo se deben aceptar números y letras en la clave de acceso del cliente. |
---|
31 | if [ -n "${OPENGNSYS_CLIENT_PASSWD//[a-zA-Z0-9]/}" ]; then |
---|
32 | echo "ERROR: client password must be alphanumeric, edit installer variables." |
---|
33 | exit 1 |
---|
34 | fi |
---|
35 | |
---|
36 | # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). |
---|
37 | PROGRAMDIR=$(readlink -e $(dirname "$0")) |
---|
38 | OPENGNSYS_SERVER="www.opengnsys.es" |
---|
39 | if [ -d "$PROGRAMDIR/../installer" ]; then |
---|
40 | USESVN=0 |
---|
41 | else |
---|
42 | USESVN=1 |
---|
43 | fi |
---|
44 | SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/" |
---|
45 | |
---|
46 | WORKDIR=/tmp/opengnsys_installer |
---|
47 | mkdir -p $WORKDIR |
---|
48 | |
---|
49 | INSTALL_TARGET=/opt/opengnsys |
---|
50 | LOG_FILE=/tmp/opengnsys_installation.log |
---|
51 | |
---|
52 | # Base de datos |
---|
53 | OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogAdmBD.sql |
---|
54 | |
---|
55 | |
---|
56 | ##################################################################### |
---|
57 | ####### Funciones de configuración |
---|
58 | ##################################################################### |
---|
59 | |
---|
60 | # Generar variables de configuración del instalador |
---|
61 | # Variables globales: |
---|
62 | # - OSDISTRIB, OSCODENAME - datos de la distribución Linux |
---|
63 | # - DEPENDENCIES - array de dependencias que deben estar instaladas |
---|
64 | # - UPDATEPKGLIST, INSTALLPKGS, CHECKPKGS - comandos para gestión de paquetes |
---|
65 | # - APACHEINIT, APACHECFGDIR, APACHEUSER, APACHEGROUP - arranque y configuración de Apache |
---|
66 | # - ENABLEMOD, ENABLESITE - habilitar módulo Apache y sitio web |
---|
67 | # - DHCPINIT, DHCPCFGDIR - arranque y configuración de DHCP |
---|
68 | # - SAMBAINIT, SAMBACFGDIR - arranque y configuración de Samba |
---|
69 | # - TFTPCFGDIR - configuración de TFTP |
---|
70 | function autoConfigure() |
---|
71 | { |
---|
72 | # Detectar sistema operativo del servidor (debe soportar LSB). |
---|
73 | OSDISTRIB=$(lsb_release -is 2>/dev/null) |
---|
74 | OSCODENAME=$(lsb_release -cs 2>/dev/null) |
---|
75 | |
---|
76 | # Configuración según la distribución de Linux. |
---|
77 | case "$OSDISTRIB" in |
---|
78 | Ubuntu|Debian|LinuxMint) |
---|
79 | DEPENDENCIES=( subversion apache2 php5 libapache2-mod-php5 mysql-server php5-mysql isc-dhcp-server bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential g++-multilib libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent samba unzip netpipes debootstrap schroot squashfs-tools ) |
---|
80 | UPDATEPKGLIST="apt-get update" |
---|
81 | INSTALLPKG="apt-get -y install --force-yes" |
---|
82 | CHECKPKG="dpkg -s \$package 2>/dev/null | grep Status | grep -qw install" |
---|
83 | APACHEINIT=/etc/init.d/apache2 |
---|
84 | APACHECFGDIR=/etc/apache2 |
---|
85 | APACHEUSER="www-data" |
---|
86 | APACHEGROUP="www-data" |
---|
87 | ENABLEMOD="a2enmod" |
---|
88 | ENABLESITE="a2ensite" |
---|
89 | DHCPINIT=/etc/init.d/isc-dhcp-server |
---|
90 | DHCPCFGDIR=/etc/dhcp |
---|
91 | SAMBAINIT=/etc/init.d/smbd |
---|
92 | SAMBACFGDIR=/etc/samba |
---|
93 | TFTPCFGDIR=/var/lib/tftpboot |
---|
94 | ;; |
---|
95 | Fedora) |
---|
96 | DEPENDENCIES=( subversion httpd mod_ssl php mysql-server mysql-devel mysql-devel.i686 php-mysql dhcp bittorrent tftp-server syslinux binutils gcc gcc-c++ glibc-devel.i686 make wget doxygen graphviz python-tornado ctorrent samba unzip NetPIPE debootstrap schroot squashfs-tools ) # TODO comprobar paquetes |
---|
97 | EXTRADEPS=( ftp://ftp.altlinux.org/pub/distributions/ALTLinux/5.1/branch/files/i586/RPMS/netpipes-4.2-alt1.i586.rpm ) |
---|
98 | UPDATEPKGLIST="" |
---|
99 | INSTALLPKG="yum install -y" |
---|
100 | INSTALLEXTRA="rpm -ihv" |
---|
101 | CHECKPKG="rpm -q \$package" |
---|
102 | APACHEINIT=/etc/init.d/httpd |
---|
103 | APACHECFGDIR=/etc/httpd/conf.d |
---|
104 | APACHEUSER="apache" |
---|
105 | APACHEGROUP="apache" |
---|
106 | DHCPINIT=/etc/init.d/dhcpd |
---|
107 | DHCPCFGDIR=/etc/dhcp |
---|
108 | SAMBAINIT=/etc/init.d/smb |
---|
109 | SAMBACFGDIR=/etc/samba |
---|
110 | TFTPCFGDIR=/var/lib/tftpboot |
---|
111 | ;; |
---|
112 | "") echo "ERROR: Unknown Linux distribution, please install \"lsb_release\" command." |
---|
113 | exit 1 ;; |
---|
114 | *) echo "ERROR: Distribution not supported by OpenGnSys." |
---|
115 | exit 1 ;; |
---|
116 | esac |
---|
117 | } |
---|
118 | |
---|
119 | # Modificar variables de configuración tras instalar paquetes del sistema. |
---|
120 | function autoConfigurePost() |
---|
121 | { |
---|
122 | [ -e $SAMBAINIT ] || SAMBAINIT=/etc/init.d/samba # Debian 6 |
---|
123 | [ -e $TFTPCFGDIR ] || TFTPCFGDIR=/srv/tftp # Debian 6 |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | # Cargar lista de paquetes del sistema y actualizar algunas variables de configuración |
---|
128 | # dependiendo de la versión instalada. |
---|
129 | function updatePackageList() |
---|
130 | { |
---|
131 | local DHCPVERSION |
---|
132 | |
---|
133 | # Si es necesario, actualizar la lista de paquetes disponibles. |
---|
134 | [ -n "$UPDATEPKGLIST" ] && eval $UPDATEPKGLIST |
---|
135 | |
---|
136 | # Configuración personallizada de algunos paquetes. |
---|
137 | case "$OSDISTRIB" in |
---|
138 | Ubuntu|LinuxMint) # Postconfiguación personalizada para Ubuntu. |
---|
139 | # Configuración para DHCP v3. |
---|
140 | DHCPVERSION=$(apt-cache show $(apt-cache pkgnames|egrep "dhcp.?-server$") | \ |
---|
141 | awk '/Version/ {print substr($2,1,1);}' | \ |
---|
142 | sort -n | tail -1) |
---|
143 | if [ $DHCPVERSION = 3 ]; then |
---|
144 | DEPENDENCIES=( ${DEPENDENCIES[@]/isc-dhcp-server/dhcp3-server} ) |
---|
145 | DHCPINIT=/etc/init.d/dhcp3-server |
---|
146 | DHCPCFGDIR=/etc/dhcp3 |
---|
147 | fi |
---|
148 | ;; |
---|
149 | esac |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | ##################################################################### |
---|
154 | ####### Algunas funciones útiles de propósito general: |
---|
155 | ##################################################################### |
---|
156 | |
---|
157 | function getDateTime() |
---|
158 | { |
---|
159 | date "+%Y%m%d-%H%M%S" |
---|
160 | } |
---|
161 | |
---|
162 | # Escribe a fichero y muestra por pantalla |
---|
163 | function echoAndLog() |
---|
164 | { |
---|
165 | local DATETIME=`getDateTime` |
---|
166 | echo "$1" |
---|
167 | echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
168 | } |
---|
169 | |
---|
170 | # Escribe a fichero y muestra mensaje de error |
---|
171 | function errorAndLog() |
---|
172 | { |
---|
173 | local DATETIME=`getDateTime` |
---|
174 | echo "ERROR: $1" |
---|
175 | echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
176 | } |
---|
177 | |
---|
178 | # Comprueba si el elemento pasado en $2 está en el array $1 |
---|
179 | function isInArray() |
---|
180 | { |
---|
181 | if [ $# -ne 2 ]; then |
---|
182 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
183 | exit 1 |
---|
184 | fi |
---|
185 | |
---|
186 | local deps |
---|
187 | local is_in_array=1 |
---|
188 | local element="$2" |
---|
189 | |
---|
190 | echoAndLog "${FUNCNAME}(): checking if $2 is in $1" |
---|
191 | eval "deps=( \"\${$1[@]}\" )" |
---|
192 | |
---|
193 | # Copia local del array del parámetro 1. |
---|
194 | for (( i = 0 ; i < ${#deps[@]} ; i++ )); do |
---|
195 | if [ "${deps[$i]}" = "${element}" ]; then |
---|
196 | echoAndLog "isInArray(): $element found in array" |
---|
197 | is_in_array=0 |
---|
198 | fi |
---|
199 | done |
---|
200 | |
---|
201 | if [ $is_in_array -ne 0 ]; then |
---|
202 | echoAndLog "${FUNCNAME}(): $element NOT found in array" |
---|
203 | fi |
---|
204 | |
---|
205 | return $is_in_array |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | ##################################################################### |
---|
210 | ####### Funciones de manejo de paquetes Debian |
---|
211 | ##################################################################### |
---|
212 | |
---|
213 | function checkPackage() |
---|
214 | { |
---|
215 | package=$1 |
---|
216 | if [ -z $package ]; then |
---|
217 | errorAndLog "${FUNCNAME}(): parameter required" |
---|
218 | exit 1 |
---|
219 | fi |
---|
220 | echoAndLog "${FUNCNAME}(): checking if package $package exists" |
---|
221 | eval $CHECKPKG |
---|
222 | if [ $? -eq 0 ]; then |
---|
223 | echoAndLog "${FUNCNAME}(): package $package exists" |
---|
224 | return 0 |
---|
225 | else |
---|
226 | echoAndLog "${FUNCNAME}(): package $package doesn't exists" |
---|
227 | return 1 |
---|
228 | fi |
---|
229 | } |
---|
230 | |
---|
231 | # Recibe array con dependencias |
---|
232 | # por referencia deja un array con las dependencias no resueltas |
---|
233 | # devuelve 1 si hay alguna dependencia no resuelta |
---|
234 | function checkDependencies() |
---|
235 | { |
---|
236 | if [ $# -ne 2 ]; then |
---|
237 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
238 | exit 1 |
---|
239 | fi |
---|
240 | |
---|
241 | echoAndLog "${FUNCNAME}(): checking dependences" |
---|
242 | uncompletedeps=0 |
---|
243 | |
---|
244 | # copia local del array del parametro 1 |
---|
245 | local deps |
---|
246 | eval "deps=( \"\${$1[@]}\" )" |
---|
247 | |
---|
248 | declare -a local_notinstalled |
---|
249 | |
---|
250 | for (( i = 0 ; i < ${#deps[@]} ; i++ )) |
---|
251 | do |
---|
252 | checkPackage ${deps[$i]} |
---|
253 | if [ $? -ne 0 ]; then |
---|
254 | local_notinstalled[$uncompletedeps]=$package |
---|
255 | let uncompletedeps=uncompletedeps+1 |
---|
256 | fi |
---|
257 | done |
---|
258 | |
---|
259 | # relleno el array especificado en $2 por referencia |
---|
260 | for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ )) |
---|
261 | do |
---|
262 | eval "${2}[$i]=${local_notinstalled[$i]}" |
---|
263 | done |
---|
264 | |
---|
265 | # retorna el numero de paquetes no resueltos |
---|
266 | echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps" |
---|
267 | return $uncompletedeps |
---|
268 | } |
---|
269 | |
---|
270 | # Recibe un array con las dependencias y lo instala |
---|
271 | function installDependencies() |
---|
272 | { |
---|
273 | if [ $# -ne 1 ]; then |
---|
274 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
275 | exit 1 |
---|
276 | fi |
---|
277 | echoAndLog "${FUNCNAME}(): installing uncompleted dependencies" |
---|
278 | |
---|
279 | # copia local del array del parametro 1 |
---|
280 | local deps |
---|
281 | eval "deps=( \"\${$1[@]}\" )" |
---|
282 | |
---|
283 | local string_deps="" |
---|
284 | for (( i = 0 ; i < ${#deps[@]} ; i++ )) |
---|
285 | do |
---|
286 | string_deps="$string_deps ${deps[$i]}" |
---|
287 | done |
---|
288 | |
---|
289 | if [ -z "${string_deps}" ]; then |
---|
290 | errorAndLog "${FUNCNAME}(): array of dependeces is empty" |
---|
291 | exit 1 |
---|
292 | fi |
---|
293 | |
---|
294 | OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND |
---|
295 | export DEBIAN_FRONTEND=noninteractive |
---|
296 | |
---|
297 | echoAndLog "${FUNCNAME}(): now $string_deps will be installed" |
---|
298 | eval $INSTALLPKG $string_deps |
---|
299 | if [ $? -ne 0 ]; then |
---|
300 | errorAndLog "${FUNCNAME}(): error installing dependencies" |
---|
301 | return 1 |
---|
302 | fi |
---|
303 | |
---|
304 | DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND |
---|
305 | echoAndLog "${FUNCNAME}(): dependencies installed" |
---|
306 | } |
---|
307 | |
---|
308 | # Hace un backup del fichero pasado por parámetro |
---|
309 | # deja un -last y uno para el día |
---|
310 | function backupFile() |
---|
311 | { |
---|
312 | if [ $# -ne 1 ]; then |
---|
313 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
314 | exit 1 |
---|
315 | fi |
---|
316 | |
---|
317 | local file="$1" |
---|
318 | local dateymd=`date +%Y%m%d` |
---|
319 | |
---|
320 | if [ ! -f "$file" ]; then |
---|
321 | errorAndLog "${FUNCNAME}(): file $file doesn't exists" |
---|
322 | return 1 |
---|
323 | fi |
---|
324 | |
---|
325 | echoAndLog "${FUNCNAME}(): making $file backup" |
---|
326 | |
---|
327 | # realiza una copia de la última configuración como last |
---|
328 | cp -a "$file" "${file}-LAST" |
---|
329 | |
---|
330 | # si para el día no hay backup lo hace, sino no |
---|
331 | if [ ! -f "${file}-${dateymd}" ]; then |
---|
332 | cp -a "$file" "${file}-${dateymd}" |
---|
333 | fi |
---|
334 | |
---|
335 | echoAndLog "${FUNCNAME}(): $file backup success" |
---|
336 | } |
---|
337 | |
---|
338 | ##################################################################### |
---|
339 | ####### Funciones para el manejo de bases de datos |
---|
340 | ##################################################################### |
---|
341 | |
---|
342 | # This function set password to root |
---|
343 | function mysqlSetRootPassword() |
---|
344 | { |
---|
345 | if [ $# -ne 1 ]; then |
---|
346 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
347 | exit 1 |
---|
348 | fi |
---|
349 | |
---|
350 | local root_mysql="$1" |
---|
351 | echoAndLog "${FUNCNAME}(): setting root password in MySQL server" |
---|
352 | mysqladmin -u root password "$root_mysql" |
---|
353 | if [ $? -ne 0 ]; then |
---|
354 | errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server" |
---|
355 | return 1 |
---|
356 | fi |
---|
357 | echoAndLog "${FUNCNAME}(): root password saved!" |
---|
358 | return 0 |
---|
359 | } |
---|
360 | |
---|
361 | # Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente |
---|
362 | function mysqlGetRootPassword() |
---|
363 | { |
---|
364 | local pass_mysql |
---|
365 | local pass_mysql2 |
---|
366 | # Comprobar si MySQL está instalado con la clave de root por defecto. |
---|
367 | if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then |
---|
368 | echoAndLog "${FUNCNAME}(): Using default mysql root password." |
---|
369 | else |
---|
370 | stty -echo |
---|
371 | echo "There is a MySQL service already installed." |
---|
372 | read -p "Enter MySQL root password: " pass_mysql |
---|
373 | echo "" |
---|
374 | read -p "Confrim password:" pass_mysql2 |
---|
375 | echo "" |
---|
376 | stty echo |
---|
377 | if [ "$pass_mysql" == "$pass_mysql2" ] ;then |
---|
378 | MYSQL_ROOT_PASSWORD="$pass_mysql" |
---|
379 | return 0 |
---|
380 | else |
---|
381 | echo "The keys don't match. Do not configure the server's key," |
---|
382 | echo "transactions in the database will give error." |
---|
383 | return 1 |
---|
384 | fi |
---|
385 | fi |
---|
386 | } |
---|
387 | |
---|
388 | # comprueba si puede conectar con mysql con el usuario root |
---|
389 | function mysqlTestConnection() |
---|
390 | { |
---|
391 | if [ $# -ne 1 ]; then |
---|
392 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
393 | exit 1 |
---|
394 | fi |
---|
395 | |
---|
396 | local root_password="${1}" |
---|
397 | echoAndLog "${FUNCNAME}(): checking connection to mysql..." |
---|
398 | echo "" | mysql -uroot -p"${root_password}" |
---|
399 | if [ $? -ne 0 ]; then |
---|
400 | errorAndLog "${FUNCNAME}(): connection to mysql failed, check root password and if daemon is running!" |
---|
401 | return 1 |
---|
402 | else |
---|
403 | echoAndLog "${FUNCNAME}(): connection success" |
---|
404 | return 0 |
---|
405 | fi |
---|
406 | } |
---|
407 | |
---|
408 | # comprueba si la base de datos existe |
---|
409 | function mysqlDbExists() |
---|
410 | { |
---|
411 | if [ $# -ne 2 ]; then |
---|
412 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
413 | exit 1 |
---|
414 | fi |
---|
415 | |
---|
416 | local root_password="${1}" |
---|
417 | local database=$2 |
---|
418 | echoAndLog "${FUNCNAME}(): checking if $database exists..." |
---|
419 | echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$" |
---|
420 | if [ $? -ne 0 ]; then |
---|
421 | echoAndLog "${FUNCNAME}():database $database doesn't exists" |
---|
422 | return 1 |
---|
423 | else |
---|
424 | echoAndLog "${FUNCNAME}():database $database exists" |
---|
425 | return 0 |
---|
426 | fi |
---|
427 | } |
---|
428 | |
---|
429 | function mysqlCheckDbIsEmpty() |
---|
430 | { |
---|
431 | if [ $# -ne 2 ]; then |
---|
432 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
433 | exit 1 |
---|
434 | fi |
---|
435 | |
---|
436 | local root_password="${1}" |
---|
437 | local database=$2 |
---|
438 | echoAndLog "${FUNCNAME}(): checking if $database is empty..." |
---|
439 | num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l` |
---|
440 | if [ $? -ne 0 ]; then |
---|
441 | errorAndLog "${FUNCNAME}(): error executing query, check database and root password" |
---|
442 | exit 1 |
---|
443 | fi |
---|
444 | |
---|
445 | if [ $num_tablas -eq 0 ]; then |
---|
446 | echoAndLog "${FUNCNAME}():database $database is empty" |
---|
447 | return 0 |
---|
448 | else |
---|
449 | echoAndLog "${FUNCNAME}():database $database has tables" |
---|
450 | return 1 |
---|
451 | fi |
---|
452 | |
---|
453 | } |
---|
454 | |
---|
455 | |
---|
456 | function mysqlImportSqlFileToDb() |
---|
457 | { |
---|
458 | if [ $# -ne 3 ]; then |
---|
459 | errorAndLog "${FNCNAME}(): invalid number of parameters" |
---|
460 | exit 1 |
---|
461 | fi |
---|
462 | |
---|
463 | local root_password="$1" |
---|
464 | local database="$2" |
---|
465 | local sqlfile="$3" |
---|
466 | local tmpfile=$(mktemp) |
---|
467 | local i=0 |
---|
468 | local dev="" |
---|
469 | local status |
---|
470 | |
---|
471 | if [ ! -f $sqlfile ]; then |
---|
472 | errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!" |
---|
473 | return 1 |
---|
474 | fi |
---|
475 | |
---|
476 | echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..." |
---|
477 | chmod 600 $tmpfile |
---|
478 | for dev in ${DEVICE[*]}; do |
---|
479 | if [ "${DEVICE[i]}" == "$DEFAULTDEV" ]; then |
---|
480 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
481 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
482 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
483 | $sqlfile > $tmpfile |
---|
484 | fi |
---|
485 | let i++ |
---|
486 | done |
---|
487 | mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $tmpfile |
---|
488 | status=$? |
---|
489 | rm -f $tmpfile |
---|
490 | if [ $status -ne 0 ]; then |
---|
491 | errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database" |
---|
492 | return 1 |
---|
493 | fi |
---|
494 | echoAndLog "${FUNCNAME}(): file imported to database $database" |
---|
495 | return 0 |
---|
496 | } |
---|
497 | |
---|
498 | # Crea la base de datos |
---|
499 | function mysqlCreateDb() |
---|
500 | { |
---|
501 | if [ $# -ne 2 ]; then |
---|
502 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
503 | exit 1 |
---|
504 | fi |
---|
505 | |
---|
506 | local root_password="${1}" |
---|
507 | local database=$2 |
---|
508 | |
---|
509 | echoAndLog "${FUNCNAME}(): creating database..." |
---|
510 | mysqladmin -u root --password="${root_password}" create $database |
---|
511 | if [ $? -ne 0 ]; then |
---|
512 | errorAndLog "${FUNCNAME}(): error while creating database $database" |
---|
513 | return 1 |
---|
514 | fi |
---|
515 | echoAndLog "${FUNCNAME}(): database $database created" |
---|
516 | return 0 |
---|
517 | } |
---|
518 | |
---|
519 | |
---|
520 | function mysqlCheckUserExists() |
---|
521 | { |
---|
522 | if [ $# -ne 2 ]; then |
---|
523 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
524 | exit 1 |
---|
525 | fi |
---|
526 | |
---|
527 | local root_password="${1}" |
---|
528 | local userdb=$2 |
---|
529 | |
---|
530 | echoAndLog "${FUNCNAME}(): checking if $userdb exists..." |
---|
531 | echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user |
---|
532 | if [ $? -ne 0 ]; then |
---|
533 | echoAndLog "${FUNCNAME}(): user doesn't exists" |
---|
534 | return 1 |
---|
535 | else |
---|
536 | echoAndLog "${FUNCNAME}(): user already exists" |
---|
537 | return 0 |
---|
538 | fi |
---|
539 | |
---|
540 | } |
---|
541 | |
---|
542 | # Crea un usuario administrativo para la base de datos |
---|
543 | function mysqlCreateAdminUserToDb() |
---|
544 | { |
---|
545 | if [ $# -ne 4 ]; then |
---|
546 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
547 | exit 1 |
---|
548 | fi |
---|
549 | |
---|
550 | local root_password=$1 |
---|
551 | local database=$2 |
---|
552 | local userdb=$3 |
---|
553 | local passdb=$4 |
---|
554 | |
---|
555 | echoAndLog "${FUNCNAME}(): creating admin user ${userdb} to database ${database}" |
---|
556 | |
---|
557 | cat > $WORKDIR/create_${database}.sql <<EOF |
---|
558 | GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ; |
---|
559 | GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ; |
---|
560 | FLUSH PRIVILEGES ; |
---|
561 | EOF |
---|
562 | mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql |
---|
563 | if [ $? -ne 0 ]; then |
---|
564 | errorAndLog "${FUNCNAME}(): error while creating user in mysql" |
---|
565 | rm -f $WORKDIR/create_${database}.sql |
---|
566 | return 1 |
---|
567 | else |
---|
568 | echoAndLog "${FUNCNAME}(): user created ok" |
---|
569 | rm -f $WORKDIR/create_${database}.sql |
---|
570 | return 0 |
---|
571 | fi |
---|
572 | } |
---|
573 | |
---|
574 | |
---|
575 | ##################################################################### |
---|
576 | ####### Funciones para el manejo de Subversion |
---|
577 | ##################################################################### |
---|
578 | |
---|
579 | function svnExportCode() |
---|
580 | { |
---|
581 | if [ $# -ne 1 ]; then |
---|
582 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
583 | exit 1 |
---|
584 | fi |
---|
585 | |
---|
586 | local url="$1" |
---|
587 | |
---|
588 | echoAndLog "${FUNCNAME}(): downloading subversion code..." |
---|
589 | |
---|
590 | svn export --force "$url" opengnsys |
---|
591 | if [ $? -ne 0 ]; then |
---|
592 | errorAndLog "${FUNCNAME}(): error getting OpenGnSys code from $url" |
---|
593 | return 1 |
---|
594 | fi |
---|
595 | echoAndLog "${FUNCNAME}(): subversion code downloaded" |
---|
596 | return 0 |
---|
597 | } |
---|
598 | |
---|
599 | |
---|
600 | ############################################################ |
---|
601 | ### Detectar red |
---|
602 | ############################################################ |
---|
603 | |
---|
604 | # Comprobar si existe conexión. |
---|
605 | function checkNetworkConnection() |
---|
606 | { |
---|
607 | OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"} |
---|
608 | wget --spider -q $OPENGNSYS_SERVER |
---|
609 | } |
---|
610 | |
---|
611 | # Obtener los parámetros de red de la interfaz por defecto. |
---|
612 | function getNetworkSettings() |
---|
613 | { |
---|
614 | # Arrays globales definidas: |
---|
615 | # - DEVICE: nombres de dispositivos de red activos. |
---|
616 | # - SERVERIP: IPs locales del servidor. |
---|
617 | # - NETIP: IPs de redes. |
---|
618 | # - NETMASK: máscaras de red. |
---|
619 | # - NETBROAD: IPs de difusión de redes. |
---|
620 | # - ROUTERIP: IPs de routers. |
---|
621 | # Otras variables globales: |
---|
622 | # - DEFAULTDEV: dispositivo de red por defecto. |
---|
623 | # - DNSIP: IP del servidor DNS principal. |
---|
624 | |
---|
625 | local i=0 |
---|
626 | local dev="" |
---|
627 | |
---|
628 | echoAndLog "${FUNCNAME}(): Detecting network parameters." |
---|
629 | DEVICE=( $(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}') ) |
---|
630 | if [ -z "$DEVICE" ]; then |
---|
631 | errorAndLog "${FUNCNAME}(): Network devices not detected." |
---|
632 | exit 1 |
---|
633 | fi |
---|
634 | for dev in ${DEVICE[*]}; do |
---|
635 | SERVERIP[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}') |
---|
636 | if [ -n "${SERVERIP[i]}" ]; then |
---|
637 | NETMASK[i]=$(LANG=C ifconfig $dev | awk '/Mask/ {sub(/.*:/,"",$4); print $4}') |
---|
638 | NETBROAD[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {print ($6)}') |
---|
639 | NETIP[i]=$(netstat -nr | awk -v d="$dev" '$1!~/0\.0\.0\.0/&&$8==d {if (n=="") n=$1} END {print n}') |
---|
640 | ROUTERIP[i]=$(netstat -nr | awk -v d="$dev" '$1~/0\.0\.0\.0/&&$8==d {print $2}') |
---|
641 | DEFAULTDEV=${DEFAULTDEV:-"$dev"} |
---|
642 | let i++ |
---|
643 | fi |
---|
644 | done |
---|
645 | DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1) |
---|
646 | if [ -z "${NETIP}[*]" -o -z "${NETMASK[*]}" ]; then |
---|
647 | errorAndLog "${FUNCNAME}(): Network not detected." |
---|
648 | exit 1 |
---|
649 | fi |
---|
650 | |
---|
651 | # Variables de ejecución de Apache |
---|
652 | # - APACHE_RUN_USER |
---|
653 | # - APACHE_RUN_GROUP |
---|
654 | if [ -f $APACHECFGDIR/envvars ]; then |
---|
655 | source $APACHECFGDIR/envvars |
---|
656 | fi |
---|
657 | APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"} |
---|
658 | APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"} |
---|
659 | |
---|
660 | echoAndLog "${FUNCNAME}(): Default network device: $DEFAULTDEV." |
---|
661 | } |
---|
662 | |
---|
663 | |
---|
664 | ############################################################ |
---|
665 | ### Esqueleto para el Servicio pxe y contenedor tftpboot ### |
---|
666 | ############################################################ |
---|
667 | |
---|
668 | function tftpConfigure() |
---|
669 | { |
---|
670 | echoAndLog "${FUNCNAME}(): Configuring TFTP service." |
---|
671 | # reiniciamos demonio internet ????? porque ???? |
---|
672 | /etc/init.d/openbsd-inetd start |
---|
673 | |
---|
674 | # preparacion contenedor tftpboot |
---|
675 | cp -a /usr/lib/syslinux/ $TFTPCFGDIR/syslinux |
---|
676 | cp -a /usr/lib/syslinux/pxelinux.0 $TFTPCFGDIR |
---|
677 | # prepamos el directorio de la configuracion de pxe |
---|
678 | mkdir -p $TFTPCFGDIR/pxelinux.cfg |
---|
679 | cat > $TFTPCFGDIR/pxelinux.cfg/default <<EOF |
---|
680 | DEFAULT syslinux/vesamenu.c32 |
---|
681 | MENU TITLE Aplicacion GNSYS |
---|
682 | |
---|
683 | LABEL 1 |
---|
684 | MENU LABEL 1 |
---|
685 | KERNEL syslinux/chain.c32 |
---|
686 | APPEND hd0 |
---|
687 | |
---|
688 | PROMPT 0 |
---|
689 | TIMEOUT 10 |
---|
690 | EOF |
---|
691 | # comprobamos el servicio tftp |
---|
692 | sleep 1 |
---|
693 | testPxe |
---|
694 | } |
---|
695 | |
---|
696 | function testPxe () |
---|
697 | { |
---|
698 | echoAndLog "${FUNCNAME}(): Checking TFTP service... please wait." |
---|
699 | cd /tmp |
---|
700 | tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echoAndLog "TFTP service is OK." || errorAndLog "TFTP service is down." |
---|
701 | cd / |
---|
702 | } |
---|
703 | |
---|
704 | |
---|
705 | ######################################################################## |
---|
706 | ## Configuracion servicio NFS |
---|
707 | ######################################################################## |
---|
708 | |
---|
709 | # Configurar servicio NFS. |
---|
710 | # ADVERTENCIA: usa variables globales NETIP y NETMASK! |
---|
711 | function nfsConfigure() |
---|
712 | { |
---|
713 | echoAndLog "${FUNCNAME}(): Config nfs server." |
---|
714 | backupFile /etc/exports |
---|
715 | |
---|
716 | nfsAddExport $INSTALL_TARGET/client ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync |
---|
717 | if [ $? -ne 0 ]; then |
---|
718 | errorAndLog "${FUNCNAME}(): error while adding NFS client config" |
---|
719 | return 1 |
---|
720 | fi |
---|
721 | |
---|
722 | nfsAddExport $INSTALL_TARGET/images ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync,crossmnt |
---|
723 | if [ $? -ne 0 ]; then |
---|
724 | errorAndLog "${FUNCNAME}(): error while adding NFS images config" |
---|
725 | return 1 |
---|
726 | fi |
---|
727 | |
---|
728 | nfsAddExport $INSTALL_TARGET/log/clients ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync |
---|
729 | if [ $? -ne 0 ]; then |
---|
730 | errorAndLog "${FUNCNAME}(): error while adding logging client config" |
---|
731 | return 1 |
---|
732 | fi |
---|
733 | |
---|
734 | nfsAddExport $INSTALL_TARGET/tftpboot ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync |
---|
735 | if [ $? -ne 0 ]; then |
---|
736 | errorAndLog "${FUNCNAME}(): error while adding second filesystem for the PXE ogclient" |
---|
737 | return 1 |
---|
738 | fi |
---|
739 | |
---|
740 | /etc/init.d/nfs-kernel-server restart |
---|
741 | exportfs -va |
---|
742 | if [ $? -ne 0 ]; then |
---|
743 | errorAndLog "${FUNCNAME}(): error while configure exports" |
---|
744 | return 1 |
---|
745 | fi |
---|
746 | |
---|
747 | echoAndLog "${FUNCNAME}(): Added NFS configuration to file \"/etc/exports\"." |
---|
748 | return 0 |
---|
749 | } |
---|
750 | |
---|
751 | |
---|
752 | # Añadir entrada en fichero de configuración del servidor NFS. |
---|
753 | # Ejemplos: |
---|
754 | #nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0:ro,no_subtree_check,no_root_squash,sync |
---|
755 | #nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0 |
---|
756 | #nfsAddExport /opt/opengnsys 80.20.2.1:ro 192.123.32.2:rw |
---|
757 | function nfsAddExport() |
---|
758 | { |
---|
759 | if [ $# -lt 2 ]; then |
---|
760 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
761 | exit 1 |
---|
762 | fi |
---|
763 | if [ ! -f /etc/exports ]; then |
---|
764 | errorAndLog "${FUNCNAME}(): /etc/exports don't exists" |
---|
765 | return 1 |
---|
766 | fi |
---|
767 | |
---|
768 | local export="$1" |
---|
769 | local contador=0 |
---|
770 | local cadenaexport |
---|
771 | |
---|
772 | grep "^$export" /etc/exports > /dev/null |
---|
773 | if [ $? -eq 0 ]; then |
---|
774 | echoAndLog "${FUNCNAME}(): $export exists in /etc/exports, omiting" |
---|
775 | return 0 |
---|
776 | fi |
---|
777 | |
---|
778 | cadenaexport="${export}" |
---|
779 | for parametro in $*; do |
---|
780 | if [ $contador -gt 0 ]; then |
---|
781 | host=`echo $parametro | awk -F: '{print $1}'` |
---|
782 | options=`echo $parametro | awk -F: '{print $2}'` |
---|
783 | if [ "${host}" == "" ]; then |
---|
784 | errorAndLog "${FUNCNAME}(): host can't be empty" |
---|
785 | return 1 |
---|
786 | fi |
---|
787 | cadenaexport="${cadenaexport}\t${host}" |
---|
788 | |
---|
789 | if [ "${options}" != "" ]; then |
---|
790 | cadenaexport="${cadenaexport}(${options})" |
---|
791 | fi |
---|
792 | fi |
---|
793 | let contador=contador+1 |
---|
794 | done |
---|
795 | |
---|
796 | echo -en "$cadenaexport\n" >> /etc/exports |
---|
797 | |
---|
798 | echoAndLog "${FUNCNAME}(): add $export to /etc/exports" |
---|
799 | return 0 |
---|
800 | } |
---|
801 | |
---|
802 | |
---|
803 | ######################################################################## |
---|
804 | ## Configuracion servicio Samba |
---|
805 | ######################################################################## |
---|
806 | |
---|
807 | # Configurar servicios Samba. |
---|
808 | function smbConfigure() |
---|
809 | { |
---|
810 | echoAndLog "${FUNCNAME}(): Configuring Samba service." |
---|
811 | |
---|
812 | backupFile $SAMBACFGDIR/smb.conf |
---|
813 | |
---|
814 | # Copiar plantailla de recursos para OpenGnSys |
---|
815 | sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ |
---|
816 | $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf |
---|
817 | # Configurar y recargar Samba" |
---|
818 | perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnSys Samba Server/; s/^\; *include \=.*$/ include \= ${SAMBACFGDIR//\//\\/}\/smb-og.conf/" $SAMBACFGDIR/smb.conf |
---|
819 | $SAMBAINIT restart |
---|
820 | if [ $? -ne 0 ]; then |
---|
821 | errorAndLog "${FUNCNAME}(): error while configure Samba" |
---|
822 | return 1 |
---|
823 | fi |
---|
824 | # Crear clave para usuario de acceso a los recursos. |
---|
825 | echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | smbpasswd -a -s $OPENGNSYS_CLIENT_USER |
---|
826 | |
---|
827 | echoAndLog "${FUNCNAME}(): Added Samba configuration." |
---|
828 | return 0 |
---|
829 | } |
---|
830 | |
---|
831 | |
---|
832 | ######################################################################## |
---|
833 | ## Configuracion servicio DHCP |
---|
834 | ######################################################################## |
---|
835 | |
---|
836 | # Configurar servicios DHCP. |
---|
837 | function dhcpConfigure() |
---|
838 | { |
---|
839 | echoAndLog "${FUNCNAME}(): Sample DHCP configuration." |
---|
840 | |
---|
841 | local errcode=0 |
---|
842 | local i=0 |
---|
843 | local dev="" |
---|
844 | |
---|
845 | backupFile $DHCPCFGDIR/dhcpd.conf |
---|
846 | for dev in ${DEVICE[*]}; do |
---|
847 | if [ -n "${SERVERIP[i]}" ]; then |
---|
848 | backupFile $DHCPCFGDIR/dhcpd-$dev.conf |
---|
849 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
850 | -e "s/NETIP/${NETIP[i]}/g" \ |
---|
851 | -e "s/NETMASK/${NETMASK[i]}/g" \ |
---|
852 | -e "s/NETBROAD/${NETBROAD[i]}/g" \ |
---|
853 | -e "s/ROUTERIP/${ROUTERIP[i]}/g" \ |
---|
854 | -e "s/DNSIP/$DNSIP/g" \ |
---|
855 | $WORKDIR/opengnsys/server/etc/dhcpd.conf.tmpl > $DHCPCFGDIR/dhcpd-$dev.conf || errcode=1 |
---|
856 | fi |
---|
857 | let i++ |
---|
858 | done |
---|
859 | if [ $errcode -ne 0 ]; then |
---|
860 | errorAndLog "${FUNCNAME}(): error while configuring DHCP server" |
---|
861 | return 1 |
---|
862 | fi |
---|
863 | ln -f $DHCPCFGDIR/dhcpd-$DEFAULTDEV.conf $DHCPCFGDIR/dhcpd.conf |
---|
864 | $DHCPINIT restart |
---|
865 | echoAndLog "${FUNCNAME}(): Sample DHCP configured in \"$DHCPCFGDIR\"." |
---|
866 | return 0 |
---|
867 | } |
---|
868 | |
---|
869 | |
---|
870 | ##################################################################### |
---|
871 | ####### Funciones específicas de la instalación de Opengnsys |
---|
872 | ##################################################################### |
---|
873 | |
---|
874 | # Copiar ficheros del OpenGnSys Web Console. |
---|
875 | function installWebFiles() |
---|
876 | { |
---|
877 | echoAndLog "${FUNCNAME}(): Installing web files..." |
---|
878 | cp -a $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para doxigen |
---|
879 | if [ $? != 0 ]; then |
---|
880 | errorAndLog "${FUNCNAME}(): Error copying web files." |
---|
881 | exit 1 |
---|
882 | fi |
---|
883 | find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
884 | # Descomprimir XAJAX. |
---|
885 | unzip $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax |
---|
886 | # Cambiar permisos para ficheros especiales. |
---|
887 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/iconos |
---|
888 | echoAndLog "${FUNCNAME}(): Web files installed successfully." |
---|
889 | } |
---|
890 | |
---|
891 | # Configuración específica de Apache. |
---|
892 | function installWebConsoleApacheConf() |
---|
893 | { |
---|
894 | if [ $# -ne 2 ]; then |
---|
895 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
896 | exit 1 |
---|
897 | fi |
---|
898 | |
---|
899 | local path_opengnsys_base=$1 |
---|
900 | local path_apache2_confd=$2 |
---|
901 | local CONSOLEDIR=${path_opengnsys_base}/www |
---|
902 | |
---|
903 | if [ ! -d $path_apache2_confd ]; then |
---|
904 | errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation" |
---|
905 | return 1 |
---|
906 | fi |
---|
907 | |
---|
908 | mkdir -p $path_apache2_confd/{sites-available,sites-enabled} |
---|
909 | |
---|
910 | echoAndLog "${FUNCNAME}(): creating apache2 config file.." |
---|
911 | |
---|
912 | # Activar HTTPS. |
---|
913 | $ENABLESITE default-ssl |
---|
914 | $ENABLEMOD ssl |
---|
915 | make-ssl-cert generate-default-snakeoil --force-overwrite |
---|
916 | |
---|
917 | # Genera configuración de consola web a partir del fichero plantilla. |
---|
918 | sed -e "s/CONSOLEDIR/${CONSOLEDIR//\//\\/}/g" \ |
---|
919 | $WORKDIR/opengnsys/server/etc/apache.conf.tmpl > $path_opengnsys_base/etc/apache.conf |
---|
920 | |
---|
921 | ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys |
---|
922 | $ENABLESITE opengnsys |
---|
923 | if [ $? -ne 0 ]; then |
---|
924 | errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation" |
---|
925 | return 1 |
---|
926 | else |
---|
927 | echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon" |
---|
928 | $APACHEINIT restart |
---|
929 | return 0 |
---|
930 | fi |
---|
931 | } |
---|
932 | |
---|
933 | |
---|
934 | # Crear documentación Doxygen para la consola web. |
---|
935 | function makeDoxygenFiles() |
---|
936 | { |
---|
937 | echoAndLog "${FUNCNAME}(): Making Doxygen web files..." |
---|
938 | $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \ |
---|
939 | $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www |
---|
940 | if [ ! -d "$INSTALL_TARGET/www/html" ]; then |
---|
941 | errorAndLog "${FUNCNAME}(): unable to create Doxygen web files." |
---|
942 | return 1 |
---|
943 | fi |
---|
944 | mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api" |
---|
945 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api |
---|
946 | echoAndLog "${FUNCNAME}(): Doxygen web files created successfully." |
---|
947 | } |
---|
948 | |
---|
949 | |
---|
950 | # Crea la estructura base de la instalación de opengnsys |
---|
951 | function createDirs() |
---|
952 | { |
---|
953 | if [ $# -ne 1 ]; then |
---|
954 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
955 | exit 1 |
---|
956 | fi |
---|
957 | |
---|
958 | local path_opengnsys_base="$1" |
---|
959 | |
---|
960 | # Crear estructura de directorios. |
---|
961 | echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base" |
---|
962 | mkdir -p $path_opengnsys_base |
---|
963 | mkdir -p $path_opengnsys_base/bin |
---|
964 | mkdir -p $path_opengnsys_base/client |
---|
965 | mkdir -p $path_opengnsys_base/doc |
---|
966 | mkdir -p $path_opengnsys_base/etc |
---|
967 | mkdir -p $path_opengnsys_base/lib |
---|
968 | mkdir -p $path_opengnsys_base/log/clients |
---|
969 | ln -fs $path_opengnsys_base/log /var/log/opengnsys |
---|
970 | mkdir -p $path_opengnsys_base/sbin |
---|
971 | mkdir -p $path_opengnsys_base/www |
---|
972 | mkdir -p $path_opengnsys_base/images |
---|
973 | mkdir -p $TFTPCFGDIR |
---|
974 | ln -fs $TFTPCFGDIR $path_opengnsys_base/tftpboot |
---|
975 | mkdir -p $path_opengnsys_base/tftpboot/pxelinux.cfg |
---|
976 | mkdir -p $path_opengnsys_base/tftpboot/menu.lst |
---|
977 | if [ $? -ne 0 ]; then |
---|
978 | errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" |
---|
979 | return 1 |
---|
980 | fi |
---|
981 | |
---|
982 | # Crear usuario ficticio. |
---|
983 | if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then |
---|
984 | echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created" |
---|
985 | else |
---|
986 | echoAndLog "${FUNCNAME}(): creating OpenGnSys user" |
---|
987 | useradd $OPENGNSYS_CLIENT_USER 2>/dev/null |
---|
988 | if [ $? -ne 0 ]; then |
---|
989 | errorAndLog "${FUNCNAME}(): error creating OpenGnSys user" |
---|
990 | return 1 |
---|
991 | fi |
---|
992 | fi |
---|
993 | |
---|
994 | # Establecer los permisos básicos. |
---|
995 | echoAndLog "${FUNCNAME}(): setting directory permissions" |
---|
996 | chmod -R 775 $path_opengnsys_base/{log/clients,images} |
---|
997 | chown -R :$OPENGNSYS_CLIENT_USER $path_opengnsys_base/{log/clients,images} |
---|
998 | if [ $? -ne 0 ]; then |
---|
999 | errorAndLog "${FUNCNAME}(): error while setting permissions" |
---|
1000 | return 1 |
---|
1001 | fi |
---|
1002 | |
---|
1003 | echoAndLog "${FUNCNAME}(): directory paths created" |
---|
1004 | return 0 |
---|
1005 | } |
---|
1006 | |
---|
1007 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
1008 | function copyServerFiles () |
---|
1009 | { |
---|
1010 | if [ $# -ne 1 ]; then |
---|
1011 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
1012 | exit 1 |
---|
1013 | fi |
---|
1014 | |
---|
1015 | local path_opengnsys_base="$1" |
---|
1016 | |
---|
1017 | local SOURCES=( server/tftpboot \ |
---|
1018 | server/bin \ |
---|
1019 | repoman/bin \ |
---|
1020 | installer/opengnsys_uninstall.sh \ |
---|
1021 | installer/opengnsys_update.sh \ |
---|
1022 | doc ) |
---|
1023 | local TARGETS=( tftpboot \ |
---|
1024 | bin \ |
---|
1025 | bin \ |
---|
1026 | lib \ |
---|
1027 | lib \ |
---|
1028 | doc ) |
---|
1029 | |
---|
1030 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
1031 | errorAndLog "${FUNCNAME}(): inconsistent number of array items" |
---|
1032 | exit 1 |
---|
1033 | fi |
---|
1034 | |
---|
1035 | echoAndLog "${FUNCNAME}(): copying files to server directories" |
---|
1036 | |
---|
1037 | pushd $WORKDIR/opengnsys |
---|
1038 | local i |
---|
1039 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
1040 | if [ -f "${SOURCES[$i]}" ]; then |
---|
1041 | echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
1042 | cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
1043 | elif [ -d "${SOURCES[$i]}" ]; then |
---|
1044 | echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
1045 | cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
1046 | else |
---|
1047 | echoAndLog "Warning: Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
1048 | fi |
---|
1049 | done |
---|
1050 | popd |
---|
1051 | } |
---|
1052 | |
---|
1053 | #################################################################### |
---|
1054 | ### Funciones de compilación de código fuente de servicios |
---|
1055 | #################################################################### |
---|
1056 | |
---|
1057 | # Compilar los servicios de OpenGnSys |
---|
1058 | function servicesCompilation () |
---|
1059 | { |
---|
1060 | local hayErrores=0 |
---|
1061 | |
---|
1062 | # Compilar OpenGnSys Server |
---|
1063 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server" |
---|
1064 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer |
---|
1065 | make && mv ogAdmServer $INSTALL_TARGET/sbin |
---|
1066 | if [ $? -ne 0 ]; then |
---|
1067 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server" |
---|
1068 | hayErrores=1 |
---|
1069 | fi |
---|
1070 | popd |
---|
1071 | # Compilar OpenGnSys Repository Manager |
---|
1072 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager" |
---|
1073 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo |
---|
1074 | make && mv ogAdmRepo $INSTALL_TARGET/sbin |
---|
1075 | if [ $? -ne 0 ]; then |
---|
1076 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager" |
---|
1077 | hayErrores=1 |
---|
1078 | fi |
---|
1079 | popd |
---|
1080 | # Compilar OpenGnSys Agent |
---|
1081 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent" |
---|
1082 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent |
---|
1083 | make && mv ogAdmAgent $INSTALL_TARGET/sbin |
---|
1084 | if [ $? -ne 0 ]; then |
---|
1085 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent" |
---|
1086 | hayErrores=1 |
---|
1087 | fi |
---|
1088 | popd |
---|
1089 | # Compilar OpenGnSys Client |
---|
1090 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client" |
---|
1091 | pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient |
---|
1092 | make && mv ogAdmClient ../../../../client/shared/bin |
---|
1093 | if [ $? -ne 0 ]; then |
---|
1094 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client" |
---|
1095 | hayErrores=1 |
---|
1096 | fi |
---|
1097 | popd |
---|
1098 | |
---|
1099 | return $hayErrores |
---|
1100 | } |
---|
1101 | |
---|
1102 | #################################################################### |
---|
1103 | ### Funciones de copia de la Interface de administración |
---|
1104 | #################################################################### |
---|
1105 | |
---|
1106 | # Copiar carpeta de Interface |
---|
1107 | function copyInterfaceAdm () |
---|
1108 | { |
---|
1109 | local hayErrores=0 |
---|
1110 | |
---|
1111 | # Crear carpeta y copiar Interface |
---|
1112 | echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" |
---|
1113 | cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm |
---|
1114 | if [ $? -ne 0 ]; then |
---|
1115 | echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder" |
---|
1116 | hayErrores=1 |
---|
1117 | fi |
---|
1118 | chown $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
1119 | chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
1120 | |
---|
1121 | return $hayErrores |
---|
1122 | } |
---|
1123 | |
---|
1124 | #################################################################### |
---|
1125 | ### Funciones instalacion cliente opengnsys |
---|
1126 | #################################################################### |
---|
1127 | |
---|
1128 | function copyClientFiles() |
---|
1129 | { |
---|
1130 | local errstatus=0 |
---|
1131 | |
---|
1132 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files." |
---|
1133 | cp -a $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client |
---|
1134 | if [ $? -ne 0 ]; then |
---|
1135 | errorAndLog "${FUNCNAME}(): error while copying client estructure" |
---|
1136 | errstatus=1 |
---|
1137 | fi |
---|
1138 | find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
1139 | |
---|
1140 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files." |
---|
1141 | mkdir -p $INSTALL_TARGET/client/lib/engine/bin |
---|
1142 | cp -a $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin |
---|
1143 | if [ $? -ne 0 ]; then |
---|
1144 | errorAndLog "${FUNCNAME}(): error while copying engine files" |
---|
1145 | errstatus=1 |
---|
1146 | fi |
---|
1147 | |
---|
1148 | if [ $errstatus -eq 0 ]; then |
---|
1149 | echoAndLog "${FUNCNAME}(): client copy files success." |
---|
1150 | else |
---|
1151 | errorAndLog "${FUNCNAME}(): client copy files with errors" |
---|
1152 | fi |
---|
1153 | |
---|
1154 | return $errstatus |
---|
1155 | } |
---|
1156 | |
---|
1157 | |
---|
1158 | # Crear cliente OpenGnSys 1.0.2 |
---|
1159 | function clientCreate() |
---|
1160 | { |
---|
1161 | local DOWNLOADURL="http://$OPENGNSYS_SERVER/downloads" |
---|
1162 | local FILENAME=ogLive-oneiric-3.0.0-14-generic-r2439.iso |
---|
1163 | local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME |
---|
1164 | local TMPDIR=/tmp/${FILENAME%.iso} |
---|
1165 | |
---|
1166 | echoAndLog "${FUNCNAME}(): Loading Client" |
---|
1167 | # Descargar, montar imagen, copiar cliente ogclient y desmontar. |
---|
1168 | wget $DOWNLOADURL/$FILENAME -O $TARGETFILE |
---|
1169 | if [ ! -s $TARGETFILE ]; then |
---|
1170 | errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client" |
---|
1171 | return 1 |
---|
1172 | fi |
---|
1173 | echoAndLog "${FUNCNAME}(): Copying Client files" |
---|
1174 | mkdir -p $TMPDIR |
---|
1175 | mount -o loop,ro $TARGETFILE $TMPDIR |
---|
1176 | cp -av $TMPDIR/ogclient $INSTALL_TARGET/tftpboot |
---|
1177 | umount $TMPDIR |
---|
1178 | rmdir $TMPDIR |
---|
1179 | # Asignar la clave cliente para acceso a Samba. |
---|
1180 | echoAndLog "${FUNCNAME}(): Set client access key" |
---|
1181 | echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | \ |
---|
1182 | $INSTALL_TARGET/bin/setsmbpass |
---|
1183 | |
---|
1184 | # Establecer los permisos. |
---|
1185 | find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \; |
---|
1186 | find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \; |
---|
1187 | chown -R :$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/tftpboot/ogclient |
---|
1188 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg} |
---|
1189 | |
---|
1190 | # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache |
---|
1191 | cp -av $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot |
---|
1192 | cp -av $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot |
---|
1193 | |
---|
1194 | echoAndLog "${FUNCNAME}(): Client generation success" |
---|
1195 | } |
---|
1196 | |
---|
1197 | |
---|
1198 | # Configuración básica de servicios de OpenGnSys |
---|
1199 | function openGnsysConfigure() |
---|
1200 | { |
---|
1201 | local i=0 |
---|
1202 | local dev="" |
---|
1203 | local CONSOLEURL |
---|
1204 | |
---|
1205 | echoAndLog "${FUNCNAME}(): Copying init files." |
---|
1206 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys |
---|
1207 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys |
---|
1208 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepoAux $INSTALL_TARGET/sbin |
---|
1209 | update-rc.d opengnsys defaults |
---|
1210 | echoAndLog "${FUNCNAME}(): Creating cron files." |
---|
1211 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys |
---|
1212 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator |
---|
1213 | echo "5 * * * * root [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker |
---|
1214 | |
---|
1215 | echoAndLog "${FUNCNAME}(): Creating logrotate configuration file." |
---|
1216 | sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ |
---|
1217 | $WORKDIR/opengnsys/server/etc/logrotate.tmpl > /etc/logrotate.d/opengnsys |
---|
1218 | |
---|
1219 | echoAndLog "${FUNCNAME}(): Creating OpenGnSys config files." |
---|
1220 | for dev in ${DEVICE[*]}; do |
---|
1221 | if [ -n "${SERVERIP[i]}" ]; then |
---|
1222 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
1223 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
1224 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
1225 | -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ |
---|
1226 | $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer/ogAdmServer.cfg > $INSTALL_TARGET/etc/ogAdmServer-$dev.cfg |
---|
1227 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
1228 | $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo/ogAdmRepo.cfg > $INSTALL_TARGET/etc/ogAdmRepo-$dev.cfg |
---|
1229 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
1230 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
1231 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
1232 | -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ |
---|
1233 | $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent/ogAdmAgent.cfg > $INSTALL_TARGET/etc/ogAdmAgent-$dev.cfg |
---|
1234 | CONSOLEURL="http://${SERVERIP[i]}/opengnsys" |
---|
1235 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
1236 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
1237 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
1238 | -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ |
---|
1239 | -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \ |
---|
1240 | $INSTALL_TARGET/www/controlacceso.php > $INSTALL_TARGET/www/controlacceso-$dev.php |
---|
1241 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
1242 | -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \ |
---|
1243 | $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient-$dev.cfg |
---|
1244 | if [ "$dev" == "$DEFAULTDEV" ]; then |
---|
1245 | OPENGNSYS_CONSOLEURL="$CONSOLEURL" |
---|
1246 | fi |
---|
1247 | fi |
---|
1248 | let i++ |
---|
1249 | done |
---|
1250 | ln -f $INSTALL_TARGET/etc/ogAdmServer-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmServer.cfg |
---|
1251 | ln -f $INSTALL_TARGET/etc/ogAdmRepo-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmRepo.cfg |
---|
1252 | ln -f $INSTALL_TARGET/etc/ogAdmAgent-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmAgent.cfg |
---|
1253 | ln -f $INSTALL_TARGET/client/etc/ogAdmClient-$DEFAULTDEV.cfg $INSTALL_TARGET/client/etc/ogAdmClient.cfg |
---|
1254 | ln -f $INSTALL_TARGET/www/controlacceso-$DEFAULTDEV.php $INSTALL_TARGET/www/controlacceso.php |
---|
1255 | chown root:root $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg |
---|
1256 | chmod 600 $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg |
---|
1257 | chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso*.php |
---|
1258 | chmod 600 $INSTALL_TARGET/www/controlacceso*.php |
---|
1259 | echoAndLog "${FUNCNAME}(): Starting OpenGnSys services." |
---|
1260 | /etc/init.d/opengnsys start |
---|
1261 | } |
---|
1262 | |
---|
1263 | |
---|
1264 | ##################################################################### |
---|
1265 | ####### Función de resumen informativo de la instalación |
---|
1266 | ##################################################################### |
---|
1267 | |
---|
1268 | function installationSummary() |
---|
1269 | { |
---|
1270 | # Crear fichero de versión y revisión, si no existe. |
---|
1271 | local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt" |
---|
1272 | local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}') |
---|
1273 | [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE |
---|
1274 | perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE |
---|
1275 | |
---|
1276 | # Mostrar información. |
---|
1277 | echo |
---|
1278 | echoAndLog "OpenGnSys Installation Summary" |
---|
1279 | echo "==============================" |
---|
1280 | echoAndLog "Project version: $(cat $VERSIONFILE 2>/dev/null)" |
---|
1281 | echoAndLog "Installation directory: $INSTALL_TARGET" |
---|
1282 | echoAndLog "Repository directory: $INSTALL_TARGET/images" |
---|
1283 | echoAndLog "DHCP configuration directory: $DHCPCFGDIR" |
---|
1284 | echoAndLog "TFTP configuration directory: $TFTPCFGDIR" |
---|
1285 | echoAndLog "Samba configuration directory: $SAMBACFGDIR" |
---|
1286 | echoAndLog "Web Console URL: $OPENGNSYS_CONSOLEURL" |
---|
1287 | echoAndLog "Web Console admin user: $OPENGNSYS_DB_USER" |
---|
1288 | echoAndLog "Web Console admin password: $OPENGNSYS_DB_PASSWD" |
---|
1289 | echo |
---|
1290 | echoAndLog "Post-Installation Instructions:" |
---|
1291 | echo "===============================" |
---|
1292 | echoAndLog "Review or edit all configuration files." |
---|
1293 | echoAndLog "Insert DHCP configuration data and restart service." |
---|
1294 | echoAndLog "Optional: Log-in as Web Console admin user." |
---|
1295 | echoAndLog " - Review default Organization data and assign access to users." |
---|
1296 | echoAndLog "Log-in as Web Console organization user." |
---|
1297 | echoAndLog " - Insert OpenGnSys data (labs, computers, menus, etc)." |
---|
1298 | echo |
---|
1299 | } |
---|
1300 | |
---|
1301 | |
---|
1302 | |
---|
1303 | ##################################################################### |
---|
1304 | ####### Proceso de instalación de OpenGnSys |
---|
1305 | ##################################################################### |
---|
1306 | |
---|
1307 | echoAndLog "OpenGnSys installation begins at $(date)" |
---|
1308 | pushd $WORKDIR |
---|
1309 | |
---|
1310 | # Detectar datos iniciales de auto-configuración del instalador. |
---|
1311 | autoConfigure |
---|
1312 | |
---|
1313 | # Detectar parámetros de red y comprobar si hay conexión. |
---|
1314 | getNetworkSettings |
---|
1315 | if [ $? -ne 0 ]; then |
---|
1316 | errorAndLog "Error reading default network settings." |
---|
1317 | exit 1 |
---|
1318 | fi |
---|
1319 | checkNetworkConnection |
---|
1320 | if [ $? -ne 0 ]; then |
---|
1321 | errorAndLog "Error connecting to server. Causes:" |
---|
1322 | errorAndLog " - Network is unreachable, review devices parameters." |
---|
1323 | errorAndLog " - You are inside a private network, configure the proxy service." |
---|
1324 | errorAndLog " - Server is temporally down, try agian later." |
---|
1325 | exit 1 |
---|
1326 | fi |
---|
1327 | |
---|
1328 | # Detener servicios de OpenGnSys, si están activos previamente. |
---|
1329 | [ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop |
---|
1330 | |
---|
1331 | # Actualizar repositorios |
---|
1332 | updatePackageList |
---|
1333 | |
---|
1334 | # Instalación de dependencias (paquetes de sistema operativo). |
---|
1335 | declare -a notinstalled |
---|
1336 | checkDependencies DEPENDENCIES notinstalled |
---|
1337 | if [ $? -ne 0 ]; then |
---|
1338 | installDependencies notinstalled |
---|
1339 | if [ $? -ne 0 ]; then |
---|
1340 | echoAndLog "Error while installing some dependeces, please verify your server installation before continue" |
---|
1341 | exit 1 |
---|
1342 | fi |
---|
1343 | fi |
---|
1344 | |
---|
1345 | # Detectar datos de auto-configuración después de instalar paquetes. |
---|
1346 | autoConfigurePost |
---|
1347 | |
---|
1348 | # Arbol de directorios de OpenGnSys. |
---|
1349 | createDirs ${INSTALL_TARGET} |
---|
1350 | if [ $? -ne 0 ]; then |
---|
1351 | errorAndLog "Error while creating directory paths!" |
---|
1352 | exit 1 |
---|
1353 | fi |
---|
1354 | |
---|
1355 | # Si es necesario, descarga el repositorio de código en directorio temporal |
---|
1356 | if [ $USESVN -eq 1 ]; then |
---|
1357 | svnExportCode $SVN_URL |
---|
1358 | if [ $? -ne 0 ]; then |
---|
1359 | errorAndLog "Error while getting code from svn" |
---|
1360 | exit 1 |
---|
1361 | fi |
---|
1362 | else |
---|
1363 | ln -fs "$(dirname $PROGRAMDIR)" opengnsys |
---|
1364 | fi |
---|
1365 | |
---|
1366 | # Compilar código fuente de los servicios de OpenGnSys. |
---|
1367 | servicesCompilation |
---|
1368 | if [ $? -ne 0 ]; then |
---|
1369 | errorAndLog "Error while compiling OpenGnsys services" |
---|
1370 | exit 1 |
---|
1371 | fi |
---|
1372 | |
---|
1373 | # Copiar carpeta Interface entre administración y motor de clonación. |
---|
1374 | copyInterfaceAdm |
---|
1375 | if [ $? -ne 0 ]; then |
---|
1376 | errorAndLog "Error while copying Administration Interface" |
---|
1377 | exit 1 |
---|
1378 | fi |
---|
1379 | |
---|
1380 | # Configurando tftp |
---|
1381 | tftpConfigure |
---|
1382 | |
---|
1383 | # Configuración Samba |
---|
1384 | smbConfigure |
---|
1385 | if [ $? -ne 0 ]; then |
---|
1386 | errorAndLog "Error while configuring Samba server!" |
---|
1387 | exit 1 |
---|
1388 | fi |
---|
1389 | |
---|
1390 | # Configuración ejemplo DHCP |
---|
1391 | dhcpConfigure |
---|
1392 | if [ $? -ne 0 ]; then |
---|
1393 | errorAndLog "Error while copying your dhcp server files!" |
---|
1394 | exit 1 |
---|
1395 | fi |
---|
1396 | |
---|
1397 | # Copiar ficheros de servicios OpenGnSys Server. |
---|
1398 | copyServerFiles ${INSTALL_TARGET} |
---|
1399 | if [ $? -ne 0 ]; then |
---|
1400 | errorAndLog "Error while copying the server files!" |
---|
1401 | exit 1 |
---|
1402 | fi |
---|
1403 | |
---|
1404 | # Instalar Base de datos de OpenGnSys Admin. |
---|
1405 | isInArray notinstalled "mysql-server" |
---|
1406 | if [ $? -eq 0 ]; then |
---|
1407 | mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD} |
---|
1408 | else |
---|
1409 | mysqlGetRootPassword |
---|
1410 | fi |
---|
1411 | |
---|
1412 | mysqlTestConnection ${MYSQL_ROOT_PASSWORD} |
---|
1413 | if [ $? -ne 0 ]; then |
---|
1414 | errorAndLog "Error while connection to mysql" |
---|
1415 | exit 1 |
---|
1416 | fi |
---|
1417 | mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
1418 | if [ $? -ne 0 ]; then |
---|
1419 | echoAndLog "Creating Web Console database" |
---|
1420 | mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
1421 | if [ $? -ne 0 ]; then |
---|
1422 | errorAndLog "Error while creating Web Console database" |
---|
1423 | exit 1 |
---|
1424 | fi |
---|
1425 | else |
---|
1426 | echoAndLog "Web Console database exists, ommiting creation" |
---|
1427 | fi |
---|
1428 | |
---|
1429 | mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER} |
---|
1430 | if [ $? -ne 0 ]; then |
---|
1431 | echoAndLog "Creating user in database" |
---|
1432 | mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}" |
---|
1433 | if [ $? -ne 0 ]; then |
---|
1434 | errorAndLog "Error while creating database user" |
---|
1435 | exit 1 |
---|
1436 | fi |
---|
1437 | |
---|
1438 | fi |
---|
1439 | |
---|
1440 | mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
1441 | if [ $? -eq 0 ]; then |
---|
1442 | echoAndLog "Creating tables..." |
---|
1443 | if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then |
---|
1444 | mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE |
---|
1445 | else |
---|
1446 | errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!" |
---|
1447 | exit 1 |
---|
1448 | fi |
---|
1449 | else |
---|
1450 | # Si existe fichero ogBDAdmin-VersLocal-VersRepo.sql; aplicar cambios. |
---|
1451 | INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt) |
---|
1452 | REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt) |
---|
1453 | OPENGNSYS_DB_UPDATE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql" |
---|
1454 | if [ -f $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE ]; then |
---|
1455 | echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION" |
---|
1456 | mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE |
---|
1457 | else |
---|
1458 | echoAndLog "Database unchanged." |
---|
1459 | fi |
---|
1460 | fi |
---|
1461 | |
---|
1462 | # copiando paqinas web |
---|
1463 | installWebFiles |
---|
1464 | # Generar páqinas web de documentación de la API |
---|
1465 | makeDoxygenFiles |
---|
1466 | |
---|
1467 | # creando configuracion de apache2 |
---|
1468 | installWebConsoleApacheConf $INSTALL_TARGET /etc/apache2 |
---|
1469 | if [ $? -ne 0 ]; then |
---|
1470 | errorAndLog "Error configuring Apache for OpenGnSys Admin" |
---|
1471 | exit 1 |
---|
1472 | fi |
---|
1473 | |
---|
1474 | popd |
---|
1475 | |
---|
1476 | |
---|
1477 | # Crear la estructura de los accesos al servidor desde el cliente (shared) |
---|
1478 | copyClientFiles |
---|
1479 | if [ $? -ne 0 ]; then |
---|
1480 | errorAndLog "Error creating client structure" |
---|
1481 | fi |
---|
1482 | |
---|
1483 | # Crear la estructura del cliente de OpenGnSys |
---|
1484 | clientCreate |
---|
1485 | if [ $? -ne 0 ]; then |
---|
1486 | errorAndLog "Error creating client" |
---|
1487 | exit 1 |
---|
1488 | fi |
---|
1489 | |
---|
1490 | # Configuración de servicios de OpenGnSys |
---|
1491 | openGnsysConfigure |
---|
1492 | |
---|
1493 | # Mostrar sumario de la instalación e instrucciones de post-instalación. |
---|
1494 | installationSummary |
---|
1495 | |
---|
1496 | #rm -rf $WORKDIR |
---|
1497 | echoAndLog "OpenGnSys installation finished at $(date)" |
---|
1498 | exit 0 |
---|
1499 | |
---|