source: installer/opengnsys_installer.sh @ 8457092

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

ICreado nuevo tar.gz solucionando fallos de instalador (ticket #102).

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

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