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 |
---|
21 | |
---|
22 | # Datos de base de datos |
---|
23 | HIDRA_DATABASE=bdhidra |
---|
24 | HIDRA_DB_USER=usuhidra |
---|
25 | HIDRA_DB_PASSWD=passusuhidra |
---|
26 | HIDRA_DB_CREATION_FILE=eac-hidra/branches/eac-hidra-us/Hidra/doc/hidra-bd.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 | # comprueba si puede conectar con mysql con el usuario root |
---|
217 | function mysqlTestConnection() |
---|
218 | { |
---|
219 | if [ $# -ne 1 ]; then |
---|
220 | errorAndLog "mysqlTestConnection(): invalid number of parameters" |
---|
221 | exit 1 |
---|
222 | fi |
---|
223 | |
---|
224 | local root_password="${1}" |
---|
225 | echoAndLog "mysqlTestConnection(): checking connection to mysql..." |
---|
226 | echo "" | mysql -uroot -p"${root_password}" |
---|
227 | if [ $? -ne 0 ]; then |
---|
228 | errorAndLog "mysqlTestConnection(): connection to mysql failed, check root password and if daemon is running!" |
---|
229 | return 1 |
---|
230 | else |
---|
231 | echoAndLog "mysqlTestConnection(): connection success" |
---|
232 | return 0 |
---|
233 | fi |
---|
234 | } |
---|
235 | |
---|
236 | # comprueba si la base de datos existe |
---|
237 | function mysqlDbExists() |
---|
238 | { |
---|
239 | if [ $# -ne 2 ]; then |
---|
240 | errorAndLog "mysqlDbExists(): invalid number of parameters" |
---|
241 | exit 1 |
---|
242 | fi |
---|
243 | |
---|
244 | local root_password="${1}" |
---|
245 | local database=$2 |
---|
246 | echoAndLog "mysqlDbExists(): checking if $database exists..." |
---|
247 | echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$" |
---|
248 | if [ $? -ne 0 ]; then |
---|
249 | echoAndLog "mysqlDbExists():database $database doesn't exists" |
---|
250 | return 1 |
---|
251 | else |
---|
252 | echoAndLog "mysqlDbExists():database $database exists" |
---|
253 | return 0 |
---|
254 | fi |
---|
255 | } |
---|
256 | |
---|
257 | function mysqlCheckDbIsEmpty() |
---|
258 | { |
---|
259 | if [ $# -ne 2 ]; then |
---|
260 | errorAndLog "mysqlCheckDbIsEmpty(): invalid number of parameters" |
---|
261 | exit 1 |
---|
262 | fi |
---|
263 | |
---|
264 | local root_password="${1}" |
---|
265 | local database=$2 |
---|
266 | echoAndLog "mysqlCheckDbIsEmpty(): checking if $database is empty..." |
---|
267 | num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l` |
---|
268 | if [ $? -ne 0 ]; then |
---|
269 | errorAndLog "mysqlCheckDbIsEmpty(): error executing query, check database and root password" |
---|
270 | exit 1 |
---|
271 | fi |
---|
272 | |
---|
273 | if [ $num_tablas -eq 0 ]; then |
---|
274 | echoAndLog "mysqlCheckDbIsEmpty():database $database is empty" |
---|
275 | return 0 |
---|
276 | else |
---|
277 | echoAndLog "mysqlCheckDbIsEmpty():database $database has tables" |
---|
278 | return 1 |
---|
279 | fi |
---|
280 | |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | function mysqlImportSqlFileToDb() |
---|
285 | { |
---|
286 | if [ $# -ne 3 ]; then |
---|
287 | errorAndLog "mysqlImportSqlFileToDb(): invalid number of parameters" |
---|
288 | exit 1 |
---|
289 | fi |
---|
290 | |
---|
291 | local root_password="${1}" |
---|
292 | local database=$2 |
---|
293 | local sqlfile=$3 |
---|
294 | |
---|
295 | if [ ! -f $sqlfile ]; then |
---|
296 | errorAndLog "mysqlImportSqlFileToDb(): Unable to locate $sqlfile!!" |
---|
297 | return 1 |
---|
298 | fi |
---|
299 | |
---|
300 | echoAndLog "mysqlImportSqlFileToDb(): importing sql file to ${database}..." |
---|
301 | mysql -uroot -p"${root_password}" "${database}" < $sqlfile |
---|
302 | if [ $? -ne 0 ]; then |
---|
303 | errorAndLog "mysqlImportSqlFileToDb(): error while importing $sqlfile in database $database" |
---|
304 | return 1 |
---|
305 | fi |
---|
306 | echoAndLog "mysqlImportSqlFileToDb(): file imported to database $database" |
---|
307 | return 0 |
---|
308 | } |
---|
309 | |
---|
310 | # Crea la base de datos |
---|
311 | function mysqlCreateDb() |
---|
312 | { |
---|
313 | if [ $# -ne 2 ]; then |
---|
314 | errorAndLog "mysqlCreateDb(): invalid number of parameters" |
---|
315 | exit 1 |
---|
316 | fi |
---|
317 | |
---|
318 | local root_password="${1}" |
---|
319 | local database=$2 |
---|
320 | |
---|
321 | echoAndLog "mysqlCreateDb(): creating database..." |
---|
322 | mysqladmin -u root --password="${root_password}" create $database |
---|
323 | if [ $? -ne 0 ]; then |
---|
324 | errorAndLog "mysqlCreateDb(): error while creating database $database" |
---|
325 | return 1 |
---|
326 | fi |
---|
327 | errorAndLog "mysqlCreateDb(): database $database created" |
---|
328 | return 0 |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | function mysqlCheckUserExists() |
---|
333 | { |
---|
334 | if [ $# -ne 2 ]; then |
---|
335 | errorAndLog "mysqlCheckUserExists(): invalid number of parameters" |
---|
336 | exit 1 |
---|
337 | fi |
---|
338 | |
---|
339 | local root_password="${1}" |
---|
340 | local userdb=$2 |
---|
341 | |
---|
342 | echoAndLog "mysqlCheckUserExists(): checking if $userdb exists..." |
---|
343 | echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user |
---|
344 | if [ $? -ne 0 ]; then |
---|
345 | echoAndLog "mysqlCheckUserExists(): user doesn't exists" |
---|
346 | return 1 |
---|
347 | else |
---|
348 | echoAndLog "mysqlCheckUserExists(): user already exists" |
---|
349 | return 0 |
---|
350 | fi |
---|
351 | |
---|
352 | } |
---|
353 | |
---|
354 | # Crea un usuario administrativo para la base de datos |
---|
355 | function mysqlCreateAdminUserToDb() |
---|
356 | { |
---|
357 | if [ $# -ne 4 ]; then |
---|
358 | errorAndLog "mysqlCreateAdminUserToDb(): invalid number of parameters" |
---|
359 | exit 1 |
---|
360 | fi |
---|
361 | |
---|
362 | local root_password=$1 |
---|
363 | local database=$2 |
---|
364 | local userdb=$3 |
---|
365 | local passdb=$4 |
---|
366 | |
---|
367 | echoAndLog "mysqlCreateAdminUserToDb(): creating admin user ${userdb} to database ${database}" |
---|
368 | |
---|
369 | cat > $WORKDIR/create_${database}.sql <<EOF |
---|
370 | GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ; |
---|
371 | GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ; |
---|
372 | FLUSH PRIVILEGES ; |
---|
373 | EOF |
---|
374 | mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql |
---|
375 | if [ $? -ne 0 ]; then |
---|
376 | errorAndLog "mysqlCreateAdminUserToDb(): error while creating user in mysql" |
---|
377 | rm -f $WORKDIR/create_${database}.sql |
---|
378 | return 1 |
---|
379 | else |
---|
380 | echoAndLog "mysqlCreateAdminUserToDb(): user created ok" |
---|
381 | rm -f $WORKDIR/create_${database}.sql |
---|
382 | return 0 |
---|
383 | fi |
---|
384 | } |
---|
385 | |
---|
386 | |
---|
387 | ##################################################################### |
---|
388 | ####### Funciones para el manejo de Subversion |
---|
389 | ##################################################################### |
---|
390 | |
---|
391 | svnCheckoutCode() |
---|
392 | { |
---|
393 | if [ $# -ne 1 ]; then |
---|
394 | errorAndLog "svnCheckoutCode(): invalid number of parameters" |
---|
395 | exit 1 |
---|
396 | fi |
---|
397 | |
---|
398 | local url=$1 |
---|
399 | |
---|
400 | echoAndLog "svnCheckoutCode(): downloading subversion code..." |
---|
401 | |
---|
402 | /usr/bin/svn co "${url}" |
---|
403 | if [ $? -ne 0 ]; then |
---|
404 | errorAndLog "svnCheckoutCode(): error getting code from ${url}, verify your user and password" |
---|
405 | return 1 |
---|
406 | fi |
---|
407 | echoAndLog "svnCheckoutCode(): subversion code downloaded" |
---|
408 | return 0 |
---|
409 | } |
---|
410 | |
---|
411 | ##################################################################### |
---|
412 | ####### Funciones específicas de la instalación de Opengnsys |
---|
413 | ##################################################################### |
---|
414 | |
---|
415 | function openGnsysInstallHidraApacheConf() |
---|
416 | { |
---|
417 | if [ $# -ne 2 ]; then |
---|
418 | errorAndLog "openGnsysInstallHidraApacheConf(): invalid number of parameters" |
---|
419 | exit 1 |
---|
420 | fi |
---|
421 | |
---|
422 | local path_opengnsys_base=$1 |
---|
423 | local path_apache2_confd=$2 |
---|
424 | local path_web_hidra=${path_opengnsys_base}/www |
---|
425 | |
---|
426 | echoAndLog "openGnsysInstallHidraApacheConf(): creating apache2 config file.." |
---|
427 | |
---|
428 | # genera configuración |
---|
429 | cat > $WORKDIR/apache.conf <<EOF |
---|
430 | # Hidra web interface configuration for Apache |
---|
431 | |
---|
432 | Alias /hidra ${path_web_hidra} |
---|
433 | |
---|
434 | <Directory ${path_web_hidra}> |
---|
435 | Options -Indexes FollowSymLinks |
---|
436 | DirectoryIndex acceso.php |
---|
437 | </Directory> |
---|
438 | EOF |
---|
439 | |
---|
440 | if [ ! -d $path_apache2_confd ]; then |
---|
441 | errorAndLog "openGnsysInstallHidraApacheConf(): path to apache2 conf.d can not found, verify your server installation" |
---|
442 | rm -f $WORKDIR/apache.conf |
---|
443 | return 1 |
---|
444 | fi |
---|
445 | cp $WORKDIR/apache.conf $path_opengnsys_base/etc |
---|
446 | ln -s $path_opengnsys_base/etc/apache.conf $path_apache2_confd/hidra.conf |
---|
447 | if [ $? -ne 0 ]; then |
---|
448 | errorAndLog "openGnsysInstallHidraApacheConf(): config file can't be linked to apache conf, verify your server installation" |
---|
449 | rm -f $WORKDIR/apache.conf |
---|
450 | return 1 |
---|
451 | else |
---|
452 | echoAndLog "openGnsysInstallHidraApacheConf(): config file created and linked, restart your apache daemon" |
---|
453 | rm -f $WORKDIR/apache.conf |
---|
454 | return 0 |
---|
455 | fi |
---|
456 | } |
---|
457 | |
---|
458 | # Crea la estructura base de la instalación de opengnsys |
---|
459 | openGnsysInstallCreateDirs() |
---|
460 | { |
---|
461 | if [ $# -ne 1 ]; then |
---|
462 | errorAndLog "openGnsysInstallCreateDirs(): invalid number of parameters" |
---|
463 | exit 1 |
---|
464 | fi |
---|
465 | |
---|
466 | local path_opengnsys_base=$1 |
---|
467 | |
---|
468 | echoAndLog "openGnsysInstallCreateDirs(): creating directory paths in $path_opengnsys_base" |
---|
469 | |
---|
470 | mkdir -p $path_opengnsys_base |
---|
471 | mkdir -p $path_opengnsys_base/bin |
---|
472 | mkdir -p $path_opengnsys_base/client |
---|
473 | mkdir -p $path_opengnsys_base/etc |
---|
474 | mkdir -p $path_opengnsys_base/lib |
---|
475 | mkdir -p $path_opengnsys_base/log/clients |
---|
476 | mkdir -p $path_opengnsys_base/www |
---|
477 | mkdir -p $path_opengnsys_base/tftpboot/ogclients |
---|
478 | mkdir -p $path_opengnsys_base/images |
---|
479 | |
---|
480 | if [ $? -ne 0 ]; then |
---|
481 | errorAndLog "openGnsysInstallCreateDirs(): error while creating dirs. Do you have write permissions?" |
---|
482 | return 1 |
---|
483 | fi |
---|
484 | |
---|
485 | echoAndLog "openGnsysInstallCreateDirs(): directory paths created" |
---|
486 | return 0 |
---|
487 | } |
---|
488 | |
---|
489 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
490 | openGnsysCopyServerFiles () { |
---|
491 | if [ $# -ne 1 ]; then |
---|
492 | errorAndLog "openGnsysCopyServerFiles(): invalid number of parameters" |
---|
493 | exit 1 |
---|
494 | fi |
---|
495 | |
---|
496 | local path_opengnsys_base=$1 |
---|
497 | |
---|
498 | local SOURCES=( client/boot/initrd-generator \ |
---|
499 | client/boot/upgrade-clients-udeb.sh \ |
---|
500 | client/boot/udeblist.conf ) |
---|
501 | local TARGETS=( bin/initrd-generator \ |
---|
502 | bin/upgrade-clients-udeb.sh \ |
---|
503 | etc/udeblist.conf ) |
---|
504 | |
---|
505 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
506 | errorAndLog "openGnsysCopyServerFiles(): inconsistent number of array items" |
---|
507 | exit 1 |
---|
508 | fi |
---|
509 | |
---|
510 | echoAndLog "openGnsysCopyServerFiles(): copying files to server directories" |
---|
511 | |
---|
512 | pushd opengnsys/trunk >/dev/null |
---|
513 | local i |
---|
514 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
515 | if [ -f "${SOURCES[$i]}" ]; then |
---|
516 | echoAndLog "copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
517 | cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
518 | fi |
---|
519 | if [ -d "${SOURCES[$i]}" ]; then |
---|
520 | echoAndLog "openGnsysCopyServerFiles(): copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
521 | cp -pr "${SOURCES[$i]}/*" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
522 | fi |
---|
523 | done |
---|
524 | popd >/dev/null |
---|
525 | } |
---|
526 | |
---|
527 | |
---|
528 | ##################################################################### |
---|
529 | ####### Proceso de instalación |
---|
530 | ##################################################################### |
---|
531 | |
---|
532 | |
---|
533 | # Proceso de instalación de opengnsys |
---|
534 | declare -a notinstalled |
---|
535 | checkDependencies DEPENDENCIES notinstalled |
---|
536 | if [ $? -ne 0 ]; then |
---|
537 | installDependencies notinstalled |
---|
538 | if [ $? -ne 0 ]; then |
---|
539 | echoAndLog "Error while installing some dependeces, please verify your server installation before continue" |
---|
540 | exit 1 |
---|
541 | fi |
---|
542 | fi |
---|
543 | |
---|
544 | isInArray notinstalled "mysql-server" |
---|
545 | if [ $? -eq 0 ]; then |
---|
546 | mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD} |
---|
547 | fi |
---|
548 | |
---|
549 | openGnsysInstallCreateDirs ${INSTALL_TARGET} |
---|
550 | if [ $? -ne 0 ]; then |
---|
551 | errorAndLog "Error while creating directory paths!" |
---|
552 | exit 1 |
---|
553 | fi |
---|
554 | svnCheckoutCode $SVN_URL |
---|
555 | if [ $? -ne 0 ]; then |
---|
556 | errorAndLog "Error while getting code from svn" |
---|
557 | exit 1 |
---|
558 | fi |
---|
559 | |
---|
560 | openGnsysCopyServerFiles ${INSTALL_TARGET} |
---|
561 | if [ $? -ne 0 ]; then |
---|
562 | errorAndLog "Error while copying the server files!" |
---|
563 | exit 1 |
---|
564 | fi |
---|
565 | |
---|
566 | |
---|
567 | mysqlTestConnection ${MYSQL_ROOT_PASSWORD} |
---|
568 | if [ $? -ne 0 ]; then |
---|
569 | errorAndLog "Error while connection to mysql" |
---|
570 | exit 1 |
---|
571 | fi |
---|
572 | mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${HIDRA_DATABASE} |
---|
573 | if [ $? -ne 0 ]; then |
---|
574 | echoAndLog "Creating hidra database" |
---|
575 | mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${HIDRA_DATABASE} |
---|
576 | if [ $? -ne 0 ]; then |
---|
577 | errorAndLog "Error while creating hidra database" |
---|
578 | exit 1 |
---|
579 | fi |
---|
580 | else |
---|
581 | echoAndLog "Hidra database exists, ommiting creation" |
---|
582 | fi |
---|
583 | |
---|
584 | mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${HIDRA_DB_USER} |
---|
585 | if [ $? -ne 0 ]; then |
---|
586 | echoAndLog "Creating user in database" |
---|
587 | mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${HIDRA_DATABASE} ${HIDRA_DB_USER} "${HIDRA_DB_PASS}" |
---|
588 | if [ $? -ne 0 ]; then |
---|
589 | errorAndLog "Error while creating hidra user" |
---|
590 | exit 1 |
---|
591 | fi |
---|
592 | |
---|
593 | fi |
---|
594 | |
---|
595 | mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${HIDRA_DATABASE} |
---|
596 | if [ $? -eq 0 ]; then |
---|
597 | echoAndLog "Creating tables..." |
---|
598 | if [ -f $WORKDIR/$HIDRA_DB_CREATION_FILE ]; then |
---|
599 | mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${HIDRA_DATABASE} $WORKDIR/$HIDRA_DB_CREATION_FILE |
---|
600 | else |
---|
601 | errorAndLog "Unable to locate $WORKDIR/$HIDRA_DB_CREATION_FILE!!" |
---|
602 | exit 1 |
---|
603 | fi |
---|
604 | fi |
---|
605 | |
---|
606 | echoAndLog "Installing web files..." |
---|
607 | # copiando paqinas web |
---|
608 | cp -pr eac-hidra/branches/eac-hidra-us/Hidra/webhidra/* $INSTALL_TARGET/www #*/ comentario para doxigen |
---|
609 | |
---|
610 | # creando configuracion de apache2 |
---|
611 | openGnsysInstallHidraApacheConf $INSTALL_TARGET /etc/apache2/conf.d |
---|
612 | if [ $? -ne 0 ]; then |
---|
613 | errorAndLog "Error while creating hidra apache config" |
---|
614 | exit 1 |
---|
615 | fi |
---|
616 | |
---|
617 | popd |
---|
618 | #rm -rf $WORKDIR |
---|
619 | echoAndLog "Process finalized!" |
---|
620 | |
---|
621 | |
---|
622 | |
---|
623 | function TestPxe () { |
---|
624 | cd /tmp |
---|
625 | echo "comprobando servidio pxe ..... Espere" |
---|
626 | tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echo "servidor tftp OK" || echo "servidor tftp KO" |
---|
627 | cd / |
---|
628 | } |
---|
629 | |
---|
630 | function preparacontenedortft() { |
---|
631 | ############################################################ |
---|
632 | ### Esqueleto para el Servicio pxe y contenedor tftpboot ############## |
---|
633 | ########################################################### |
---|
634 | basetftp=/var/lib/tftpboot |
---|
635 | basetftpaux=/tftpboot |
---|
636 | basetftpog=/opt/opengnsys/tftpboot |
---|
637 | # creamos los correspondientes enlaces hacia nuestro contenedor. |
---|
638 | ln -s ${basetftp} ${basetftpog} |
---|
639 | ln -s ${basetftpaux} ${basetftpog} |
---|
640 | |
---|
641 | # reiniciamos demonio internet |
---|
642 | /etc/init.d/openbsd-inetd start |
---|
643 | |
---|
644 | ##preparcion contendor tftpboot |
---|
645 | cp -pr /usr/lib/syslinux/ ${basetftpboot}/syslinux |
---|
646 | cp /usr/lib/syslinux/pxelinux.0 $basetftpboot |
---|
647 | # prepamos el directorio de la configuracion de pxe |
---|
648 | mkdir -p ${basetftpboot}/pxelinux.cfg |
---|
649 | touch ${basetftpboot}/pxelinux.cfg/default |
---|
650 | # comprobamos el servicio tftp |
---|
651 | sleep 1 |
---|
652 | TestPxe |
---|
653 | ## damos perfimos de lectura a usuario web. |
---|
654 | chown -R www-data:www-data /var/lib/tftpboot |
---|
655 | ######### fin revisar2 contenedor tftp |
---|
656 | } |
---|
657 | |
---|