source: installer/opengnsys_installer.sh @ cc3b46b

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

Versión 1.0.1: corregir errata en actualización de permisos para PXE (cerrar #412).

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

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