source: installer/opengnsys_installer.sh @ fa2ba4f2

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since fa2ba4f2 was 0795938, checked in by adv <adv@…>, 16 years ago

se incluye paquetes a instalar: doxygen y graphviz para la generación de documentacion

git-svn-id: https://opengnsys.es/svn/trunk@569 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 32.7 KB
Line 
1#!/bin/bash
2
3#####################################################################
4####### Script instalador OpenGnsys
5####### autor: Luis Guillén <lguillen@unizar.es>
6#####################################################################
7
8
9WORKDIR=/tmp/opengnsys_installer
10LOG_FILE=/tmp/opengnsys_installation.log
11
12# Array con las dependencias
13DEPENDENCIES=( subversion apache2 php5 mysql-server php5-mysql nfs-kernel-server dhcp3-server udpcast bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential libmysqlclient15-dev wget doxygen graphviz)
14
15INSTALL_TARGET=/opt/opengnsys
16
17MYSQL_ROOT_PASSWORD="passwordroot"
18
19# conexión al svn
20SVN_URL=svn://www.informatica.us.es:3690/opengnsys/trunk
21
22# Datos de base de datos
23OPENGNSYS_DATABASE=ogBDAdmin
24OPENGNSYS_DB_USER=usuog
25OPENGNSYS_DB_PASSWD=passusuog
26OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogBDAdmin.sql
27
28USUARIO=`whoami`
29
30if [ $USUARIO != 'root' ]
31then
32        echo "ERROR: this program must run under root privileges!!"
33        exit 1
34fi
35
36
37mkdir -p $WORKDIR
38pushd $WORKDIR
39
40#####################################################################
41####### Algunas funciones útiles de propósito general:
42#####################################################################
43function getDateTime()
44{
45        echo `date +%Y%m%d-%H%M%S`
46}
47
48# Escribe a fichero y muestra por pantalla
49function echoAndLog()
50{
51        echo $1
52        FECHAHORA=`getDateTime`
53        echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE
54}
55
56function 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
64function isInArray()
65{
66        if [ $# -ne 2 ]; then
67                errorAndLog "${FUNCNAME}(): invalid number of parameters"
68                exit 1
69        fi
70
71        echoAndLog "${FUNCNAME}(): 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 "${FUNCNAME}(): $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
98function 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
119function 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
156function 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# Hace un backup del fichero pasado por parámetro
194# deja un -last y uno para el día
195function backupFile()
196{
197        if [ $# -ne 1 ]; then
198                errorAndLog "${FUNCNAME}(): invalid number of parameters"
199                exit 1
200        fi
201
202        local fichero=$1
203        local fecha=`date +%Y%m%d`
204
205        if [ ! -f $fichero ]; then
206                errorAndLog "${FUNCNAME}(): file $fichero doesn't exists"
207                return 1
208        fi
209
210        echoAndLog "${FUNCNAME}(): realizando backup de $fichero"
211
212        # realiza una copia de la última configuración como last
213        cp -p $fichero "${fichero}-LAST"
214
215        # si para el día no hay backup lo hace, sino no
216        if [ ! -f "${fichero}-${fecha}" ]; then
217                cp -p $fichero "${fichero}-${fecha}"
218        fi
219
220        echoAndLog "${FUNCNAME}(): backup realizado"
221}
222
223#####################################################################
224####### Funciones para el manejo de bases de datos
225#####################################################################
226
227# This function set password to root
228function mysqlSetRootPassword()
229{
230        if [ $# -ne 1 ]; then
231                errorAndLog "mysqlSetRootPassword(): invalid number of parameters"
232                exit 1
233        fi
234
235        local root_mysql=$1
236        echoAndLog "mysqlSetRootPassword(): setting root password in MySQL server"
237        /usr/bin/mysqladmin -u root password ${root_mysql}
238        if [ $? -ne 0 ]; then
239                errorAndLog "mysqlSetRootPassword(): error while setting root password in MySQL server"
240                return 1
241        fi
242        echoAndLog "mysqlSetRootPassword(): root password saved!"
243        return 0
244}
245
246# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
247function mysqlGetRootPassword(){
248        local pass_mysql
249        local pass_mysql2
250        stty -echo
251        echo "Existe un servicio mysql ya instalado"
252        read -p  "Insertar clave de root de Mysql: " pass_mysql
253        echo ""
254        read -p "Confirmar clave:" pass_mysql2
255        echo ""
256        stty echo
257        if [ "$pass_mysql" == "$pass_mysql2" ] ;then
258                MYSQL_ROOT_PASSWORD=$pass_mysql
259                echo "La clave es: ${MYSQL_ROOT_PASSWORD}"
260                return 0
261        else
262                echo "Las claves no coinciden no se configura la clave del servidor de base de datos."
263                echo "las operaciones con la base de datos daran error"
264                return 1
265        fi
266
267
268}
269
270# comprueba si puede conectar con mysql con el usuario root
271function mysqlTestConnection()
272{
273        if [ $# -ne 1 ]; then
274                errorAndLog "mysqlTestConnection(): invalid number of parameters"
275                exit 1
276        fi
277
278        local root_password="${1}"
279        echoAndLog "mysqlTestConnection(): checking connection to mysql..."
280        echo "" | mysql -uroot -p"${root_password}"
281        if [ $? -ne 0 ]; then
282                errorAndLog "mysqlTestConnection(): connection to mysql failed, check root password and if daemon is running!"
283                return 1
284        else
285                echoAndLog "mysqlTestConnection(): connection success"
286                return 0
287        fi
288}
289
290# comprueba si la base de datos existe
291function mysqlDbExists()
292{
293        if [ $# -ne 2 ]; then
294                errorAndLog "mysqlDbExists(): invalid number of parameters"
295                exit 1
296        fi
297
298        local root_password="${1}"
299        local database=$2
300        echoAndLog "mysqlDbExists(): checking if $database exists..."
301        echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$"
302        if [ $? -ne 0 ]; then
303                echoAndLog "mysqlDbExists():database $database doesn't exists"
304                return 1
305        else
306                echoAndLog "mysqlDbExists():database $database exists"
307                return 0
308        fi
309}
310
311function mysqlCheckDbIsEmpty()
312{
313        if [ $# -ne 2 ]; then
314                errorAndLog "mysqlCheckDbIsEmpty(): invalid number of parameters"
315                exit 1
316        fi
317
318        local root_password="${1}"
319        local database=$2
320        echoAndLog "mysqlCheckDbIsEmpty(): checking if $database is empty..."
321        num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l`
322        if [ $? -ne 0 ]; then
323                errorAndLog "mysqlCheckDbIsEmpty(): error executing query, check database and root password"
324                exit 1
325        fi
326
327        if [ $num_tablas -eq 0 ]; then
328                echoAndLog "mysqlCheckDbIsEmpty():database $database is empty"
329                return 0
330        else
331                echoAndLog "mysqlCheckDbIsEmpty():database $database has tables"
332                return 1
333        fi
334
335}
336
337
338function mysqlImportSqlFileToDb()
339{
340        if [ $# -ne 3 ]; then
341                errorAndLog "mysqlImportSqlFileToDb(): invalid number of parameters"
342                exit 1
343        fi
344
345        local root_password="${1}"
346        local database=$2
347        local sqlfile=$3
348
349        if [ ! -f $sqlfile ]; then
350                errorAndLog "mysqlImportSqlFileToDb(): Unable to locate $sqlfile!!"
351                return 1
352        fi
353
354        echoAndLog "mysqlImportSqlFileToDb(): importing sql file to ${database}..."
355        mysql -uroot -p"${root_password}" "${database}" < $sqlfile
356        if [ $? -ne 0 ]; then
357                errorAndLog "mysqlImportSqlFileToDb(): error while importing $sqlfile in database $database"
358                return 1
359        fi
360        echoAndLog "mysqlImportSqlFileToDb(): file imported to database $database"
361        return 0
362}
363
364# Crea la base de datos
365function mysqlCreateDb()
366{
367        if [ $# -ne 2 ]; then
368                errorAndLog "${FUNCNAME}(): invalid number of parameters"
369                exit 1
370        fi
371
372        local root_password="${1}"
373        local database=$2
374
375        echoAndLog "${FUNCNAME}(): creating database..."
376        mysqladmin -u root --password="${root_password}" create $database
377        if [ $? -ne 0 ]; then
378                errorAndLog "${FUNCNAME}(): error while creating database $database"
379                return 1
380        fi
381        echoAndLog "${FUNCNAME}(): database $database created"
382        return 0
383}
384
385
386function mysqlCheckUserExists()
387{
388        if [ $# -ne 2 ]; then
389                errorAndLog "mysqlCheckUserExists(): invalid number of parameters"
390                exit 1
391        fi
392
393        local root_password="${1}"
394        local userdb=$2
395
396        echoAndLog "mysqlCheckUserExists(): checking if $userdb exists..."
397        echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user
398        if [ $? -ne 0 ]; then
399                echoAndLog "mysqlCheckUserExists(): user doesn't exists"
400                return 1
401        else
402                echoAndLog "mysqlCheckUserExists(): user already exists"
403                return 0
404        fi
405
406}
407
408# Crea un usuario administrativo para la base de datos
409function mysqlCreateAdminUserToDb()
410{
411        if [ $# -ne 4 ]; then
412                errorAndLog "mysqlCreateAdminUserToDb(): invalid number of parameters"
413                exit 1
414        fi
415
416        local root_password=$1
417        local database=$2
418        local userdb=$3
419        local passdb=$4
420
421        echoAndLog "mysqlCreateAdminUserToDb(): creating admin user ${userdb} to database ${database}"
422
423        cat > $WORKDIR/create_${database}.sql <<EOF
424GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
425GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
426FLUSH PRIVILEGES ;
427EOF
428        mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql
429        if [ $? -ne 0 ]; then
430                errorAndLog "mysqlCreateAdminUserToDb(): error while creating user in mysql"
431                rm -f $WORKDIR/create_${database}.sql
432                return 1
433        else
434                echoAndLog "mysqlCreateAdminUserToDb(): user created ok"
435                rm -f $WORKDIR/create_${database}.sql
436                return 0
437        fi
438}
439
440
441#####################################################################
442####### Funciones para el manejo de Subversion
443#####################################################################
444
445function svnCheckoutCode()
446{
447        if [ $# -ne 1 ]; then
448                errorAndLog "${FUNCNAME}(): invalid number of parameters"
449                exit 1
450        fi
451
452        local url=$1
453
454        echoAndLog "${FUNCNAME}(): downloading subversion code..."
455
456        /usr/bin/svn co "${url}" opengnsys
457        if [ $? -ne 0 ]; then
458                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
459                return 1
460        fi
461        echoAndLog "${FUNCNAME}(): subversion code downloaded"
462        return 0
463}
464
465
466function svnExportCode()
467{
468        if [ $# -ne 1 ]; then
469                errorAndLog "${FUNCNAME}(): invalid number of parameters"
470                exit 1
471        fi
472
473        local url=$1
474
475        echoAndLog "${FUNCNAME}(): downloading subversion code..."
476
477        /usr/bin/svn export "${url}" opengnsys
478        if [ $? -ne 0 ]; then
479                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
480                return 1
481        fi
482        echoAndLog "${FUNCNAME}(): subversion code downloaded"
483        return 0
484}
485
486
487############################################################
488###  Detectar red
489############################################################
490
491function getNetworkSettings()
492{
493        # Variables globales definidas:
494        # - SERVERIP: IP local del servidor.
495        # - NETIP:    IP de la red.
496        # - NETMASK:  máscara de red.
497        # - NETBROAD: IP de difusión de la red.
498        # - ROUTERIP: IP del router.
499        # - DNSIP:    IP del servidor DNS.
500
501        echoAndLog "getNetworkSettings(): Detecting default network parameters."
502        SERVERIP=$(LANG=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | head -n1 | awk '{print $1}')
503        NETMASK=$(LANG=C ifconfig | grep 'Mask:'| grep -v '127.0.0.1' | cut -d: -f4 | head -n1 | awk '{print $1}')
504        NETBROAD=$(LANG=C ifconfig | grep 'Bcast:'| grep -v '127.0.0.1' | cut -d: -f3 | head -n1 | awk '{print $1}')
505        NETIP=$(netstat -r | grep $NETMASK | head -n1 | awk '{print $1}')
506        ROUTERIP=$(netstat -nr | awk '$1~/0\.0\.0\.0/ {print $2}')
507        DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1)
508        if [ -z "$NETIP" -o -z "$NETMASK" ]; then
509                errorAndLog "getNetworkSettings(): Network not detected."
510                exit 1
511        fi
512
513        # Variables de ejecución de Apache
514        # - APACHE_RUN_USER
515        # - APACHE_RUN_GROUP
516        if [ -f /etc/apache2/envvars ]; then
517                source /etc/apache2/envvars
518        fi
519        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
520        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
521}
522
523
524############################################################
525### Esqueleto para el Servicio pxe y contenedor tftpboot ###
526############################################################
527
528function tftpConfigure() {
529        echo "Configurando el servicio tftp"
530        basetftp=/var/lib/tftpboot
531
532        # reiniciamos demonio internet ????? porque ????
533        /etc/init.d/openbsd-inetd start
534
535        # preparacion contenedor tftpboot
536        cp -pr /usr/lib/syslinux/ ${basetftp}/syslinux
537        cp /usr/lib/syslinux/pxelinux.0 ${basetftp}
538        # prepamos el directorio de la configuracion de pxe
539        mkdir -p ${basetftp}/pxelinux.cfg
540        cat > ${basetftp}/pxelinux.cfg/default <<EOF
541DEFAULT pxe
542
543LABEL pxe
544KERNEL linux
545APPEND initrd=initrd.gz ip=dhcp ro vga=788 irqpoll acpi=on
546EOF
547        # comprobamos el servicio tftp
548        sleep 1
549        testPxe
550        ## damos perfimos de lectura a usuario web.
551        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP ${basetftp}
552}
553
554function testPxe () {
555        cd /tmp
556        echo "comprobando servicio pxe ..... Espere"
557        tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echo "servidor tftp OK" || echo "servidor tftp KO"
558        cd /
559}
560
561########################################################################
562## Configuracion servicio NFS
563########################################################################
564
565# function nfsConfigure ()
566# {
567#         echoAndLog "${FUNCNAME}(): Sample NFS Configuration."
568#         sed -e "s/NETIP/$NETIP/g" -e "s/NETMASK/$NETMASK/g" $WORKDIR/opengnsys/server/NFS/exports  >> /etc/exports
569#       /etc/init.d/nfs-kernel-server restart
570#       exportfs -va
571#         echoAndLog "${FUNCNAME}(): Sample NFS Configured in file \"/etc/exports\"."
572# }
573
574# ADVERTENCIA: usa variables globales NETIP y NETMASK!
575function nfsConfigure()
576{
577        echoAndLog "${FUNCNAME}(): Config nfs server."
578
579        backupFile /etc/exports
580
581        nfsAddExport /opt/opengnsys/client ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync
582        if [ $? -ne 0 ]; then
583                errorAndLog "${FUNCNAME}(): error while adding nfs client config"
584                return 1
585        fi
586
587        nfsAddExport /opt/opengnsys/images ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync,crossmnt
588        if [ $? -ne 0 ]; then
589                errorAndLog "${FUNCNAME}(): error while adding nfs images config"
590                return 1
591        fi
592
593        nfsAddExport /opt/opengnsys/log/clients ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync
594        if [ $? -ne 0 ]; then
595                errorAndLog "${FUNCNAME}(): error while adding logging client config"
596                return 1
597        fi
598
599        /etc/init.d/nfs-kernel-server restart
600
601        exportfs -va
602        if [ $? -ne 0 ]; then
603                errorAndLog "${FUNCNAME}(): error while configure exports"
604                return 1
605        fi
606
607        echoAndLog "${FUNCNAME}(): Added NFS configuration to file \"/etc/exports\"."
608        return 0
609}
610
611
612# ejemplos:
613#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0:ro,no_subtree_check,no_root_squash,sync
614#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0
615#nfsAddExport /opt/opengnsys 80.20.2.1:ro 192.123.32.2:rw
616function nfsAddExport()
617{
618        if [ $# -lt 2 ]; then
619                errorAndLog "${FUNCNAME}(): invalid number of parameters"
620                exit 1
621        fi
622
623        if [ ! -f /etc/exports ]; then
624                errorAndLog "${FUNCNAME}(): /etc/exports don't exists"
625                return 1
626        fi
627
628        local export="${1}"
629        local contador=0
630        local cadenaexport
631
632        grep "^${export}" /etc/exports > /dev/null
633        if [ $? -eq 0 ]; then
634                echoAndLog "${FUNCNAME}(): $export exists in /etc/exports, omiting"
635                return 0
636        fi
637
638        cadenaexport="${export}"
639        for parametro in $*
640        do
641                if [ $contador -gt 0 ]
642                then
643                        host=`echo $parametro | awk -F: '{print $1}'`
644                        options=`echo $parametro | awk -F: '{print $2}'`
645                        if [ "${host}" == "" ]; then
646                                errorAndLog "${FUNCNAME}(): host can't be empty"
647                                return 1
648                        fi
649                        cadenaexport="${cadenaexport}\t${host}"
650
651                        if [ "${options}" != "" ]; then
652                                cadenaexport="${cadenaexport}(${options})"
653                        fi
654                fi
655                let contador=contador+1
656        done
657
658        echo -en "$cadenaexport\n" >> /etc/exports
659
660        echoAndLog "${FUNCNAME}(): add $export to /etc/exports"
661
662        return 0
663}
664
665########################################################################
666## Configuracion servicio DHCP
667########################################################################
668
669function dhcpConfigure()
670{
671        echoAndLog "${FUNCNAME}(): Sample DHCP Configuration."
672
673        backupFile /etc/dhcp3/dhcpd.conf
674
675        sed -e "s/SERVERIP/$SERVERIP/g" \
676            -e "s/NETIP/$NETIP/g" \
677            -e "s/NETMASK/$NETMASK/g" \
678            -e "s/NETBROAD/$NETBROAD/g" \
679            -e "s/ROUTERIP/$ROUTERIP/g" \
680            -e "s/DNSIP/$DNSIP/g" \
681            $WORKDIR/opengnsys/server/DHCP/dhcpd.conf > /etc/dhcp3/dhcpd.conf
682        if [ $? -ne 0 ]; then
683                errorAndLog "${FUNCNAME}(): error while configuring dhcp server"
684                return 1
685        fi
686
687        /etc/init.d/dhcp3-server restart
688        echoAndLog "${FUNCNAME}(): Sample DHCP Configured in file \"/etc/dhcp3/dhcpd.conf\"."
689        return 0
690}
691
692
693#####################################################################
694####### Funciones específicas de la instalación de Opengnsys
695#####################################################################
696
697# Copiar ficheros del OpenGNSys Web Console.
698function installWebFiles()
699{
700        echoAndLog "installWebFiles(): Installing web files..."
701        cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www   #*/ comentario para doxigen
702        if [ $? != 0 ]; then
703                errorAndLog "installWebFiles(): Error copying web files."
704                exit 1
705        fi
706        find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null
707        # Cambiar permisos para ficheros especiales.
708        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP \
709                        $INSTALL_TARGET/www/includes \
710                        $INSTALL_TARGET/www/comandos/gestores/filescripts \
711                        $INSTALL_TARGET/www/images/icons
712        echoAndLog "installWebFiles(): Web files installed successfully."
713}
714
715# Configuración específica de Apache.
716function openGnsysInstallWebConsoleApacheConf()
717{
718        if [ $# -ne 2 ]; then
719                errorAndLog "openGnsysInstallWebConsoleApacheConf(): invalid number of parameters"
720                exit 1
721        fi
722
723        local path_opengnsys_base=$1
724        local path_apache2_confd=$2
725        local path_web_console=${path_opengnsys_base}/www
726
727        if [ ! -d $path_apache2_confd ]; then
728                errorAndLog "openGnsysInstallWebConsoleApacheConf(): path to apache2 conf.d can not found, verify your server installation"
729                return 1
730        fi
731
732        mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
733
734        echoAndLog "openGnsysInstallWebConsoleApacheConf(): creating apache2 config file.."
735
736        # genera configuración
737        cat > $path_opengnsys_base/etc/apache.conf <<EOF
738# OpenGNSys Web Console configuration for Apache
739
740Alias /opengnsys ${path_web_console}
741
742<Directory ${path_web_console}>
743        Options -Indexes FollowSymLinks
744        DirectoryIndex acceso.php
745</Directory>
746EOF
747
748        ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys.conf
749        ln -fs $path_apache2_confd/sites-available/opengnsys.conf $path_apache2_confd/sites-enabled/opengnsys.conf
750        if [ $? -ne 0 ]; then
751                errorAndLog "openGnsysInstallWebConsoleApacheConf(): config file can't be linked to apache conf, verify your server installation"
752                return 1
753        else
754                echoAndLog "openGnsysInstallWebConsoleApacheConf(): config file created and linked, restarting apache daemon"
755                /etc/init.d/apache2 restart
756                return 0
757        fi
758}
759
760# Crea la estructura base de la instalación de opengnsys
761function openGnsysInstallCreateDirs()
762{
763        if [ $# -ne 1 ]; then
764                errorAndLog "openGnsysInstallCreateDirs(): invalid number of parameters"
765                exit 1
766        fi
767
768        local path_opengnsys_base=$1
769
770        echoAndLog "openGnsysInstallCreateDirs(): creating directory paths in $path_opengnsys_base"
771
772        mkdir -p $path_opengnsys_base
773        mkdir -p $path_opengnsys_base/admin/{autoexec,comandos,menus,usuarios}
774        mkdir -p $path_opengnsys_base/bin
775        mkdir -p $path_opengnsys_base/client
776        mkdir -p $path_opengnsys_base/etc
777        mkdir -p $path_opengnsys_base/lib
778        mkdir -p $path_opengnsys_base/log/clients
779        mkdir -p $path_opengnsys_base/sbin
780        mkdir -p $path_opengnsys_base/www
781        mkdir -p $path_opengnsys_base/images
782        ln -fs /var/lib/tftpboot $path_opengnsys_base
783        ln -fs $path_opengnsys_base/log /var/log/opengnsys
784
785        if [ $? -ne 0 ]; then
786                errorAndLog "openGnsysInstallCreateDirs(): error while creating dirs. Do you have write permissions?"
787                return 1
788        fi
789
790        echoAndLog "openGnsysInstallCreateDirs(): directory paths created"
791        return 0
792}
793
794# Copia ficheros de configuración y ejecutables genéricos del servidor.
795function openGnsysCopyServerFiles () {
796        if [ $# -ne 1 ]; then
797                errorAndLog "${FUNCNAME}(): invalid number of parameters"
798                exit 1
799        fi
800
801        local path_opengnsys_base=$1
802
803        local SOURCES=( client/boot/initrd-generator \
804                        client/boot/upgrade-clients-udeb.sh \
805                        client/boot/udeblist.conf  \
806                        client/boot/udeblist-jaunty.conf  \
807                        client/boot/udeblist-karmic.conf \
808                        server/PXE/pxelinux.cfg/default )
809        local TARGETS=( bin/initrd-generator \
810                        bin/upgrade-clients-udeb.sh \
811                        etc/udeblist.conf \
812                        etc/udeblist-jaunty.conf  \
813                        etc/udeblist-karmic.conf \
814                        tftpboot/pxelinux.cfg/default )
815
816        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
817                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
818                exit 1
819        fi
820
821        echoAndLog "${FUNCNAME}(): copying files to server directories"
822
823        pushd $WORKDIR/opengnsys
824        local i
825        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
826                if [ -f "${SOURCES[$i]}" ]; then
827                        echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
828                        cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
829                fi
830                if [ -d "${SOURCES[$i]}" ]; then
831                        echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
832                        cp -ar "${SOURCES[$i]}/*" "${path_opengnsys_base}/${TARGETS[$i]}"
833                fi
834        done
835        popd
836}
837
838####################################################################
839### Funciones de compilación de códifo fuente de servicios
840####################################################################
841
842# Compilar los servicios de OpenGNsys
843function servicesCompilation ()
844{
845        local hayErrores=0
846
847        # Compilar OpenGNSys Server
848        echoAndLog "${FUNCNAME}(): Compiling OpenGNSys Admin Server"
849        pushd $WORKDIR/opengnsys/admin/Services/ogAdmServer
850        make && make install
851        if [ $? -ne 0 ]; then
852                echoAndLog "${FUNCNAME}(): error while compiling OpenGNSys Admin Server"
853                hayErrores=1
854        fi
855        popd
856        # Compilar OpenGNSys Repository Manager
857        echoAndLog "${FUNCNAME}(): Compiling OpenGNSys Repository Manager"
858        pushd $WORKDIR/opengnsys/admin/Services/ogAdmRepo
859        make && make install
860        if [ $? -ne 0 ]; then
861                echoAndLog "${FUNCNAME}(): error while compiling OpenGNSys Repository Manager"
862                hayErrores=1
863        fi
864        popd
865        # Compilar OpenGNSys Client
866        echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Client"
867        pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
868        make && mv ogAdmClient ../../../client/nfsexport/bin
869        if [ $? -ne 0 ]; then
870                echoAndLog "${FUNCNAME}(): error while compiling OpenGNSys Admin Client"
871                hayErrores=1
872        fi
873        popd
874
875        return $hayErrores
876}
877
878
879####################################################################
880### Funciones instalacion cliente opengnsys
881####################################################################
882
883function openGnsysClientCreate()
884{
885        local OSDISTRIB OSCODENAME
886
887        local hayErrores=0
888
889        echoAndLog "${FUNCNAME}(): Copying OpenGNSys Client files."
890        cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
891        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
892        chmod +x $INSTALL_TARGET/client/admin/scripts/*
893        echoAndLog "${FUNCNAME}(): Copying OpenGNSys Cloning Engine files."
894        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
895        cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
896        if [ $? -ne 0 ]; then
897                errorAndLog "${FUNCNAME}(): error while copying engine files"
898                hayErrores=1
899        fi
900
901        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
902        OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
903        OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
904        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
905                echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
906                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
907                if [ $? -ne 0 ]; then
908                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGNSys Admin Client"
909                        hayErrores=1
910                fi
911                echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
912                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
913                if [ $? -ne 0 ]; then
914                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGNSys Admin Client"
915                        hayErrores=1
916                fi
917        else
918                echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
919                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
920                if [ $? -ne 0 ]; then
921                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGNSys Admin Client"
922                        hayErrores=1
923                fi
924                echoAndLog "${FUNCNAME}(): Loading default udeb files."
925                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh
926                if [ $? -ne 0 ]; then
927                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGNSys Admin Client"
928                        hayErrores=1
929                fi
930        fi
931
932        if [ $hayErrores -eq 0 ]; then
933                echoAndLog "${FUNCNAME}(): Client generation success."
934        else
935                errorAndLog "${FUNCNAME}(): Client generation with errors"
936        fi
937
938        return $hayErrores
939}
940
941
942# Configuración básica de servicios de OpenGNSys
943function openGnsysConfigure()
944{
945        echoAndLog "openGnsysConfigure(): Copying init files."
946        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
947        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.default /etc/default/opengnsys
948        update-rc.d opengnsys defaults
949        echoAndLog "openGnsysConfigure(): Creating OpenGNSys config file in \"$INSTALL_TARGET/etc\"."
950        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmServer.cfg
951        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg
952        sed -e "s/SERVERIP/$SERVERIP/g" $WORKDIR/opengnsys/admin/Services/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg
953        echoAndLog "openGnsysConfigure(): Creating Web Console config file"
954        perl -pi -e "s/SERVERIP/$SERVERIP/g; s/OPENGNSYSURL/http:\/\/$SERVERIP\/opengnsys/g" $INSTALL_TARGET/www/controlacceso.php
955        OPENGNSYS_CONSOLEURL=$(awk -F\" '$1~/\$wac/ {print $2}' $INSTALL_TARGET/www/controlacceso.php)
956        echoAndLog "openGnsysConfiguration(): Starting OpenGNSys services."
957        /etc/init.d/opengnsys start
958}
959
960
961#####################################################################
962#######  Función de resumen informativo de la instalación
963#####################################################################
964
965function installationSummary(){
966        echo
967        echoAndLog "OpenGNSys Installation Summary"
968        echo       "=============================="
969        echoAndLog "OpenGNSys installation directory: $INSTALL_TARGET"
970        echoAndLog "OpenGNSys repository directory:   $INSTALL_TARGET/images"
971        echoAndLog "TFTP configuracion directory:     /var/lib/tftpboot"
972        echoAndLog "DHCP configuracion file:          /etc/dhcp3/dhcpd.conf"
973        echoAndLog "NFS configuracion file:           /etc/exports"
974        echoAndLog "OpenGNSys Web Console URL:        $OPENGNSYS_CONSOLEURL"
975        echoAndLog "Web Console admin user:           $OPENGNSYS_DB_USER"
976        echoAndLog "Web Console admin password:       $OPENGNSYS_DB_PASSWD"
977        echo
978        echoAndLog "Post-Installation Instructions:"
979        echo       "==============================="
980        echoAndLog "Review or edit all configuration files."
981        echoAndLog "Log-in as Web Console admin user."
982        echoAndLog " - Insert Organization data and Organization user."
983        echoAndLog "Log-in as Web Console organization user."
984        echoAndLog " - Insert OpenGNSys Server configuration data."
985        echoAndLog "Restart OpenGNSys services."
986echo
987}
988
989
990
991#####################################################################
992####### Proceso de instalación de OpenGNSys
993#####################################################################
994
995
996echoAndLog "OpenGNSys installation begins at $(date)"
997
998# Detectar parámetros de red por defecto
999getNetworkSettings
1000if [ $? -ne 0 ]; then
1001        errorAndLog "Error reading default network settings."
1002        exit 1
1003fi
1004
1005# Actualizar repositorios
1006apt-get update
1007
1008# Instalación de dependencias (paquetes de sistema operativo).
1009declare -a notinstalled
1010checkDependencies DEPENDENCIES notinstalled
1011if [ $? -ne 0 ]; then
1012        installDependencies notinstalled
1013        if [ $? -ne 0 ]; then
1014                echoAndLog "Error while installing some dependeces, please verify your server installation before continue"
1015                exit 1
1016        fi
1017fi
1018
1019# Arbol de directorios de OpenGNSys.
1020openGnsysInstallCreateDirs ${INSTALL_TARGET}
1021if [ $? -ne 0 ]; then
1022        errorAndLog "Error while creating directory paths!"
1023        exit 1
1024fi
1025
1026# Descarga del repositorio de código en directorio temporal
1027#svnCheckoutCode $SVN_URL
1028svnExportCode $SVN_URL
1029if [ $? -ne 0 ]; then
1030        errorAndLog "Error while getting code from svn"
1031        exit 1
1032fi
1033
1034# Compilar código fuente de los servicios de OpenGNSys.
1035servicesCompilation
1036if [ $? -ne 0 ]; then
1037        errorAndLog "Error while compiling OpenGnsys services"
1038        exit 1
1039fi
1040
1041# Configurando tftp
1042tftpConfigure
1043
1044# Configuración NFS
1045nfsConfigure
1046if [ $? -ne 0 ]; then
1047        errorAndLog "Error while configuring nfs server!"
1048        exit 1
1049fi
1050
1051# Configuración ejemplo DHCP
1052dhcpConfigure
1053if [ $? -ne 0 ]; then
1054        errorAndLog "Error while copying your dhcp server files!"
1055        exit 1
1056fi
1057
1058# Copiar ficheros de servicios OpenGNSys Server.
1059openGnsysCopyServerFiles ${INSTALL_TARGET}
1060if [ $? -ne 0 ]; then
1061        errorAndLog "Error while copying the server files!"
1062        exit 1
1063fi
1064
1065# Instalar Base de datos de OpenGNSys Admin.
1066isInArray notinstalled "mysql-server"
1067if [ $? -eq 0 ]; then
1068        mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD}
1069else
1070        mysqlGetRootPassword
1071
1072fi
1073
1074mysqlTestConnection ${MYSQL_ROOT_PASSWORD}
1075if [ $? -ne 0 ]; then
1076        errorAndLog "Error while connection to mysql"
1077        exit 1
1078fi
1079mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1080if [ $? -ne 0 ]; then
1081        echoAndLog "Creating Web Console database"
1082        mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1083        if [ $? -ne 0 ]; then
1084                errorAndLog "Error while creating Web Console database"
1085                exit 1
1086        fi
1087else
1088        echoAndLog "Web Console database exists, ommiting creation"
1089fi
1090
1091mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER}
1092if [ $? -ne 0 ]; then
1093        echoAndLog "Creating user in database"
1094        mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
1095        if [ $? -ne 0 ]; then
1096                errorAndLog "Error while creating database user"
1097                exit 1
1098        fi
1099
1100fi
1101
1102mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1103if [ $? -eq 0 ]; then
1104        echoAndLog "Creating tables..."
1105        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
1106                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
1107        else
1108                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
1109                exit 1
1110        fi
1111fi
1112
1113# copiando paqinas web
1114installWebFiles
1115
1116# creando configuracion de apache2
1117openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2
1118if [ $? -ne 0 ]; then
1119        errorAndLog "Error configuring Apache for OpenGNSYS Admin"
1120        exit 1
1121fi
1122
1123popd
1124
1125# Creando la estructura del cliente
1126openGnsysClientCreate
1127if [ $? -ne 0 ]; then
1128        errorAndLog "Error creating clients"
1129        exit 1
1130fi
1131
1132# Configuración de servicios de OpenGNSys
1133openGnsysConfigure
1134
1135# Mostrar sumario de la instalación e instrucciones de post-instalación.
1136installationSummary
1137
1138#rm -rf $WORKDIR
1139echoAndLog "OpenGNSys installation finished at $(date)"
1140
Note: See TracBrowser for help on using the repository browser.