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 tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential libmysqlclient15-dev ) |
---|
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 | function 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 | ### Detectar red |
---|
437 | ############################################################ |
---|
438 | |
---|
439 | function getNetworkSettings() |
---|
440 | { |
---|
441 | # Variables globales definidas: |
---|
442 | # - SERVERIP: IP local del servidor. |
---|
443 | # - NETIP: IP de la red. |
---|
444 | # - NETMASK: máscara de red. |
---|
445 | # - NETBROAD: IP de difusión de la red. |
---|
446 | # - ROUTERIP: IP del router. |
---|
447 | # - DNSIP: IP del servidor DNS. |
---|
448 | |
---|
449 | echoAndLog "getNetworkSettings(): Detecting default network parameters." |
---|
450 | SERVERIP=$(LANG=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | head -n1 | awk '{print $1}') |
---|
451 | NETMASK=$(LANG=C ifconfig | grep 'Mask:'| grep -v '127.0.0.1' | cut -d: -f4 | head -n1 | awk '{print $1}') |
---|
452 | NETBROAD=$(LANG=C ifconfig | grep 'Bcast:'| grep -v '127.0.0.1' | cut -d: -f3 | head -n1 | awk '{print $1}') |
---|
453 | NETIP=$(netstat -r | grep $NETMASK | awk '{print $1}') |
---|
454 | ROUTERIP=$(netstat -nr | awk '$1~/0\.0\.0\.0/ {print $2}') |
---|
455 | DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf) |
---|
456 | if [ -z "$NETIP" -o -z "$NETMASK" ]; then |
---|
457 | errorAndLog "getNetworkSettings(): Network not detected." |
---|
458 | exit 1 |
---|
459 | fi |
---|
460 | |
---|
461 | # Variables de ejecución de Apache |
---|
462 | # - APACHE_RUN_USER |
---|
463 | # - APACHE_RUN_GROUP |
---|
464 | if [ -f /etc/apache2/envvars ]; then |
---|
465 | source /etc/apache2/envvars |
---|
466 | fi |
---|
467 | APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"} |
---|
468 | APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"} |
---|
469 | } |
---|
470 | |
---|
471 | |
---|
472 | ############################################################ |
---|
473 | ### Esqueleto para el Servicio pxe y contenedor tftpboot ### |
---|
474 | ############################################################ |
---|
475 | |
---|
476 | function tftpConfigure() { |
---|
477 | echo "Configurando el servicio tftp" |
---|
478 | basetftp=/var/lib/tftpboot |
---|
479 | |
---|
480 | # reiniciamos demonio internet ????? porque ???? |
---|
481 | /etc/init.d/openbsd-inetd start |
---|
482 | |
---|
483 | # preparacion contenedor tftpboot |
---|
484 | cp -pr /usr/lib/syslinux/ ${basetftp}/syslinux |
---|
485 | cp /usr/lib/syslinux/pxelinux.0 ${basetftp} |
---|
486 | # prepamos el directorio de la configuracion de pxe |
---|
487 | mkdir -p ${basetftp}/pxelinux.cfg |
---|
488 | cat > ${basetftp}/pxelinux.cfg/default <<EOF |
---|
489 | DEFAULT pxe |
---|
490 | |
---|
491 | LABEL pxe |
---|
492 | KERNEL linux |
---|
493 | APPEND initrd=initrd.gz ip=dhcp ro vga=788 irqpoll acpi=on |
---|
494 | EOF |
---|
495 | # comprobamos el servicio tftp |
---|
496 | sleep 1 |
---|
497 | testPxe |
---|
498 | ## damos perfimos de lectura a usuario web. |
---|
499 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP ${basetftp} |
---|
500 | } |
---|
501 | |
---|
502 | function testPxe () { |
---|
503 | cd /tmp |
---|
504 | echo "comprobando servicio pxe ..... Espere" |
---|
505 | tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echo "servidor tftp OK" || echo "servidor tftp KO" |
---|
506 | cd / |
---|
507 | } |
---|
508 | |
---|
509 | ######################################################################## |
---|
510 | ## Configuracion servicio NFS |
---|
511 | ######################################################################## |
---|
512 | |
---|
513 | function nfsConfigure () |
---|
514 | { |
---|
515 | echoAndLog "nfsConfigure(): Sample NFS Configuration." |
---|
516 | sed -e "s/NETIP/$NETIP/g" -e "s/NETMASK/$NETMASK/g" $WORKDIR/opengnsys/server/NFS/exports >> /etc/exports |
---|
517 | /etc/init.d/nfs-kernel-server restart |
---|
518 | exportfs -va |
---|
519 | echoAndLog "nfsConfigure(): Sample NFS Configured in file \"/etc/exports\"." |
---|
520 | } |
---|
521 | |
---|
522 | |
---|
523 | ######################################################################## |
---|
524 | ## Configuracion servicio DHCP |
---|
525 | ######################################################################## |
---|
526 | |
---|
527 | function dhcpConfigure() |
---|
528 | { |
---|
529 | echoAndLog "dhcpConfigure(): Sample DHCP Configuration." |
---|
530 | sed -e "s/SERVERIP/$SERVERIP/g" \ |
---|
531 | -e "s/NETIP/$NETIP/g" \ |
---|
532 | -e "s/NETMASK/$NETMASK/g" \ |
---|
533 | -e "s/NETBROAD/$NETBROAD/g" \ |
---|
534 | -e "s/ROUTERIP/$ROUTERIP/g" \ |
---|
535 | -e "s/DNSIP/$DNSIP/g" \ |
---|
536 | $WORKDIR/opengnsys/server/DHCP/dhcpd.conf > /etc/dhcp3/dhcpd.conf |
---|
537 | /etc/init.d/dhcp3-server restart |
---|
538 | echoAndLog "dhcpConfigure(): Sample DHCP Configured in file \"/etc/dhcp3/dhcpd.conf\"." |
---|
539 | } |
---|
540 | |
---|
541 | |
---|
542 | ##################################################################### |
---|
543 | ####### Funciones específicas de la instalación de Opengnsys |
---|
544 | ##################################################################### |
---|
545 | |
---|
546 | # Copiar ficheros del OpenGNSys Web Console. |
---|
547 | function installWebFiles() |
---|
548 | { |
---|
549 | echoAndLog "installWebFiles(): Installing web files..." |
---|
550 | cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para doxigen |
---|
551 | if [ $? != 0 ]; then |
---|
552 | errorAndLog "installWebFiles(): Error copying web files." |
---|
553 | exit 1 |
---|
554 | fi |
---|
555 | find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
556 | # Cambiar permisos para ficheros especiales. |
---|
557 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP \ |
---|
558 | $INSTALL_TARGET/www/includes \ |
---|
559 | $INSTALL_TARGET/www/comandos/gestores/filescripts \ |
---|
560 | $INSTALL_TARGET/www/images/icons |
---|
561 | echoAndLog "installWebFiles(): Web files installed successfully." |
---|
562 | } |
---|
563 | |
---|
564 | # Configuración específica de Apache. |
---|
565 | function openGnsysInstallWebConsoleApacheConf() |
---|
566 | { |
---|
567 | if [ $# -ne 2 ]; then |
---|
568 | errorAndLog "openGnsysInstallWebConsoleApacheConf(): invalid number of parameters" |
---|
569 | exit 1 |
---|
570 | fi |
---|
571 | |
---|
572 | local path_opengnsys_base=$1 |
---|
573 | local path_apache2_confd=$2 |
---|
574 | local path_web_console=${path_opengnsys_base}/www |
---|
575 | |
---|
576 | if [ ! -d $path_apache2_confd ]; then |
---|
577 | errorAndLog "openGnsysInstallWebConsoleApacheConf(): path to apache2 conf.d can not found, verify your server installation" |
---|
578 | return 1 |
---|
579 | fi |
---|
580 | |
---|
581 | mkdir -p $path_apache2_confd/{sites-available,sites-enabled} |
---|
582 | |
---|
583 | echoAndLog "openGnsysInstallWebConsoleApacheConf(): creating apache2 config file.." |
---|
584 | |
---|
585 | # genera configuración |
---|
586 | cat > $path_opengnsys_base/etc/apache.conf <<EOF |
---|
587 | # OpenGNSys Web Console configuration for Apache |
---|
588 | |
---|
589 | Alias /opengnsys ${path_web_console} |
---|
590 | |
---|
591 | <Directory ${path_web_console}> |
---|
592 | Options -Indexes FollowSymLinks |
---|
593 | DirectoryIndex acceso.php |
---|
594 | </Directory> |
---|
595 | EOF |
---|
596 | |
---|
597 | ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys.conf |
---|
598 | ln -fs $path_apache2_confd/sites-available/opengnsys.conf $path_apache2_confd/sites-enabled/opengnsys.conf |
---|
599 | if [ $? -ne 0 ]; then |
---|
600 | errorAndLog "openGnsysInstallWebConsoleApacheConf(): config file can't be linked to apache conf, verify your server installation" |
---|
601 | return 1 |
---|
602 | else |
---|
603 | echoAndLog "openGnsysInstallWebConsoleApacheConf(): config file created and linked, restart your apache daemon" |
---|
604 | return 0 |
---|
605 | fi |
---|
606 | } |
---|
607 | |
---|
608 | # Crea la estructura base de la instalación de opengnsys |
---|
609 | function openGnsysInstallCreateDirs() |
---|
610 | { |
---|
611 | if [ $# -ne 1 ]; then |
---|
612 | errorAndLog "openGnsysInstallCreateDirs(): invalid number of parameters" |
---|
613 | exit 1 |
---|
614 | fi |
---|
615 | |
---|
616 | local path_opengnsys_base=$1 |
---|
617 | |
---|
618 | echoAndLog "openGnsysInstallCreateDirs(): creating directory paths in $path_opengnsys_base" |
---|
619 | |
---|
620 | mkdir -p $path_opengnsys_base |
---|
621 | mkdir -p $path_opengnsys_base/admin/{autoexec,comandos,menus,scripts,usuarios} |
---|
622 | mkdir -p $path_opengnsys_base/bin |
---|
623 | mkdir -p $path_opengnsys_base/client |
---|
624 | mkdir -p $path_opengnsys_base/etc |
---|
625 | mkdir -p $path_opengnsys_base/lib |
---|
626 | mkdir -p $path_opengnsys_base/log/clients |
---|
627 | mkdir -p $path_opengnsys_base/sbin |
---|
628 | mkdir -p $path_opengnsys_base/www |
---|
629 | mkdir -p $path_opengnsys_base/images |
---|
630 | ln -fs /var/lib/tftpboot $path_opengnsys_base |
---|
631 | ln -fs $path_opengnsys_base/log /var/log/opengnsys |
---|
632 | |
---|
633 | if [ $? -ne 0 ]; then |
---|
634 | errorAndLog "openGnsysInstallCreateDirs(): error while creating dirs. Do you have write permissions?" |
---|
635 | return 1 |
---|
636 | fi |
---|
637 | |
---|
638 | echoAndLog "openGnsysInstallCreateDirs(): directory paths created" |
---|
639 | return 0 |
---|
640 | } |
---|
641 | |
---|
642 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
643 | function openGnsysCopyServerFiles () { |
---|
644 | if [ $# -ne 1 ]; then |
---|
645 | errorAndLog "openGnsysCopyServerFiles(): invalid number of parameters" |
---|
646 | exit 1 |
---|
647 | fi |
---|
648 | |
---|
649 | local path_opengnsys_base=$1 |
---|
650 | |
---|
651 | local SOURCES=( client/boot/initrd-generator \ |
---|
652 | client/boot/upgrade-clients-udeb.sh \ |
---|
653 | client/boot/udeblist.conf ) |
---|
654 | local TARGETS=( bin/initrd-generator \ |
---|
655 | bin/upgrade-clients-udeb.sh \ |
---|
656 | etc/udeblist.conf ) |
---|
657 | |
---|
658 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
659 | errorAndLog "openGnsysCopyServerFiles(): inconsistent number of array items" |
---|
660 | exit 1 |
---|
661 | fi |
---|
662 | |
---|
663 | echoAndLog "openGnsysCopyServerFiles(): copying files to server directories" |
---|
664 | |
---|
665 | pushd $WORKDIR/opengnsys |
---|
666 | local i |
---|
667 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
668 | if [ -f "${SOURCES[$i]}" ]; then |
---|
669 | echoAndLog "copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
670 | cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
671 | fi |
---|
672 | if [ -d "${SOURCES[$i]}" ]; then |
---|
673 | echoAndLog "openGnsysCopyServerFiles(): copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
674 | cp -ar "${SOURCES[$i]}/*" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
675 | fi |
---|
676 | done |
---|
677 | popd |
---|
678 | } |
---|
679 | |
---|
680 | #################################################################### |
---|
681 | ### Funciones de compilación de códifo fuente de servicios |
---|
682 | #################################################################### |
---|
683 | |
---|
684 | # Compilar los servicios de OpenGNsys |
---|
685 | function servicesCompilation () |
---|
686 | { |
---|
687 | # Compilar OpenGNSys Server |
---|
688 | echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Server" |
---|
689 | pushd $WORKDIR/opengnsys/admin/Services/ogAdmServer |
---|
690 | make && make install |
---|
691 | popd |
---|
692 | # Compilar OpenGNSys Repository Manager |
---|
693 | echoAndLog "servicesCompilation(): Compiling OpenGNSys Repository Manager" |
---|
694 | pushd $WORKDIR/opengnsys/admin/Services/ogAdmRepo |
---|
695 | make && make install |
---|
696 | popd |
---|
697 | # Compilar OpenGNSys Client |
---|
698 | echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Client" |
---|
699 | pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient |
---|
700 | make && mv ogAdmClient ../../../client/nfsexport/bin |
---|
701 | popd |
---|
702 | } |
---|
703 | |
---|
704 | |
---|
705 | #################################################################### |
---|
706 | ### Funciones instalacion cliente opengnsys |
---|
707 | #################################################################### |
---|
708 | |
---|
709 | function openGnsysClientCreate () |
---|
710 | { |
---|
711 | local OSDISTRIB OSCODENAME |
---|
712 | |
---|
713 | echoAndLog "openGnsysClientCreate(): Copying OpenGNSys Client files." |
---|
714 | cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client |
---|
715 | find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
716 | echoAndLog "openGnsysClientCreate(): Copying OpenGNSys Cloning Engine files." |
---|
717 | mkdir -p $INSTALL_TARGET/client/lib/engine/bin |
---|
718 | cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin |
---|
719 | cp -ar $WORKDIR/opengnsys/client/engine/*.sh $INSTALL_TARGET/client/lib/engine/bin |
---|
720 | |
---|
721 | # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto). |
---|
722 | OSDISRIB=$(lsb_release -i | awk -F: '{print $2}') 2>/dev/null |
---|
723 | OSCODENAME=$(lsb_release -c | awk -F: '{print $2}') 2>/dev/null |
---|
724 | if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then |
---|
725 | echoAndLog "openGnsysClientCreate(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME." |
---|
726 | $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME" |
---|
727 | echoAndLog "openGnsysClientCreate(): Loading udeb files for $OSDISTRIB $OSCODENAME." |
---|
728 | $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME" |
---|
729 | else |
---|
730 | echoAndLog "openGnsysClientCreate(): Loading default Kernel and Initrd files." |
---|
731 | $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/ |
---|
732 | |
---|
733 | echoAndLog "openGnsysClientCreate(): Loading default udeb files." |
---|
734 | $INSTALL_TARGET/bin/upgrade-clients-udeb.sh |
---|
735 | fi |
---|
736 | } |
---|
737 | |
---|
738 | |
---|
739 | # Configuración básica de servicios de OpenGNSys |
---|
740 | function openGnsysConfigure() |
---|
741 | { |
---|
742 | echoAndLog "openGnsysConfigure(): Copying init files." |
---|
743 | cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys |
---|
744 | cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.default /etc/default/opengnsys |
---|
745 | update-rc.d opengnsys defaults |
---|
746 | echoAndLog "openGnsysConfigure(): Creating OpenGNSys config file in \"$INSTALL_TARGET/etc\"." |
---|
747 | perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmServer.cfg |
---|
748 | perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg |
---|
749 | sed -e "s/SERVERIP/$SERVERIP/g" $WORKDIR/opengnsys/admin/Services/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg |
---|
750 | echoAndLog "openGnsysConfigure(): Creating Web Console config file" |
---|
751 | perl -pi -e "s/SERVERIP/$SERVERIP/g" \ |
---|
752 | -e "s/OPENGNSYSURL/http:\/\/$SERVERIP\/opengnsys/g" \ |
---|
753 | $INSTALL_TARGET/www/controlacceso.php |
---|
754 | echoAndLog "openGnsysConfiguration(): Starting OpenGNSys services." |
---|
755 | /etc/init.d/opengnsys start |
---|
756 | } |
---|
757 | |
---|
758 | |
---|
759 | ##################################################################### |
---|
760 | ####### Proceso de instalación de OpenGNSys |
---|
761 | ##################################################################### |
---|
762 | |
---|
763 | |
---|
764 | echoAndLog "OpenGNSys installation begins at $(date)" |
---|
765 | |
---|
766 | # Detectar parámetros de red por defecto |
---|
767 | getNetworkSettings |
---|
768 | if [ $? -ne 0 ]; then |
---|
769 | errorAndLog "Error reading default network settings." |
---|
770 | exit 1 |
---|
771 | fi |
---|
772 | |
---|
773 | # Actualizar repositorios |
---|
774 | apt-get update |
---|
775 | |
---|
776 | # Instalación de dependencias (paquetes de sistema operativo). |
---|
777 | declare -a notinstalled |
---|
778 | checkDependencies DEPENDENCIES notinstalled |
---|
779 | if [ $? -ne 0 ]; then |
---|
780 | installDependencies notinstalled |
---|
781 | if [ $? -ne 0 ]; then |
---|
782 | echoAndLog "Error while installing some dependeces, please verify your server installation before continue" |
---|
783 | exit 1 |
---|
784 | fi |
---|
785 | fi |
---|
786 | |
---|
787 | # Arbol de directorios de OpenGNSys. |
---|
788 | openGnsysInstallCreateDirs ${INSTALL_TARGET} |
---|
789 | if [ $? -ne 0 ]; then |
---|
790 | errorAndLog "Error while creating directory paths!" |
---|
791 | exit 1 |
---|
792 | fi |
---|
793 | |
---|
794 | # Descarga del repositorio de código en directorio temporal |
---|
795 | svnCheckoutCode $SVN_URL |
---|
796 | if [ $? -ne 0 ]; then |
---|
797 | errorAndLog "Error while getting code from svn" |
---|
798 | exit 1 |
---|
799 | fi |
---|
800 | |
---|
801 | # Compilar código fuente de los servicios de OpenGNSys. |
---|
802 | servicesCompilation |
---|
803 | |
---|
804 | # Configurando tftp |
---|
805 | tftpConfigure |
---|
806 | |
---|
807 | # Configuración NFS |
---|
808 | nfsConfigure |
---|
809 | |
---|
810 | # Configuración ejemplo DHCP |
---|
811 | dhcpConfigure |
---|
812 | |
---|
813 | # Copiar ficheros de servicios OpenGNSys Server. |
---|
814 | openGnsysCopyServerFiles ${INSTALL_TARGET} |
---|
815 | if [ $? -ne 0 ]; then |
---|
816 | errorAndLog "Error while copying the server files!" |
---|
817 | exit 1 |
---|
818 | fi |
---|
819 | |
---|
820 | # Instalar Base de datos de OpenGNSys Admin. |
---|
821 | isInArray notinstalled "mysql-server" |
---|
822 | if [ $? -eq 0 ]; then |
---|
823 | mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD} |
---|
824 | else |
---|
825 | mysqlGetRootPassword |
---|
826 | |
---|
827 | fi |
---|
828 | |
---|
829 | mysqlTestConnection ${MYSQL_ROOT_PASSWORD} |
---|
830 | if [ $? -ne 0 ]; then |
---|
831 | errorAndLog "Error while connection to mysql" |
---|
832 | exit 1 |
---|
833 | fi |
---|
834 | mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
835 | if [ $? -ne 0 ]; then |
---|
836 | echoAndLog "Creating Web Console database" |
---|
837 | mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
838 | if [ $? -ne 0 ]; then |
---|
839 | errorAndLog "Error while creating Web Console database" |
---|
840 | exit 1 |
---|
841 | fi |
---|
842 | else |
---|
843 | echoAndLog "Web Console database exists, ommiting creation" |
---|
844 | fi |
---|
845 | |
---|
846 | mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER} |
---|
847 | if [ $? -ne 0 ]; then |
---|
848 | echoAndLog "Creating user in database" |
---|
849 | mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}" |
---|
850 | if [ $? -ne 0 ]; then |
---|
851 | errorAndLog "Error while creating database user" |
---|
852 | exit 1 |
---|
853 | fi |
---|
854 | |
---|
855 | fi |
---|
856 | |
---|
857 | mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
858 | if [ $? -eq 0 ]; then |
---|
859 | echoAndLog "Creating tables..." |
---|
860 | if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then |
---|
861 | mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE |
---|
862 | else |
---|
863 | errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!" |
---|
864 | exit 1 |
---|
865 | fi |
---|
866 | fi |
---|
867 | |
---|
868 | # copiando paqinas web |
---|
869 | installWebFiles |
---|
870 | |
---|
871 | # creando configuracion de apache2 |
---|
872 | openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2 |
---|
873 | if [ $? -ne 0 ]; then |
---|
874 | errorAndLog "Error configuring Apache for OpenGNSYS Admin" |
---|
875 | exit 1 |
---|
876 | fi |
---|
877 | |
---|
878 | popd |
---|
879 | |
---|
880 | # Creando la estructura del cliente |
---|
881 | openGnsysClientCreate |
---|
882 | |
---|
883 | # Configuración de servicios de OpenGNSys |
---|
884 | openGnsysConfigure |
---|
885 | |
---|
886 | rm -rf $WORKDIR |
---|
887 | echoAndLog "OpenGNSys installation finished at $(date)" |
---|
888 | |
---|