source: installer/opengnsys_installer.sh @ 5eae07e

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 5eae07e was 180a07dd, checked in by ramon <ramongomez@…>, 16 years ago

OpenGNSys Installer muestra información de instalación e instrucciones de post-instalación; scripts de ejemplo compatibles con Browser.

git-svn-id: https://opengnsys.es/svn/trunk@532 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 )
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 "openGnsysCopyServerFiles(): 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        local TARGETS=( bin/initrd-generator \
809                        bin/upgrade-clients-udeb.sh \
810                        etc/udeblist.conf \
811                        etc/udeblist-jaunty.conf  \
812                        etc/udeblist-karmic.conf )
813
814        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
815                errorAndLog "openGnsysCopyServerFiles(): inconsistent number of array items"
816                exit 1
817        fi
818
819        echoAndLog "openGnsysCopyServerFiles(): copying files to server directories"
820
821        pushd $WORKDIR/opengnsys
822        local i
823        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
824                if [ -f "${SOURCES[$i]}" ]; then
825                        echoAndLog "copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
826                        cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
827                fi
828                if [ -d "${SOURCES[$i]}" ]; then
829                        echoAndLog "openGnsysCopyServerFiles(): copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
830                        cp -ar "${SOURCES[$i]}/*" "${path_opengnsys_base}/${TARGETS[$i]}"
831                fi
832        done
833        popd
834}
835
836####################################################################
837### Funciones de compilación de códifo fuente de servicios
838####################################################################
839
840# Compilar los servicios de OpenGNsys
841function servicesCompilation ()
842{
843        local hayErrores=0
844       
845        # Compilar OpenGNSys Server
846        echoAndLog "${FUNCNAME}(): Compiling OpenGNSys Admin Server"
847        pushd $WORKDIR/opengnsys/admin/Services/ogAdmServer
848        make && make install
849        if [ $? -ne 0 ]; then
850                echoAndLog "${FUNCNAME}(): error while compiling OpenGNSys Admin Server"
851                hayErrores=1
852        fi
853        popd
854        # Compilar OpenGNSys Repository Manager
855        echoAndLog "${FUNCNAME}(): Compiling OpenGNSys Repository Manager"
856        pushd $WORKDIR/opengnsys/admin/Services/ogAdmRepo
857        make && make install
858        if [ $? -ne 0 ]; then
859                echoAndLog "${FUNCNAME}(): error while compiling OpenGNSys Repository Manager"
860                hayErrores=1
861        fi
862        popd
863        # Compilar OpenGNSys Client
864        echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Client"
865        pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
866        make && mv ogAdmClient ../../../client/nfsexport/bin
867        if [ $? -ne 0 ]; then
868                echoAndLog "${FUNCNAME}(): error while compiling OpenGNSys Admin Client"
869                hayErrores=1
870        fi
871        popd
872
873        return $hayErrores
874}
875
876
877####################################################################
878### Funciones instalacion cliente opengnsys
879####################################################################
880
881function openGnsysClientCreate()
882{
883        local OSDISTRIB OSCODENAME
884
885        local hayErrores=0
886
887        echoAndLog "${FUNCNAME}(): Copying OpenGNSys Client files."
888        cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
889        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
890        chmod +x $INSTALL_TARGET/client/admin/scripts/*
891        echoAndLog "${FUNCNAME}(): Copying OpenGNSys Cloning Engine files."
892        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
893        cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
894        if [ $? -ne 0 ]; then
895                errorAndLog "${FUNCNAME}(): error while copying engine files"
896                hayErrores=1
897        fi
898
899        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
900        OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
901        OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
902        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
903                echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
904                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
905                if [ $? -ne 0 ]; then
906                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGNSys Admin Client"
907                        hayErrores=1
908                fi
909                echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
910                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
911                if [ $? -ne 0 ]; then
912                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGNSys Admin Client"
913                        hayErrores=1
914                fi
915        else
916                echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
917                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
918                if [ $? -ne 0 ]; then
919                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGNSys Admin Client"
920                        hayErrores=1
921                fi
922                echoAndLog "${FUNCNAME}(): Loading default udeb files."
923                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh
924                if [ $? -ne 0 ]; then
925                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGNSys Admin Client"
926                        hayErrores=1
927                fi
928        fi
929
930        if [ $hayErrores -eq 0 ]; then
931                echoAndLog "${FUNCNAME}(): Client generation success."
932        else
933                errorAndLog "${FUNCNAME}(): Client generation with errors"
934        fi
935
936        return $hayErrores
937}
938
939
940# Configuración básica de servicios de OpenGNSys
941function openGnsysConfigure()
942{
943        echoAndLog "openGnsysConfigure(): Copying init files."
944        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
945        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.default /etc/default/opengnsys
946        update-rc.d opengnsys defaults
947        echoAndLog "openGnsysConfigure(): Creating OpenGNSys config file in \"$INSTALL_TARGET/etc\"."
948        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmServer.cfg
949        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg
950        sed -e "s/SERVERIP/$SERVERIP/g" $WORKDIR/opengnsys/admin/Services/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg
951        echoAndLog "openGnsysConfigure(): Creating Web Console config file"
952        perl -pi -e "s/SERVERIP/$SERVERIP/g; s/OPENGNSYSURL/http:\/\/$SERVERIP\/opengnsys/g" $INSTALL_TARGET/www/controlacceso.php
953        OPENGNSYS_CONSOLEURL=$(awk -F\" '$1~/\$wac/ {print $2}' $INSTALL_TARGET/www/controlacceso.php)
954        echoAndLog "openGnsysConfiguration(): Starting OpenGNSys services."
955        /etc/init.d/opengnsys start
956}
957
958
959#####################################################################
960#######  Función de resumen informativo de la instalación
961#####################################################################
962
963function installationSummary(){
964        echo
965        echoAndLog "OpenGNSys Installation Summary"
966        echo       "=============================="
967        echoAndLog "OpenGNSys installation directory: $INSTALL_TARGET"
968        echoAndLog "OpenGNSys repository directory:   $INSTALL_TARGET/images"
969        echoAndLog "TFTP configuracion directory:     /var/lib/tftpboot"
970        echoAndLog "DHCP configuracion file:          /etc/dhcp3/dhcpd.conf"
971        echoAndLog "NFS configuracion file:           /etc/exports"
972        echoAndLog "OpenGNSys Web Console URL:        $OPENGNSYS_CONSOLEURL"
973        echoAndLog "Web Console admin user:           $OPENGNSYS_DB_USER"
974        echoAndLog "Web Console admin password:       $OPENGNSYS_DB_PASSWD"
975        echo
976        echoAndLog "Post-Installation Instructions:"
977        echo       "==============================="
978        echoAndLog "Review or edit all configuration files."
979        echoAndLog "Log-in as Web Console admin user."
980        echoAndLog " - Insert Organization data and Organization user."
981        echoAndLog "Log-in as Web Console organization user."
982        echoAndLog " - Insert OpenGNSys Server configuration data."
983        echoAndLog "Restart OpenGNSys services."
984echo
985}
986
987
988
989#####################################################################
990####### Proceso de instalación de OpenGNSys
991#####################################################################
992
993
994echoAndLog "OpenGNSys installation begins at $(date)"
995
996# Detectar parámetros de red por defecto
997getNetworkSettings
998if [ $? -ne 0 ]; then
999        errorAndLog "Error reading default network settings."
1000        exit 1
1001fi
1002
1003# Actualizar repositorios
1004apt-get update
1005
1006# Instalación de dependencias (paquetes de sistema operativo).
1007declare -a notinstalled
1008checkDependencies DEPENDENCIES notinstalled
1009if [ $? -ne 0 ]; then
1010        installDependencies notinstalled
1011        if [ $? -ne 0 ]; then
1012                echoAndLog "Error while installing some dependeces, please verify your server installation before continue"
1013                exit 1
1014        fi
1015fi
1016
1017# Arbol de directorios de OpenGNSys.
1018openGnsysInstallCreateDirs ${INSTALL_TARGET}
1019if [ $? -ne 0 ]; then
1020        errorAndLog "Error while creating directory paths!"
1021        exit 1
1022fi
1023
1024# Descarga del repositorio de código en directorio temporal
1025#svnCheckoutCode $SVN_URL
1026svnExportCode $SVN_URL
1027if [ $? -ne 0 ]; then
1028        errorAndLog "Error while getting code from svn"
1029        exit 1
1030fi
1031
1032# Compilar código fuente de los servicios de OpenGNSys.
1033servicesCompilation
1034if [ $? -ne 0 ]; then
1035        errorAndLog "Error while compiling OpenGnsys services"
1036        exit 1
1037fi
1038
1039# Configurando tftp
1040tftpConfigure
1041
1042# Configuración NFS
1043nfsConfigure
1044if [ $? -ne 0 ]; then
1045        errorAndLog "Error while configuring nfs server!"
1046        exit 1
1047fi
1048
1049# Configuración ejemplo DHCP
1050dhcpConfigure
1051if [ $? -ne 0 ]; then
1052        errorAndLog "Error while copying your dhcp server files!"
1053        exit 1
1054fi
1055
1056# Copiar ficheros de servicios OpenGNSys Server.
1057openGnsysCopyServerFiles ${INSTALL_TARGET}
1058if [ $? -ne 0 ]; then
1059        errorAndLog "Error while copying the server files!"
1060        exit 1
1061fi
1062
1063# Instalar Base de datos de OpenGNSys Admin.
1064isInArray notinstalled "mysql-server"
1065if [ $? -eq 0 ]; then
1066        mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD}
1067else
1068        mysqlGetRootPassword
1069
1070fi
1071
1072mysqlTestConnection ${MYSQL_ROOT_PASSWORD}
1073if [ $? -ne 0 ]; then
1074        errorAndLog "Error while connection to mysql"
1075        exit 1
1076fi
1077mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1078if [ $? -ne 0 ]; then
1079        echoAndLog "Creating Web Console database"
1080        mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1081        if [ $? -ne 0 ]; then
1082                errorAndLog "Error while creating Web Console database"
1083                exit 1
1084        fi
1085else
1086        echoAndLog "Web Console database exists, ommiting creation"
1087fi
1088
1089mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER}
1090if [ $? -ne 0 ]; then
1091        echoAndLog "Creating user in database"
1092        mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
1093        if [ $? -ne 0 ]; then
1094                errorAndLog "Error while creating database user"
1095                exit 1
1096        fi
1097
1098fi
1099
1100mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1101if [ $? -eq 0 ]; then
1102        echoAndLog "Creating tables..."
1103        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
1104                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
1105        else
1106                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
1107                exit 1
1108        fi
1109fi
1110
1111# copiando paqinas web
1112installWebFiles
1113
1114# creando configuracion de apache2
1115openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2
1116if [ $? -ne 0 ]; then
1117        errorAndLog "Error configuring Apache for OpenGNSYS Admin"
1118        exit 1
1119fi
1120
1121popd
1122
1123# Creando la estructura del cliente
1124openGnsysClientCreate
1125if [ $? -ne 0 ]; then
1126        errorAndLog "Error creating clients"
1127        exit 1
1128fi
1129
1130# Configuración de servicios de OpenGNSys
1131openGnsysConfigure
1132
1133# Mostrar sumario de la instalación e instrucciones de post-instalación.
1134installationSummary
1135
1136#rm -rf $WORKDIR
1137echoAndLog "OpenGNSys installation finished at $(date)"
1138
Note: See TracBrowser for help on using the repository browser.