source: installer/opengnsys_installer.sh @ 803bc36

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 803bc36 was edac247, checked in by ramon <ramongomez@…>, 14 years ago

Rama version1.0: corregir erratas de caminos en el instalador y adaptar script torrent-creator de la rama Testing.

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

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