source: installer/opengnsys_installer.sh @ 18a810c

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 18a810c was d345fa6, checked in by ramon <ramongomez@…>, 16 years ago

Script loadenviron.sh separado en 4 partes en preinit; fase inicial para modo off-line.

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

  • Property mode set to 100755
File size: 25.9 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=$WORKDIR/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 )
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#####################################################################
43getDateTime()
44{
45        echo `date +%Y%m%d-%H%M%S`
46}
47
48# Escribe a fichero y muestra por pantalla
49echoAndLog()
50{
51        echo $1
52        FECHAHORA=`getDateTime`
53        echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE
54}
55
56errorAndLog()
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
64isInArray()
65{
66        if [ $# -ne 2 ]; then
67                errorAndLog "isInArray(): invalid number of parameters"
68                exit 1
69        fi
70
71        echoAndLog "isInArray(): checking if $2 is in $1"
72        local deps
73        eval "deps=( \"\${$1[@]}\" )"
74        elemento=$2
75
76        local is_in_array=1
77        # copia local del array del parametro 1
78        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
79        do
80                if [ "${deps[$i]}" = "${elemento}" ]; then
81                        echoAndLog "isInArray(): $elemento found in array"
82                        is_in_array=0
83                fi
84        done
85
86        if [ $is_in_array -ne 0 ]; then
87                echoAndLog "isInArray(): $elemento NOT found in array"
88        fi
89
90        return $is_in_array
91
92}
93
94#####################################################################
95####### Funciones de manejo de paquetes Debian
96#####################################################################
97
98checkPackage()
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
119checkDependencies()
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
156installDependencies()
157{
158        if [ $# -ne 1 ]; then
159                errorAndLog "installDependencies(): invalid number of parameters"
160                exit 1
161        fi
162        echoAndLog "installDependencies(): installing uncompleted dependencies"
163
164        # copia local del array del parametro 1
165        local deps
166        eval "deps=( \"\${$1[@]}\" )"
167
168        local string_deps=""
169        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
170        do
171                string_deps="$string_deps ${deps[$i]}"
172        done
173
174        if [ -z "${string_deps}" ]; then
175                errorAndLog "installDependencies(): array of dependeces is empty"
176                exit 1
177        fi
178
179        OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND
180        export DEBIAN_FRONTEND=noninteractive
181
182        echoAndLog "installDependencies(): now ${string_deps} will be installed"
183        apt-get -y install --force-yes ${string_deps}
184        if [ $? -ne 0 ]; then
185                errorAndLog "installDependencies(): error installing dependencies"
186                return 1
187        fi
188
189        DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND
190        echoAndLog "installDependencies(): dependencies installed"
191}
192
193#####################################################################
194####### Funciones para el manejo de bases de datos
195#####################################################################
196
197# This function set password to root
198mysqlSetRootPassword()
199{
200        if [ $# -ne 1 ]; then
201                errorAndLog "mysqlSetRootPassword(): invalid number of parameters"
202                exit 1
203        fi
204
205        local root_mysql=$1
206        echoAndLog "mysqlSetRootPassword(): setting root password in MySQL server"
207        /usr/bin/mysqladmin -u root password ${root_mysql}
208        if [ $? -ne 0 ]; then
209                errorAndLog "mysqlSetRootPassword(): error while setting root password in MySQL server"
210                return 1
211        fi
212        echoAndLog "mysqlSetRootPassword(): root password saved!"
213        return 0
214}
215
216# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
217mysqlGetRootPassword(){
218        local pass_mysql
219        local pass_mysql2
220        stty -echo
221        echo "Existe un servicio mysql ya instalado"
222        read -p  "Insertar clave de root de Mysql: " pass_mysql
223        echo ""
224        read -p "Confirmar clave:" pass_mysql2
225        echo ""
226        stty echo
227        if [ "$pass_mysql" == "$pass_mysql2" ] ;then
228                MYSQL_ROOT_PASSWORD=$pass_mysql
229                echo "La clave es: ${MYSQL_ROOT_PASSWORD}"
230                return 0
231        else
232                echo "Las claves no coinciden no se configura la clave del servidor de base de datos."
233                echo "las operaciones con la base de datos daran error"
234                return 1
235        fi
236
237
238}
239
240# comprueba si puede conectar con mysql con el usuario root
241function mysqlTestConnection()
242{
243        if [ $# -ne 1 ]; then
244                errorAndLog "mysqlTestConnection(): invalid number of parameters"
245                exit 1
246        fi
247
248        local root_password="${1}"
249        echoAndLog "mysqlTestConnection(): checking connection to mysql..."
250        echo "" | mysql -uroot -p"${root_password}"
251        if [ $? -ne 0 ]; then
252                errorAndLog "mysqlTestConnection(): connection to mysql failed, check root password and if daemon is running!"
253                return 1
254        else
255                echoAndLog "mysqlTestConnection(): connection success"
256                return 0
257        fi
258}
259
260# comprueba si la base de datos existe
261function mysqlDbExists()
262{
263        if [ $# -ne 2 ]; then
264                errorAndLog "mysqlDbExists(): invalid number of parameters"
265                exit 1
266        fi
267
268        local root_password="${1}"
269        local database=$2
270        echoAndLog "mysqlDbExists(): checking if $database exists..."
271        echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$"
272        if [ $? -ne 0 ]; then
273                echoAndLog "mysqlDbExists():database $database doesn't exists"
274                return 1
275        else
276                echoAndLog "mysqlDbExists():database $database exists"
277                return 0
278        fi
279}
280
281function mysqlCheckDbIsEmpty()
282{
283        if [ $# -ne 2 ]; then
284                errorAndLog "mysqlCheckDbIsEmpty(): invalid number of parameters"
285                exit 1
286        fi
287
288        local root_password="${1}"
289        local database=$2
290        echoAndLog "mysqlCheckDbIsEmpty(): checking if $database is empty..."
291        num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l`
292        if [ $? -ne 0 ]; then
293                errorAndLog "mysqlCheckDbIsEmpty(): error executing query, check database and root password"
294                exit 1
295        fi
296
297        if [ $num_tablas -eq 0 ]; then
298                echoAndLog "mysqlCheckDbIsEmpty():database $database is empty"
299                return 0
300        else
301                echoAndLog "mysqlCheckDbIsEmpty():database $database has tables"
302                return 1
303        fi
304
305}
306
307
308function mysqlImportSqlFileToDb()
309{
310        if [ $# -ne 3 ]; then
311                errorAndLog "mysqlImportSqlFileToDb(): invalid number of parameters"
312                exit 1
313        fi
314
315        local root_password="${1}"
316        local database=$2
317        local sqlfile=$3
318
319        if [ ! -f $sqlfile ]; then
320                errorAndLog "mysqlImportSqlFileToDb(): Unable to locate $sqlfile!!"
321                return 1
322        fi
323
324        echoAndLog "mysqlImportSqlFileToDb(): importing sql file to ${database}..."
325        mysql -uroot -p"${root_password}" "${database}" < $sqlfile
326        if [ $? -ne 0 ]; then
327                errorAndLog "mysqlImportSqlFileToDb(): error while importing $sqlfile in database $database"
328                return 1
329        fi
330        echoAndLog "mysqlImportSqlFileToDb(): file imported to database $database"
331        return 0
332}
333
334# Crea la base de datos
335function mysqlCreateDb()
336{
337        if [ $# -ne 2 ]; then
338                errorAndLog "mysqlCreateDb(): invalid number of parameters"
339                exit 1
340        fi
341
342        local root_password="${1}"
343        local database=$2
344
345        echoAndLog "mysqlCreateDb(): creating database..."
346        mysqladmin -u root --password="${root_password}" create $database
347        if [ $? -ne 0 ]; then
348                errorAndLog "mysqlCreateDb(): error while creating database $database"
349                return 1
350        fi
351        errorAndLog "mysqlCreateDb(): database $database created"
352        return 0
353}
354
355
356function mysqlCheckUserExists()
357{
358        if [ $# -ne 2 ]; then
359                errorAndLog "mysqlCheckUserExists(): invalid number of parameters"
360                exit 1
361        fi
362
363        local root_password="${1}"
364        local userdb=$2
365
366        echoAndLog "mysqlCheckUserExists(): checking if $userdb exists..."
367        echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user
368        if [ $? -ne 0 ]; then
369                echoAndLog "mysqlCheckUserExists(): user doesn't exists"
370                return 1
371        else
372                echoAndLog "mysqlCheckUserExists(): user already exists"
373                return 0
374        fi
375
376}
377
378# Crea un usuario administrativo para la base de datos
379function mysqlCreateAdminUserToDb()
380{
381        if [ $# -ne 4 ]; then
382                errorAndLog "mysqlCreateAdminUserToDb(): invalid number of parameters"
383                exit 1
384        fi
385
386        local root_password=$1
387        local database=$2
388        local userdb=$3
389        local passdb=$4
390
391        echoAndLog "mysqlCreateAdminUserToDb(): creating admin user ${userdb} to database ${database}"
392
393        cat > $WORKDIR/create_${database}.sql <<EOF
394GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
395GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
396FLUSH PRIVILEGES ;
397EOF
398        mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql
399        if [ $? -ne 0 ]; then
400                errorAndLog "mysqlCreateAdminUserToDb(): error while creating user in mysql"
401                rm -f $WORKDIR/create_${database}.sql
402                return 1
403        else
404                echoAndLog "mysqlCreateAdminUserToDb(): user created ok"
405                rm -f $WORKDIR/create_${database}.sql
406                return 0
407        fi
408}
409
410
411#####################################################################
412####### Funciones para el manejo de Subversion
413#####################################################################
414
415function svnCheckoutCode()
416{
417        if [ $# -ne 1 ]; then
418                errorAndLog "svnCheckoutCode(): invalid number of parameters"
419                exit 1
420        fi
421
422        local url=$1
423
424        echoAndLog "svnCheckoutCode(): downloading subversion code..."
425
426        /usr/bin/svn co "${url}" opengnsys
427        if [ $? -ne 0 ]; then
428                errorAndLog "svnCheckoutCode(): error getting code from ${url}, verify your user and password"
429                return 1
430        fi
431        echoAndLog "svnCheckoutCode(): subversion code downloaded"
432        return 0
433}
434
435############################################################
436###  Detectar red
437############################################################
438
439function getNetworkSettings()
440{
441        # Variables globales definidas:
442        # - SERVERIP: IP local del servidor.
443        # - NETIP:    IP de la red.
444        # - NETMASK:  máscara de red.
445        # - NETBROAD: IP de difusión de la red.
446        # - ROUTERIP: IP del router.
447        # - DNSIP:    IP del servidor DNS.
448
449        echoAndLog "getNetworkSettings(): Detecting default network parameters."
450        SERVERIP=$(LANG=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | head -n1 | awk '{print $1}')
451        NETMASK=$(LANG=C ifconfig | grep 'Mask:'| grep -v '127.0.0.1' | cut -d: -f4 | head -n1 | awk '{print $1}')
452        NETBROAD=$(LANG=C ifconfig | grep 'Bcast:'| grep -v '127.0.0.1' | cut -d: -f3 | head -n1 | awk '{print $1}')
453        NETIP=$(netstat -r | grep $NETMASK | awk '{print $1}')
454        ROUTERIP=$(netstat -nr | awk '$1~/0\.0\.0\.0/ {print $2}')
455        DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf)
456        if [ -z "$NETIP" -o -z "$NETMASK" ]; then
457                errorAndLog "getNetworkSettings(): Network not detected."
458                exit 1
459        fi
460
461        # Variables de ejecución de Apache
462        # - APACHE_RUN_USER
463        # - APACHE_RUN_GROUP
464        if [ -f /etc/apache2/envvars ]; then
465                source /etc/apache2/envvars
466        fi
467        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
468        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
469}
470
471
472############################################################
473### Esqueleto para el Servicio pxe y contenedor tftpboot ###
474############################################################
475
476function tftpConfigure() {
477        echo "Configurando el servicio tftp"
478        basetftp=/var/lib/tftpboot
479
480        # reiniciamos demonio internet ????? porque ????
481        /etc/init.d/openbsd-inetd start
482
483        # preparacion contenedor tftpboot
484        cp -pr /usr/lib/syslinux/ ${basetftp}/syslinux
485        cp /usr/lib/syslinux/pxelinux.0 ${basetftp}
486        # prepamos el directorio de la configuracion de pxe
487        mkdir -p ${basetftp}/pxelinux.cfg
488        cat > ${basetftp}/pxelinux.cfg/default <<EOF
489DEFAULT pxe
490
491LABEL pxe
492KERNEL linux
493APPEND initrd=initrd.gz ip=dhcp ro vga=788 irqpoll acpi=on
494EOF
495        # comprobamos el servicio tftp
496        sleep 1
497        testPxe
498        ## damos perfimos de lectura a usuario web.
499        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP ${basetftp}
500}
501
502function testPxe () {
503        cd /tmp
504        echo "comprobando servicio pxe ..... Espere"
505        tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echo "servidor tftp OK" || echo "servidor tftp KO"
506        cd /
507}
508
509########################################################################
510## Configuracion servicio NFS
511########################################################################
512
513function nfsConfigure ()
514{
515        echoAndLog "nfsConfigure(): Sample NFS Configuration."
516        sed -e "s/NETIP/$NETIP/g" -e "s/NETMASK/$NETMASK/g" $WORKDIR/opengnsys/server/NFS/exports  >> /etc/exports
517        /etc/init.d/nfs-kernel-server restart
518        exportfs -va
519        echoAndLog "nfsConfigure(): Sample NFS Configured in file \"/etc/exports\"."
520}
521
522
523########################################################################
524## Configuracion servicio DHCP
525########################################################################
526
527function dhcpConfigure()
528{
529        echoAndLog "dhcpConfigure(): Sample DHCP Configuration."
530        sed -e "s/SERVERIP/$SERVERIP/g" \
531            -e "s/NETIP/$NETIP/g" \
532            -e "s/NETMASK/$NETMASK/g" \
533            -e "s/NETBROAD/$NETBROAD/g" \
534            -e "s/ROUTERIP/$ROUTERIP/g" \
535            -e "s/DNSIP/$DNSIP/g" \
536            $WORKDIR/opengnsys/server/DHCP/dhcpd.conf > /etc/dhcp3/dhcpd.conf
537        /etc/init.d/dhcp3-server restart
538        echoAndLog "dhcpConfigure(): Sample DHCP Configured in file \"/etc/dhcp3/dhcpd.conf\"."
539}
540
541
542#####################################################################
543####### Funciones específicas de la instalación de Opengnsys
544#####################################################################
545
546# Copiar ficheros del OpenGNSys Web Console.
547function installWebFiles()
548{
549        echoAndLog "installWebFiles(): Installing web files..."
550        cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www   #*/ comentario para doxigen
551        if [ $? != 0 ]; then
552                errorAndLog "installWebFiles(): Error copying web files."
553                exit 1
554        fi
555        find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null
556        # Cambiar permisos para ficheros especiales.
557        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP \
558                        $INSTALL_TARGET/www/includes \
559                        $INSTALL_TARGET/www/comandos/gestores/filescripts \
560                        $INSTALL_TARGET/www/images/icons
561        echoAndLog "installWebFiles(): Web files installed successfully."
562}
563
564# Configuración específica de Apache.
565function openGnsysInstallWebConsoleApacheConf()
566{
567        if [ $# -ne 2 ]; then
568                errorAndLog "openGnsysInstallWebConsoleApacheConf(): invalid number of parameters"
569                exit 1
570        fi
571
572        local path_opengnsys_base=$1
573        local path_apache2_confd=$2
574        local path_web_console=${path_opengnsys_base}/www
575
576        if [ ! -d $path_apache2_confd ]; then
577                errorAndLog "openGnsysInstallWebConsoleApacheConf(): path to apache2 conf.d can not found, verify your server installation"
578                return 1
579        fi
580
581        mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
582
583        echoAndLog "openGnsysInstallWebConsoleApacheConf(): creating apache2 config file.."
584
585        # genera configuración
586        cat > $path_opengnsys_base/etc/apache.conf <<EOF
587# OpenGNSys Web Console configuration for Apache
588
589Alias /opengnsys ${path_web_console}
590
591<Directory ${path_web_console}>
592        Options -Indexes FollowSymLinks
593        DirectoryIndex acceso.php
594</Directory>
595EOF
596
597        ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys.conf
598        ln -fs $path_apache2_confd/sites-available/opengnsys.conf $path_apache2_confd/sites-enabled/opengnsys.conf
599        if [ $? -ne 0 ]; then
600                errorAndLog "openGnsysInstallWebConsoleApacheConf(): config file can't be linked to apache conf, verify your server installation"
601                return 1
602        else
603                echoAndLog "openGnsysInstallWebConsoleApacheConf(): config file created and linked, restarting apache daemon"
604                /etc/init.d/apache2 restart
605                return 0
606        fi
607}
608
609# Crea la estructura base de la instalación de opengnsys
610function openGnsysInstallCreateDirs()
611{
612        if [ $# -ne 1 ]; then
613                errorAndLog "openGnsysInstallCreateDirs(): invalid number of parameters"
614                exit 1
615        fi
616
617        local path_opengnsys_base=$1
618
619        echoAndLog "openGnsysInstallCreateDirs(): creating directory paths in $path_opengnsys_base"
620
621        mkdir -p $path_opengnsys_base
622        mkdir -p $path_opengnsys_base/admin/{autoexec,comandos,menus,usuarios}
623        mkdir -p $path_opengnsys_base/bin
624        mkdir -p $path_opengnsys_base/client
625        mkdir -p $path_opengnsys_base/etc
626        mkdir -p $path_opengnsys_base/lib
627        mkdir -p $path_opengnsys_base/log/clients
628        mkdir -p $path_opengnsys_base/sbin
629        mkdir -p $path_opengnsys_base/www
630        mkdir -p $path_opengnsys_base/images
631        ln -fs /var/lib/tftpboot $path_opengnsys_base
632        ln -fs $path_opengnsys_base/log /var/log/opengnsys
633
634        if [ $? -ne 0 ]; then
635                errorAndLog "openGnsysInstallCreateDirs(): error while creating dirs. Do you have write permissions?"
636                return 1
637        fi
638
639        echoAndLog "openGnsysInstallCreateDirs(): directory paths created"
640        return 0
641}
642
643# Copia ficheros de configuración y ejecutables genéricos del servidor.
644function openGnsysCopyServerFiles () {
645        if [ $# -ne 1 ]; then
646                errorAndLog "openGnsysCopyServerFiles(): invalid number of parameters"
647                exit 1
648        fi
649
650        local path_opengnsys_base=$1
651
652        local SOURCES=( client/boot/initrd-generator \
653                        client/boot/upgrade-clients-udeb.sh \
654                        client/boot/udeblist.conf )
655        local TARGETS=( bin/initrd-generator \
656                        bin/upgrade-clients-udeb.sh \
657                        etc/udeblist.conf )
658
659        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
660                errorAndLog "openGnsysCopyServerFiles(): inconsistent number of array items"
661                exit 1
662        fi
663
664        echoAndLog "openGnsysCopyServerFiles(): copying files to server directories"
665
666        pushd $WORKDIR/opengnsys
667        local i
668        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
669                if [ -f "${SOURCES[$i]}" ]; then
670                        echoAndLog "copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
671                        cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
672                fi
673                if [ -d "${SOURCES[$i]}" ]; then
674                        echoAndLog "openGnsysCopyServerFiles(): copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
675                        cp -ar "${SOURCES[$i]}/*" "${path_opengnsys_base}/${TARGETS[$i]}"
676                fi
677        done
678        popd
679}
680
681####################################################################
682### Funciones de compilación de códifo fuente de servicios
683####################################################################
684
685# Compilar los servicios de OpenGNsys
686function servicesCompilation ()
687{
688        # Compilar OpenGNSys Server
689        echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Server"
690        pushd $WORKDIR/opengnsys/admin/Services/ogAdmServer
691        make && make install
692        popd
693        # Compilar OpenGNSys Repository Manager
694        echoAndLog "servicesCompilation(): Compiling OpenGNSys Repository Manager"
695        pushd $WORKDIR/opengnsys/admin/Services/ogAdmRepo
696        make && make install
697        popd
698        # Compilar OpenGNSys Client
699        echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Client"
700        pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
701        make && mv ogAdmClient ../../../client/nfsexport/bin
702        popd
703}
704
705
706####################################################################
707### Funciones instalacion cliente opengnsys
708####################################################################
709
710function openGnsysClientCreate ()
711{
712        local OSDISTRIB OSCODENAME
713
714        echoAndLog "openGnsysClientCreate(): Copying OpenGNSys Client files."
715        cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
716        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
717        chmod +x $INSTALL_TARGET/client/admin/scripts/*
718        echoAndLog "openGnsysClientCreate(): Copying OpenGNSys Cloning Engine files."
719        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
720        cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
721
722        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
723        OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
724        OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
725        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
726                echoAndLog "openGnsysClientCreate(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
727                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
728                echoAndLog "openGnsysClientCreate(): Loading udeb files for $OSDISTRIB $OSCODENAME."
729                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
730        else
731                echoAndLog "openGnsysClientCreate(): Loading default Kernel and Initrd files."
732                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
733
734                echoAndLog "openGnsysClientCreate(): Loading default udeb files."
735                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh
736        fi
737}
738
739
740# Configuración básica de servicios de OpenGNSys
741function openGnsysConfigure()
742{
743        echoAndLog "openGnsysConfigure(): Copying init files."
744        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
745        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.default /etc/default/opengnsys
746        update-rc.d opengnsys defaults
747        echoAndLog "openGnsysConfigure(): Creating OpenGNSys config file in \"$INSTALL_TARGET/etc\"."
748        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmServer.cfg
749        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg
750        sed -e "s/SERVERIP/$SERVERIP/g" $WORKDIR/opengnsys/admin/Services/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg
751        echoAndLog "openGnsysConfigure(): Creating Web Console config file"
752        perl -pi -e "s/SERVERIP/$SERVERIP/g; s/OPENGNSYSURL/http:\/\/$SERVERIP\/opengnsys/g" $INSTALL_TARGET/www/controlacceso.php
753        echoAndLog "openGnsysConfiguration(): Starting OpenGNSys services."
754        /etc/init.d/opengnsys start
755}
756
757
758#####################################################################
759####### Proceso de instalación de OpenGNSys
760#####################################################################
761
762
763echoAndLog "OpenGNSys installation begins at $(date)"
764
765# Detectar parámetros de red por defecto
766getNetworkSettings
767if [ $? -ne 0 ]; then
768        errorAndLog "Error reading default network settings."
769        exit 1
770fi
771
772# Actualizar repositorios
773apt-get update
774
775# Instalación de dependencias (paquetes de sistema operativo).
776declare -a notinstalled
777checkDependencies DEPENDENCIES notinstalled
778if [ $? -ne 0 ]; then
779        installDependencies notinstalled
780        if [ $? -ne 0 ]; then
781                echoAndLog "Error while installing some dependeces, please verify your server installation before continue"
782                exit 1
783        fi
784fi
785
786# Arbol de directorios de OpenGNSys.
787openGnsysInstallCreateDirs ${INSTALL_TARGET}
788if [ $? -ne 0 ]; then
789        errorAndLog "Error while creating directory paths!"
790        exit 1
791fi
792
793# Descarga del repositorio de código en directorio temporal
794svnCheckoutCode $SVN_URL
795if [ $? -ne 0 ]; then
796        errorAndLog "Error while getting code from svn"
797        exit 1
798fi
799
800# Compilar código fuente de los servicios de OpenGNSys.
801servicesCompilation
802
803# Configurando tftp
804tftpConfigure
805
806# Configuración NFS
807nfsConfigure
808
809# Configuración ejemplo DHCP
810dhcpConfigure
811
812# Copiar ficheros de servicios OpenGNSys Server.
813openGnsysCopyServerFiles ${INSTALL_TARGET}
814if [ $? -ne 0 ]; then
815        errorAndLog "Error while copying the server files!"
816        exit 1
817fi
818
819# Instalar Base de datos de OpenGNSys Admin.
820isInArray notinstalled "mysql-server"
821if [ $? -eq 0 ]; then
822        mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD}
823else
824        mysqlGetRootPassword
825
826fi
827
828mysqlTestConnection ${MYSQL_ROOT_PASSWORD}
829if [ $? -ne 0 ]; then
830        errorAndLog "Error while connection to mysql"
831        exit 1
832fi
833mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
834if [ $? -ne 0 ]; then
835        echoAndLog "Creating Web Console database"
836        mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
837        if [ $? -ne 0 ]; then
838                errorAndLog "Error while creating Web Console database"
839                exit 1
840        fi
841else
842        echoAndLog "Web Console database exists, ommiting creation"
843fi
844
845mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER}
846if [ $? -ne 0 ]; then
847        echoAndLog "Creating user in database"
848        mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
849        if [ $? -ne 0 ]; then
850                errorAndLog "Error while creating database user"
851                exit 1
852        fi
853
854fi
855
856mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
857if [ $? -eq 0 ]; then
858        echoAndLog "Creating tables..."
859        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
860                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
861        else
862                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
863                exit 1
864        fi
865fi
866
867# copiando paqinas web
868installWebFiles
869
870# creando configuracion de apache2
871openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2
872if [ $? -ne 0 ]; then
873        errorAndLog "Error configuring Apache for OpenGNSYS Admin"
874        exit 1
875fi
876
877popd
878
879# Creando la estructura del cliente
880openGnsysClientCreate
881
882# Configuración de servicios de OpenGNSys
883openGnsysConfigure
884
885#rm -rf $WORKDIR
886echoAndLog "OpenGNSys installation finished at $(date)"
887
Note: See TracBrowser for help on using the repository browser.