source: installer/opengnsys_installer.sh @ 1a22cd2

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

OpenGNSys Installer configura acceso en Web Console y no compila Browser.

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

  • Property mode set to 100755
File size: 26.0 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 php5 mysql-server nfs-kernel-server dhcp3-server udpcast bittorrent apache2 php5 mysql-server php5-mysql 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, restart your apache daemon"
604                return 0
605        fi
606}
607
608# Crea la estructura base de la instalación de opengnsys
609function openGnsysInstallCreateDirs()
610{
611        if [ $# -ne 1 ]; then
612                errorAndLog "openGnsysInstallCreateDirs(): invalid number of parameters"
613                exit 1
614        fi
615
616        local path_opengnsys_base=$1
617
618        echoAndLog "openGnsysInstallCreateDirs(): creating directory paths in $path_opengnsys_base"
619
620        mkdir -p $path_opengnsys_base
621        mkdir -p $path_opengnsys_base/admin/{autoexec,comandos,menus,scripts,usuarios}
622        mkdir -p $path_opengnsys_base/bin
623        mkdir -p $path_opengnsys_base/client
624        mkdir -p $path_opengnsys_base/etc
625        mkdir -p $path_opengnsys_base/lib
626        mkdir -p $path_opengnsys_base/log/clients
627        mkdir -p $path_opengnsys_base/sbin
628        mkdir -p $path_opengnsys_base/www
629        mkdir -p $path_opengnsys_base/images
630        ln -fs /var/lib/tftpboot $path_opengnsys_base
631        ln -fs $path_opengnsys_base/log /var/log/opengnsys
632
633        if [ $? -ne 0 ]; then
634                errorAndLog "openGnsysInstallCreateDirs(): error while creating dirs. Do you have write permissions?"
635                return 1
636        fi
637
638        echoAndLog "openGnsysInstallCreateDirs(): directory paths created"
639        return 0
640}
641
642# Copia ficheros de configuración y ejecutables genéricos del servidor.
643function openGnsysCopyServerFiles () {
644        if [ $# -ne 1 ]; then
645                errorAndLog "openGnsysCopyServerFiles(): invalid number of parameters"
646                exit 1
647        fi
648
649        local path_opengnsys_base=$1
650
651        local SOURCES=( client/boot/initrd-generator \
652                        client/boot/upgrade-clients-udeb.sh \
653                        client/boot/udeblist.conf )
654        local TARGETS=( bin/initrd-generator \
655                        bin/upgrade-clients-udeb.sh \
656                        etc/udeblist.conf )
657
658        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
659                errorAndLog "openGnsysCopyServerFiles(): inconsistent number of array items"
660                exit 1
661        fi
662
663        echoAndLog "openGnsysCopyServerFiles(): copying files to server directories"
664
665        pushd $WORKDIR/opengnsys
666        local i
667        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
668                if [ -f "${SOURCES[$i]}" ]; then
669                        echoAndLog "copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
670                        cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
671                fi
672                if [ -d "${SOURCES[$i]}" ]; then
673                        echoAndLog "openGnsysCopyServerFiles(): copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
674                        cp -ar "${SOURCES[$i]}/*" "${path_opengnsys_base}/${TARGETS[$i]}"
675                fi
676        done
677        popd
678}
679
680####################################################################
681### Funciones de compilación de códifo fuente de servicios
682####################################################################
683
684# Compilar los servicios de OpenGNsys
685function servicesCompilation ()
686{
687        # Compilar OpenGNSys Server
688        echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Server"
689        pushd $WORKDIR/opengnsys/admin/Services/ogAdmServer
690        make && make install
691        popd
692        # Compilar OpenGNSys Repository Manager
693        echoAndLog "servicesCompilation(): Compiling OpenGNSys Repository Manager"
694        pushd $WORKDIR/opengnsys/admin/Services/ogAdmRepo
695        make && make install
696        popd
697        # Compilar OpenGNSys Client
698        echoAndLog "servicesCompilation(): Compiling OpenGNSys Admin Client"
699        pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
700        make && mv ogAdmClient ../../../client/nfsexport/bin
701        popd
702}
703
704
705####################################################################
706### Funciones instalacion cliente opengnsys
707####################################################################
708
709function openGnsysClientCreate ()
710{
711        local OSDISTRIB OSCODENAME
712
713        echoAndLog "openGnsysClientCreate(): Copying OpenGNSys Client files."
714        cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
715        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
716        echoAndLog "openGnsysClientCreate(): Copying OpenGNSys Cloning Engine files."
717        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
718        cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
719        cp -ar $WORKDIR/opengnsys/client/engine/*.sh $INSTALL_TARGET/client/lib/engine/bin
720
721        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
722        OSDISRIB=$(lsb_release -i | awk -F: '{print $2}') 2>/dev/null
723        OSCODENAME=$(lsb_release -c | awk -F: '{print $2}') 2>/dev/null
724        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
725                echoAndLog "openGnsysClientCreate(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
726                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
727                echoAndLog "openGnsysClientCreate(): Loading udeb files for $OSDISTRIB $OSCODENAME."
728                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
729        else
730                echoAndLog "openGnsysClientCreate(): Loading default Kernel and Initrd files."
731                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
732
733                echoAndLog "openGnsysClientCreate(): Loading default udeb files."
734                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh
735        fi
736}
737
738
739# Configuración básica de servicios de OpenGNSys
740function openGnsysConfigure()
741{
742        echoAndLog "openGnsysConfigure(): Copying init files."
743        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
744        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.default /etc/default/opengnsys
745        update-rc.d opengnsys defaults
746        echoAndLog "openGnsysConfigure(): Creating OpenGNSys config file in \"$INSTALL_TARGET/etc\"."
747        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmServer.cfg
748        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg
749        sed -e "s/SERVERIP/$SERVERIP/g" $WORKDIR/opengnsys/admin/Services/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg
750        echoAndLog "openGnsysConfigure(): Creating Web Console config file"
751        perl -pi -e "s/SERVERIP/$SERVERIP/g" \
752                 -e "s/OPENGNSYSURL/http:\/\/$SERVERIP\/opengnsys/g" \
753                 $INSTALL_TARGET/www/controlacceso.php
754        echoAndLog "openGnsysConfiguration(): Starting OpenGNSys services."
755        /etc/init.d/opengnsys start
756}
757
758
759#####################################################################
760####### Proceso de instalación de OpenGNSys
761#####################################################################
762
763
764echoAndLog "OpenGNSys installation begins at $(date)"
765
766# Detectar parámetros de red por defecto
767getNetworkSettings
768if [ $? -ne 0 ]; then
769        errorAndLog "Error reading default network settings."
770        exit 1
771fi
772
773# Actualizar repositorios
774apt-get update
775
776# Instalación de dependencias (paquetes de sistema operativo).
777declare -a notinstalled
778checkDependencies DEPENDENCIES notinstalled
779if [ $? -ne 0 ]; then
780        installDependencies notinstalled
781        if [ $? -ne 0 ]; then
782                echoAndLog "Error while installing some dependeces, please verify your server installation before continue"
783                exit 1
784        fi
785fi
786
787# Arbol de directorios de OpenGNSys.
788openGnsysInstallCreateDirs ${INSTALL_TARGET}
789if [ $? -ne 0 ]; then
790        errorAndLog "Error while creating directory paths!"
791        exit 1
792fi
793
794# Descarga del repositorio de código en directorio temporal
795svnCheckoutCode $SVN_URL
796if [ $? -ne 0 ]; then
797        errorAndLog "Error while getting code from svn"
798        exit 1
799fi
800
801# Compilar código fuente de los servicios de OpenGNSys.
802servicesCompilation
803
804# Configurando tftp
805tftpConfigure
806
807# Configuración NFS
808nfsConfigure
809
810# Configuración ejemplo DHCP
811dhcpConfigure
812
813# Copiar ficheros de servicios OpenGNSys Server.
814openGnsysCopyServerFiles ${INSTALL_TARGET}
815if [ $? -ne 0 ]; then
816        errorAndLog "Error while copying the server files!"
817        exit 1
818fi
819
820# Instalar Base de datos de OpenGNSys Admin.
821isInArray notinstalled "mysql-server"
822if [ $? -eq 0 ]; then
823        mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD}
824else
825        mysqlGetRootPassword
826
827fi
828
829mysqlTestConnection ${MYSQL_ROOT_PASSWORD}
830if [ $? -ne 0 ]; then
831        errorAndLog "Error while connection to mysql"
832        exit 1
833fi
834mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
835if [ $? -ne 0 ]; then
836        echoAndLog "Creating Web Console database"
837        mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
838        if [ $? -ne 0 ]; then
839                errorAndLog "Error while creating Web Console database"
840                exit 1
841        fi
842else
843        echoAndLog "Web Console database exists, ommiting creation"
844fi
845
846mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER}
847if [ $? -ne 0 ]; then
848        echoAndLog "Creating user in database"
849        mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
850        if [ $? -ne 0 ]; then
851                errorAndLog "Error while creating database user"
852                exit 1
853        fi
854
855fi
856
857mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
858if [ $? -eq 0 ]; then
859        echoAndLog "Creating tables..."
860        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
861                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
862        else
863                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
864                exit 1
865        fi
866fi
867
868# copiando paqinas web
869installWebFiles
870
871# creando configuracion de apache2
872openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2
873if [ $? -ne 0 ]; then
874        errorAndLog "Error configuring Apache for OpenGNSYS Admin"
875        exit 1
876fi
877
878popd
879
880# Creando la estructura del cliente
881openGnsysClientCreate
882
883# Configuración de servicios de OpenGNSys
884openGnsysConfigure
885
886rm -rf $WORKDIR
887echoAndLog "OpenGNSys installation finished at $(date)"
888
Note: See TracBrowser for help on using the repository browser.