1 | #!/bin/bash |
---|
2 | |
---|
3 | ##################################################################### |
---|
4 | ####### Script instalador OpenGnsys |
---|
5 | ####### autor: Luis Guillén <lguillen@unizar.es> |
---|
6 | ##################################################################### |
---|
7 | |
---|
8 | |
---|
9 | WORKDIR=/tmp/opengnsys_installer |
---|
10 | LOG_FILE=$WORKDIR/installation.log |
---|
11 | |
---|
12 | # Array con las dependencias |
---|
13 | DEPENDENCIES=( subversion php5 mysql-server nfs-kernel-server dhcp3-server udpcast bittorrent apache2 php5 mysql-server php5-mysql tftpd-hpa syslinux tftp-hpa openbsd-inetd update-inetd ) |
---|
14 | |
---|
15 | INSTALL_TARGET=/opt/opengnsys |
---|
16 | |
---|
17 | MYSQL_ROOT_PASSWORD="passwordroot" |
---|
18 | |
---|
19 | # conexión al svn |
---|
20 | SVN_URL=svn://www.informatica.us.es:3690/opengnsys/trunk |
---|
21 | |
---|
22 | # Datos de base de datos |
---|
23 | OPENGNSYS_DATABASE=ogBDAdmin |
---|
24 | OPENGNSYS_DB_USER=usuog |
---|
25 | OPENGNSYS_DB_PASSWD=passusuog |
---|
26 | OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogBDAdmin.sql |
---|
27 | |
---|
28 | USUARIO=`whoami` |
---|
29 | |
---|
30 | if [ $USUARIO != 'root' ] |
---|
31 | then |
---|
32 | echo "ERROR: this program must run under root privileges!!" |
---|
33 | exit 1 |
---|
34 | fi |
---|
35 | |
---|
36 | |
---|
37 | mkdir -p $WORKDIR |
---|
38 | pushd $WORKDIR |
---|
39 | |
---|
40 | ##################################################################### |
---|
41 | ####### Algunas funciones útiles de propósito general: |
---|
42 | ##################################################################### |
---|
43 | getDateTime() |
---|
44 | { |
---|
45 | echo `date +%Y%m%d-%H%M%S` |
---|
46 | } |
---|
47 | |
---|
48 | # Escribe a fichero y muestra por pantalla |
---|
49 | echoAndLog() |
---|
50 | { |
---|
51 | echo $1 |
---|
52 | FECHAHORA=`getDateTime` |
---|
53 | echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
54 | } |
---|
55 | |
---|
56 | errorAndLog() |
---|
57 | { |
---|
58 | echo "ERROR: $1" |
---|
59 | FECHAHORA=`getDateTime` |
---|
60 | echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
61 | } |
---|
62 | |
---|
63 | # comprueba si el elemento pasado en $2 esta en el array $1 |
---|
64 | isInArray() |
---|
65 | { |
---|
66 | if [ $# -ne 2 ]; then |
---|
67 | errorAndLog "isInArray(): invalid number of parameters" |
---|
68 | exit 1 |
---|
69 | fi |
---|
70 | |
---|
71 | echoAndLog "isInArray(): checking if $2 is in $1" |
---|
72 | local deps |
---|
73 | eval "deps=( \"\${$1[@]}\" )" |
---|
74 | elemento=$2 |
---|
75 | |
---|
76 | local is_in_array=1 |
---|
77 | # copia local del array del parametro 1 |
---|
78 | for (( i = 0 ; i < ${#deps[@]} ; i++ )) |
---|
79 | do |
---|
80 | if [ "${deps[$i]}" = "${elemento}" ]; then |
---|
81 | echoAndLog "isInArray(): $elemento found in array" |
---|
82 | is_in_array=0 |
---|
83 | fi |
---|
84 | done |
---|
85 | |
---|
86 | if [ $is_in_array -ne 0 ]; then |
---|
87 | echoAndLog "isInArray(): $elemento NOT found in array" |
---|
88 | fi |
---|
89 | |
---|
90 | return $is_in_array |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | ##################################################################### |
---|
95 | ####### Funciones de manejo de paquetes Debian |
---|
96 | ##################################################################### |
---|
97 | |
---|
98 | checkPackage() |
---|
99 | { |
---|
100 | package=$1 |
---|
101 | if [ -z $package ]; then |
---|
102 | errorAndLog "checkPackage(): parameter required" |
---|
103 | exit 1 |
---|
104 | fi |
---|
105 | echoAndLog "checkPackage(): checking if package $package exists" |
---|
106 | dpkg -L $package &>/dev/null |
---|
107 | if [ $? -eq 0 ]; then |
---|
108 | echoAndLog "checkPackage(): package $package exists" |
---|
109 | return 0 |
---|
110 | else |
---|
111 | echoAndLog "checkPackage(): package $package doesn't exists" |
---|
112 | return 1 |
---|
113 | fi |
---|
114 | } |
---|
115 | |
---|
116 | # recibe array con dependencias |
---|
117 | # por referencia deja un array con las dependencias no resueltas |
---|
118 | # devuelve 1 si hay alguna dependencia no resuelta |
---|
119 | checkDependencies() |
---|
120 | { |
---|
121 | if [ $# -ne 2 ]; then |
---|
122 | errorAndLog "checkDependencies(): invalid number of parameters" |
---|
123 | exit 1 |
---|
124 | fi |
---|
125 | |
---|
126 | echoAndLog "checkDependencies(): checking dependences" |
---|
127 | uncompletedeps=0 |
---|
128 | |
---|
129 | # copia local del array del parametro 1 |
---|
130 | local deps |
---|
131 | eval "deps=( \"\${$1[@]}\" )" |
---|
132 | |
---|
133 | declare -a local_notinstalled |
---|
134 | |
---|
135 | for (( i = 0 ; i < ${#deps[@]} ; i++ )) |
---|
136 | do |
---|
137 | checkPackage ${deps[$i]} |
---|
138 | if [ $? -ne 0 ]; then |
---|
139 | local_notinstalled[$uncompletedeps]=$package |
---|
140 | let uncompletedeps=uncompletedeps+1 |
---|
141 | fi |
---|
142 | done |
---|
143 | |
---|
144 | # relleno el array especificado en $2 por referencia |
---|
145 | for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ )) |
---|
146 | do |
---|
147 | eval "${2}[$i]=${local_notinstalled[$i]}" |
---|
148 | done |
---|
149 | |
---|
150 | # retorna el numero de paquetes no resueltos |
---|
151 | echoAndLog "checkDependencies(): dependencies uncompleted: $uncompletedeps" |
---|
152 | return $uncompletedeps |
---|
153 | } |
---|
154 | |
---|
155 | # Recibe un array con las dependencias y lo instala |
---|
156 | installDependencies() |
---|
157 | { |
---|
158 | if [ $# -ne 1 ]; then |
---|
159 | errorAndLog "installDependencies(): invalid number of parameters" |
---|
160 | exit 1 |
---|
161 | fi |
---|
162 | echoAndLog "installDependencies(): installing uncompleted dependencies" |
---|
163 | |
---|
164 | # copia local del array del parametro 1 |
---|
165 | local deps |
---|
166 | eval "deps=( \"\${$1[@]}\" )" |
---|
167 | |
---|
168 | local string_deps="" |
---|
169 | for (( i = 0 ; i < ${#deps[@]} ; i++ )) |
---|
170 | do |
---|
171 | string_deps="$string_deps ${deps[$i]}" |
---|
172 | done |
---|
173 | |
---|
174 | if [ -z "${string_deps}" ]; then |
---|
175 | errorAndLog "installDependencies(): array of dependeces is empty" |
---|
176 | exit 1 |
---|
177 | fi |
---|
178 | |
---|
179 | OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND |
---|
180 | export DEBIAN_FRONTEND=noninteractive |
---|
181 | |
---|
182 | echoAndLog "installDependencies(): now ${string_deps} will be installed" |
---|
183 | apt-get -y install --force-yes ${string_deps} |
---|
184 | if [ $? -ne 0 ]; then |
---|
185 | errorAndLog "installDependencies(): error installing dependencies" |
---|
186 | return 1 |
---|
187 | fi |
---|
188 | |
---|
189 | DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND |
---|
190 | echoAndLog "installDependencies(): dependencies installed" |
---|
191 | } |
---|
192 | |
---|
193 | ##################################################################### |
---|
194 | ####### Funciones para el manejo de bases de datos |
---|
195 | ##################################################################### |
---|
196 | |
---|
197 | # This function set password to root |
---|
198 | mysqlSetRootPassword() |
---|
199 | { |
---|
200 | if [ $# -ne 1 ]; then |
---|
201 | errorAndLog "mysqlSetRootPassword(): invalid number of parameters" |
---|
202 | exit 1 |
---|
203 | fi |
---|
204 | |
---|
205 | local root_mysql=$1 |
---|
206 | echoAndLog "mysqlSetRootPassword(): setting root password in MySQL server" |
---|
207 | /usr/bin/mysqladmin -u root password ${root_mysql} |
---|
208 | if [ $? -ne 0 ]; then |
---|
209 | errorAndLog "mysqlSetRootPassword(): error while setting root password in MySQL server" |
---|
210 | return 1 |
---|
211 | fi |
---|
212 | echoAndLog "mysqlSetRootPassword(): root password saved!" |
---|
213 | return 0 |
---|
214 | } |
---|
215 | |
---|
216 | # Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente |
---|
217 | mysqlGetRootPassword(){ |
---|
218 | local pass_mysql |
---|
219 | local pass_mysql2 |
---|
220 | stty -echo |
---|
221 | echo "Existe un servicio mysql ya instalado" |
---|
222 | read -p "Insertar clave de root de Mysql: " pass_mysql |
---|
223 | echo "" |
---|
224 | read -p "Confirmar clave:" pass_mysql2 |
---|
225 | echo "" |
---|
226 | stty echo |
---|
227 | if [ "$pass_mysql" == "$pass_mysql2" ] ;then |
---|
228 | MYSQL_ROOT_PASSWORD=$pass_mysql |
---|
229 | echo "La clave es: ${MYSQL_ROOT_PASSWORD}" |
---|
230 | return 0 |
---|
231 | else |
---|
232 | echo "Las claves no coinciden no se configura la clave del servidor de base de datos." |
---|
233 | echo "las operaciones con la base de datos daran error" |
---|
234 | return 1 |
---|
235 | fi |
---|
236 | |
---|
237 | |
---|
238 | } |
---|
239 | |
---|
240 | # comprueba si puede conectar con mysql con el usuario root |
---|
241 | function mysqlTestConnection() |
---|
242 | { |
---|
243 | if [ $# -ne 1 ]; then |
---|
244 | errorAndLog "mysqlTestConnection(): invalid number of parameters" |
---|
245 | exit 1 |
---|
246 | fi |
---|
247 | |
---|
248 | local root_password="${1}" |
---|
249 | echoAndLog "mysqlTestConnection(): checking connection to mysql..." |
---|
250 | echo "" | mysql -uroot -p"${root_password}" |
---|
251 | if [ $? -ne 0 ]; then |
---|
252 | errorAndLog "mysqlTestConnection(): connection to mysql failed, check root password and if daemon is running!" |
---|
253 | return 1 |
---|
254 | else |
---|
255 | echoAndLog "mysqlTestConnection(): connection success" |
---|
256 | return 0 |
---|
257 | fi |
---|
258 | } |
---|
259 | |
---|
260 | # comprueba si la base de datos existe |
---|
261 | function mysqlDbExists() |
---|
262 | { |
---|
263 | if [ $# -ne 2 ]; then |
---|
264 | errorAndLog "mysqlDbExists(): invalid number of parameters" |
---|
265 | exit 1 |
---|
266 | fi |
---|
267 | |
---|
268 | local root_password="${1}" |
---|
269 | local database=$2 |
---|
270 | echoAndLog "mysqlDbExists(): checking if $database exists..." |
---|
271 | echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$" |
---|
272 | if [ $? -ne 0 ]; then |
---|
273 | echoAndLog "mysqlDbExists():database $database doesn't exists" |
---|
274 | return 1 |
---|
275 | else |
---|
276 | echoAndLog "mysqlDbExists():database $database exists" |
---|
277 | return 0 |
---|
278 | fi |
---|
279 | } |
---|
280 | |
---|
281 | function mysqlCheckDbIsEmpty() |
---|
282 | { |
---|
283 | if [ $# -ne 2 ]; then |
---|
284 | errorAndLog "mysqlCheckDbIsEmpty(): invalid number of parameters" |
---|
285 | exit 1 |
---|
286 | fi |
---|
287 | |
---|
288 | local root_password="${1}" |
---|
289 | local database=$2 |
---|
290 | echoAndLog "mysqlCheckDbIsEmpty(): checking if $database is empty..." |
---|
291 | num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l` |
---|
292 | if [ $? -ne 0 ]; then |
---|
293 | errorAndLog "mysqlCheckDbIsEmpty(): error executing query, check database and root password" |
---|
294 | exit 1 |
---|
295 | fi |
---|
296 | |
---|
297 | if [ $num_tablas -eq 0 ]; then |
---|
298 | echoAndLog "mysqlCheckDbIsEmpty():database $database is empty" |
---|
299 | return 0 |
---|
300 | else |
---|
301 | echoAndLog "mysqlCheckDbIsEmpty():database $database has tables" |
---|
302 | return 1 |
---|
303 | fi |
---|
304 | |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | function mysqlImportSqlFileToDb() |
---|
309 | { |
---|
310 | if [ $# -ne 3 ]; then |
---|
311 | errorAndLog "mysqlImportSqlFileToDb(): invalid number of parameters" |
---|
312 | exit 1 |
---|
313 | fi |
---|
314 | |
---|
315 | local root_password="${1}" |
---|
316 | local database=$2 |
---|
317 | local sqlfile=$3 |
---|
318 | |
---|
319 | if [ ! -f $sqlfile ]; then |
---|
320 | errorAndLog "mysqlImportSqlFileToDb(): Unable to locate $sqlfile!!" |
---|
321 | return 1 |
---|
322 | fi |
---|
323 | |
---|
324 | echoAndLog "mysqlImportSqlFileToDb(): importing sql file to ${database}..." |
---|
325 | mysql -uroot -p"${root_password}" "${database}" < $sqlfile |
---|
326 | if [ $? -ne 0 ]; then |
---|
327 | errorAndLog "mysqlImportSqlFileToDb(): error while importing $sqlfile in database $database" |
---|
328 | return 1 |
---|
329 | fi |
---|
330 | echoAndLog "mysqlImportSqlFileToDb(): file imported to database $database" |
---|
331 | return 0 |
---|
332 | } |
---|
333 | |
---|
334 | # Crea la base de datos |
---|
335 | function mysqlCreateDb() |
---|
336 | { |
---|
337 | if [ $# -ne 2 ]; then |
---|
338 | errorAndLog "mysqlCreateDb(): invalid number of parameters" |
---|
339 | exit 1 |
---|
340 | fi |
---|
341 | |
---|
342 | local root_password="${1}" |
---|
343 | local database=$2 |
---|
344 | |
---|
345 | echoAndLog "mysqlCreateDb(): creating database..." |
---|
346 | mysqladmin -u root --password="${root_password}" create $database |
---|
347 | if [ $? -ne 0 ]; then |
---|
348 | errorAndLog "mysqlCreateDb(): error while creating database $database" |
---|
349 | return 1 |
---|
350 | fi |
---|
351 | errorAndLog "mysqlCreateDb(): database $database created" |
---|
352 | return 0 |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | function mysqlCheckUserExists() |
---|
357 | { |
---|
358 | if [ $# -ne 2 ]; then |
---|
359 | errorAndLog "mysqlCheckUserExists(): invalid number of parameters" |
---|
360 | exit 1 |
---|
361 | fi |
---|
362 | |
---|
363 | local root_password="${1}" |
---|
364 | local userdb=$2 |
---|
365 | |
---|
366 | echoAndLog "mysqlCheckUserExists(): checking if $userdb exists..." |
---|
367 | echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user |
---|
368 | if [ $? -ne 0 ]; then |
---|
369 | echoAndLog "mysqlCheckUserExists(): user doesn't exists" |
---|
370 | return 1 |
---|
371 | else |
---|
372 | echoAndLog "mysqlCheckUserExists(): user already exists" |
---|
373 | return 0 |
---|
374 | fi |
---|
375 | |
---|
376 | } |
---|
377 | |
---|
378 | # Crea un usuario administrativo para la base de datos |
---|
379 | function mysqlCreateAdminUserToDb() |
---|
380 | { |
---|
381 | if [ $# -ne 4 ]; then |
---|
382 | errorAndLog "mysqlCreateAdminUserToDb(): invalid number of parameters" |
---|
383 | exit 1 |
---|
384 | fi |
---|
385 | |
---|
386 | local root_password=$1 |
---|
387 | local database=$2 |
---|
388 | local userdb=$3 |
---|
389 | local passdb=$4 |
---|
390 | |
---|
391 | echoAndLog "mysqlCreateAdminUserToDb(): creating admin user ${userdb} to database ${database}" |
---|
392 | |
---|
393 | cat > $WORKDIR/create_${database}.sql <<EOF |
---|
394 | GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ; |
---|
395 | GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ; |
---|
396 | FLUSH PRIVILEGES ; |
---|
397 | EOF |
---|
398 | mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql |
---|
399 | if [ $? -ne 0 ]; then |
---|
400 | errorAndLog "mysqlCreateAdminUserToDb(): error while creating user in mysql" |
---|
401 | rm -f $WORKDIR/create_${database}.sql |
---|
402 | return 1 |
---|
403 | else |
---|
404 | echoAndLog "mysqlCreateAdminUserToDb(): user created ok" |
---|
405 | rm -f $WORKDIR/create_${database}.sql |
---|
406 | return 0 |
---|
407 | fi |
---|
408 | } |
---|
409 | |
---|
410 | |
---|
411 | ##################################################################### |
---|
412 | ####### Funciones para el manejo de Subversion |
---|
413 | ##################################################################### |
---|
414 | |
---|
415 | svnCheckoutCode() |
---|
416 | { |
---|
417 | if [ $# -ne 1 ]; then |
---|
418 | errorAndLog "svnCheckoutCode(): invalid number of parameters" |
---|
419 | exit 1 |
---|
420 | fi |
---|
421 | |
---|
422 | local url=$1 |
---|
423 | |
---|
424 | echoAndLog "svnCheckoutCode(): downloading subversion code..." |
---|
425 | |
---|
426 | /usr/bin/svn co "${url}" opengnsys |
---|
427 | if [ $? -ne 0 ]; then |
---|
428 | errorAndLog "svnCheckoutCode(): error getting code from ${url}, verify your user and password" |
---|
429 | return 1 |
---|
430 | fi |
---|
431 | echoAndLog "svnCheckoutCode(): subversion code downloaded" |
---|
432 | return 0 |
---|
433 | } |
---|
434 | |
---|
435 | ############################################################ |
---|
436 | ### Esqueleto para el Servicio pxe y contenedor tftpboot ### |
---|
437 | ############################################################ |
---|
438 | |
---|
439 | function tftpConfigure() { |
---|
440 | echo "Configurando el servicio tftp" |
---|
441 | basetftp=/var/lib/tftpboot |
---|
442 | |
---|
443 | # reiniciamos demonio internet ????? porque ???? |
---|
444 | /etc/init.d/openbsd-inetd start |
---|
445 | |
---|
446 | # preparacion contenedor tftpboot |
---|
447 | cp -pr /usr/lib/syslinux/ ${basetftp}/syslinux |
---|
448 | cp /usr/lib/syslinux/pxelinux.0 ${basetftp} |
---|
449 | # prepamos el directorio de la configuracion de pxe |
---|
450 | mkdir -p ${basetftp}/pxelinux.cfg |
---|
451 | cat > ${basetftp}/pxelinux.cfg/default <<EOF |
---|
452 | DEFAULT pxe |
---|
453 | |
---|
454 | LABEL pxe |
---|
455 | KERNEL linux |
---|
456 | APPEND initrd=initrd.gz ip=dhcp ro vga=788 irqpoll acpi=on |
---|
457 | EOF |
---|
458 | # comprobamos el servicio tftp |
---|
459 | sleep 1 |
---|
460 | testPxe |
---|
461 | ## damos perfimos de lectura a usuario web. |
---|
462 | chown -R www-data:www-data ${basetftp} |
---|
463 | } |
---|
464 | |
---|
465 | function testPxe () { |
---|
466 | cd /tmp |
---|
467 | echo "comprobando servicio pxe ..... Espere" |
---|
468 | tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echo "servidor tftp OK" || echo "servidor tftp KO" |
---|
469 | cd / |
---|
470 | } |
---|
471 | |
---|
472 | ######################################################################## |
---|
473 | ## Configuracion servicio nfs |
---|
474 | ######################################################################## |
---|
475 | |
---|
476 | function nfsConfigure (){ |
---|
477 | # FALTA: las variables se pediran al principio de la instalacion y no aqui |
---|
478 | # FALTA: control de errores |
---|
479 | echo "Configurando servicio nfs:" |
---|
480 | local ip_server |
---|
481 | local net_mask |
---|
482 | read -p "Ip del servidor: " ip_server |
---|
483 | read -p "Mascara de red: " net_mask |
---|
484 | |
---|
485 | sed s/IP/$ip_server/g $WORKDIR/opengnsys/server/NFS/exports | sed s/NETMASK/$net_mask/g >> /etc/exports |
---|
486 | echo "Se ha configurado el servicio nfs con la ip $ip_server y la mascara de red $net_mask" |
---|
487 | |
---|
488 | } |
---|
489 | |
---|
490 | |
---|
491 | ##################################################################### |
---|
492 | ####### Funciones específicas de la instalación de Opengnsys |
---|
493 | ##################################################################### |
---|
494 | |
---|
495 | function openGnsysInstallWebConsoleApacheConf() |
---|
496 | { |
---|
497 | if [ $# -ne 2 ]; then |
---|
498 | errorAndLog "openGnsysInstallWebConsoleApacheConf(): invalid number of parameters" |
---|
499 | exit 1 |
---|
500 | fi |
---|
501 | |
---|
502 | local path_opengnsys_base=$1 |
---|
503 | local path_apache2_confd=$2 |
---|
504 | local path_web_console=${path_opengnsys_base}/www |
---|
505 | |
---|
506 | if [ ! -d $path_apache2_confd ]; then |
---|
507 | errorAndLog "openGnsysInstallWebConsoleApacheConf(): path to apache2 conf.d can not found, verify your server installation" |
---|
508 | return 1 |
---|
509 | fi |
---|
510 | |
---|
511 | [ -d $path_apache2_confd/sites-available ] || mkdir $path_apache2_confd/sites-available |
---|
512 | [ -d $path_apache2_confd/sites-enabled ] || mkdir $path_apache2_confd/sites-enabled |
---|
513 | |
---|
514 | echoAndLog "openGnsysInstallWebConsoleApacheConf(): creating apache2 config file.." |
---|
515 | |
---|
516 | # genera configuración |
---|
517 | cat > $path_opengnsys_base/etc/apache.conf <<EOF |
---|
518 | # Hidra web interface configuration for Apache |
---|
519 | |
---|
520 | Alias /opengnsys ${path_web_console} |
---|
521 | |
---|
522 | <Directory ${path_web_console}> |
---|
523 | Options -Indexes FollowSymLinks |
---|
524 | DirectoryIndex acceso.php |
---|
525 | </Directory> |
---|
526 | EOF |
---|
527 | |
---|
528 | |
---|
529 | ln -s $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys.conf |
---|
530 | ln -s $path_apache2_confd/sites-available/opengnsys.conf $path_apache2_confd/sites-enabled/opengnsys.conf |
---|
531 | if [ $? -ne 0 ]; then |
---|
532 | errorAndLog "openGnsysInstallWebConsoleApacheConf(): config file can't be linked to apache conf, verify your server installation" |
---|
533 | return 1 |
---|
534 | else |
---|
535 | echoAndLog "openGnsysInstallWebConsoleApacheConf(): config file created and linked, restart your apache daemon" |
---|
536 | return 0 |
---|
537 | fi |
---|
538 | } |
---|
539 | |
---|
540 | # Crea la estructura base de la instalación de opengnsys |
---|
541 | openGnsysInstallCreateDirs() |
---|
542 | { |
---|
543 | if [ $# -ne 1 ]; then |
---|
544 | errorAndLog "openGnsysInstallCreateDirs(): invalid number of parameters" |
---|
545 | exit 1 |
---|
546 | fi |
---|
547 | |
---|
548 | local path_opengnsys_base=$1 |
---|
549 | |
---|
550 | echoAndLog "openGnsysInstallCreateDirs(): creating directory paths in $path_opengnsys_base" |
---|
551 | |
---|
552 | mkdir -p $path_opengnsys_base |
---|
553 | mkdir -p $path_opengnsys_base/admin/{autoexec,comandos,usuarios} |
---|
554 | mkdir -p $path_opengnsys_base/bin |
---|
555 | mkdir -p $path_opengnsys_base/client |
---|
556 | mkdir -p $path_opengnsys_base/etc |
---|
557 | mkdir -p $path_opengnsys_base/lib |
---|
558 | mkdir -p $path_opengnsys_base/log/clients |
---|
559 | mkdir -p $path_opengnsys_base/www |
---|
560 | mkdir -p $path_opengnsys_base/images |
---|
561 | ln -fs /var/lib/tftpboot $path_opengnsys_base/tftpboot |
---|
562 | ln -fs /var/log/opengnsys $path_opengnsys_base/log |
---|
563 | |
---|
564 | if [ $? -ne 0 ]; then |
---|
565 | errorAndLog "openGnsysInstallCreateDirs(): error while creating dirs. Do you have write permissions?" |
---|
566 | return 1 |
---|
567 | fi |
---|
568 | |
---|
569 | echoAndLog "openGnsysInstallCreateDirs(): directory paths created" |
---|
570 | return 0 |
---|
571 | } |
---|
572 | |
---|
573 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
574 | openGnsysCopyServerFiles () { |
---|
575 | if [ $# -ne 1 ]; then |
---|
576 | errorAndLog "openGnsysCopyServerFiles(): invalid number of parameters" |
---|
577 | exit 1 |
---|
578 | fi |
---|
579 | |
---|
580 | local path_opengnsys_base=$1 |
---|
581 | |
---|
582 | local SOURCES=( client/boot/initrd-generator \ |
---|
583 | client/boot/upgrade-clients-udeb.sh \ |
---|
584 | client/boot/udeblist.conf ) |
---|
585 | local TARGETS=( bin/initrd-generator \ |
---|
586 | bin/upgrade-clients-udeb.sh \ |
---|
587 | etc/udeblist.conf ) |
---|
588 | |
---|
589 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
590 | errorAndLog "openGnsysCopyServerFiles(): inconsistent number of array items" |
---|
591 | exit 1 |
---|
592 | fi |
---|
593 | |
---|
594 | echoAndLog "openGnsysCopyServerFiles(): copying files to server directories" |
---|
595 | |
---|
596 | pushd opengnsys >/dev/null |
---|
597 | local i |
---|
598 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
599 | if [ -f "${SOURCES[$i]}" ]; then |
---|
600 | echoAndLog "copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
601 | cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
602 | fi |
---|
603 | if [ -d "${SOURCES[$i]}" ]; then |
---|
604 | echoAndLog "openGnsysCopyServerFiles(): copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
605 | cp -pr "${SOURCES[$i]}/*" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
606 | fi |
---|
607 | done |
---|
608 | popd >/dev/null |
---|
609 | } |
---|
610 | |
---|
611 | #################################################################### |
---|
612 | ### Funciones instalacion cliente opengnsys |
---|
613 | #################################################################### |
---|
614 | |
---|
615 | function openGnsysClientCreate () { |
---|
616 | # FALTA control de errores. |
---|
617 | # Creamos los directorios especificos del cliente |
---|
618 | mkdir -p $INSTALL_TARGET/client/lib/engine/bin |
---|
619 | |
---|
620 | cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client |
---|
621 | cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin |
---|
622 | cp -ar $WORKDIR/opengnsys/client/engine/*.sh $INSTALL_TARGET/client/lib/engine/bin |
---|
623 | |
---|
624 | |
---|
625 | # Creando el client tftp |
---|
626 | $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/ |
---|
627 | |
---|
628 | # Instalando los paquetes udeb y la configuracion |
---|
629 | $INSTALL_TARGET/bin/upgrade-clients-udeb.sh |
---|
630 | |
---|
631 | |
---|
632 | } |
---|
633 | |
---|
634 | |
---|
635 | ##################################################################### |
---|
636 | ####### Proceso de instalación |
---|
637 | ##################################################################### |
---|
638 | |
---|
639 | |
---|
640 | # Proceso de instalación de opengnsys |
---|
641 | declare -a notinstalled |
---|
642 | checkDependencies DEPENDENCIES notinstalled |
---|
643 | if [ $? -ne 0 ]; then |
---|
644 | installDependencies notinstalled |
---|
645 | if [ $? -ne 0 ]; then |
---|
646 | echoAndLog "Error while installing some dependeces, please verify your server installation before continue" |
---|
647 | exit 1 |
---|
648 | fi |
---|
649 | fi |
---|
650 | |
---|
651 | isInArray notinstalled "mysql-server" |
---|
652 | if [ $? -eq 0 ]; then |
---|
653 | mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD} |
---|
654 | else |
---|
655 | mysqlGetRootPassword |
---|
656 | |
---|
657 | fi |
---|
658 | |
---|
659 | openGnsysInstallCreateDirs ${INSTALL_TARGET} |
---|
660 | if [ $? -ne 0 ]; then |
---|
661 | errorAndLog "Error while creating directory paths!" |
---|
662 | exit 1 |
---|
663 | fi |
---|
664 | svnCheckoutCode $SVN_URL |
---|
665 | if [ $? -ne 0 ]; then |
---|
666 | errorAndLog "Error while getting code from svn" |
---|
667 | exit 1 |
---|
668 | fi |
---|
669 | |
---|
670 | openGnsysCopyServerFiles ${INSTALL_TARGET} |
---|
671 | if [ $? -ne 0 ]; then |
---|
672 | errorAndLog "Error while copying the server files!" |
---|
673 | exit 1 |
---|
674 | fi |
---|
675 | |
---|
676 | |
---|
677 | mysqlTestConnection ${MYSQL_ROOT_PASSWORD} |
---|
678 | if [ $? -ne 0 ]; then |
---|
679 | errorAndLog "Error while connection to mysql" |
---|
680 | exit 1 |
---|
681 | fi |
---|
682 | mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
683 | if [ $? -ne 0 ]; then |
---|
684 | echoAndLog "Creating web console database" |
---|
685 | mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
686 | if [ $? -ne 0 ]; then |
---|
687 | errorAndLog "Error while creating hidra database" |
---|
688 | exit 1 |
---|
689 | fi |
---|
690 | else |
---|
691 | echoAndLog "Hidra database exists, ommiting creation" |
---|
692 | fi |
---|
693 | |
---|
694 | mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER} |
---|
695 | if [ $? -ne 0 ]; then |
---|
696 | echoAndLog "Creating user in database" |
---|
697 | mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}" |
---|
698 | if [ $? -ne 0 ]; then |
---|
699 | errorAndLog "Error while creating hidra user" |
---|
700 | exit 1 |
---|
701 | fi |
---|
702 | |
---|
703 | fi |
---|
704 | |
---|
705 | mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
706 | if [ $? -eq 0 ]; then |
---|
707 | echoAndLog "Creating tables..." |
---|
708 | if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then |
---|
709 | mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE |
---|
710 | else |
---|
711 | errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!" |
---|
712 | exit 1 |
---|
713 | fi |
---|
714 | fi |
---|
715 | |
---|
716 | # Configurando tftp |
---|
717 | tftpConfigurate |
---|
718 | pxeTest |
---|
719 | |
---|
720 | echoAndLog "Installing web files..." |
---|
721 | # copiando paqinas web |
---|
722 | cp -pr opengnsys/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para doxigen |
---|
723 | |
---|
724 | # creando configuracion de apache2 |
---|
725 | openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2 |
---|
726 | if [ $? -ne 0 ]; then |
---|
727 | errorAndLog "Error while creating hidra apache config" |
---|
728 | exit 1 |
---|
729 | fi |
---|
730 | |
---|
731 | popd |
---|
732 | |
---|
733 | # Creando la estructura del cliente |
---|
734 | openGnsysClientCreate |
---|
735 | |
---|
736 | #rm -rf $WORKDIR |
---|
737 | echoAndLog "Process finalized!" |
---|
738 | |
---|
739 | |
---|
740 | |
---|
741 | |
---|