source: installer/opengnsys_installer.sh @ de87b1a

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 de87b1a was 6ef9f23, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0: instalador y actualizador descargan el cliente desde un único fichero.

git-svn-id: https://opengnsys.es/svn/branches/version1.0@1542 a21b9725-9963-47de-94b9-378ad31fedc9

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