source: installer/opengnsys_installer.sh @ 1c9cd8b1

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 1c9cd8b1 was 1e7eaab, checked in by ramon <ramongomez@…>, 15 years ago

Installador vale para repositorio y descargable; funciones de API compatibles Doxygen.

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

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