source: installer/opengnsys_update.sh @ 31d4f1a5

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 31d4f1a5 was 0645906, checked in by ramon <ramongomez@…>, 8 years ago

#708: Nuevo script de ejecución cronológica para enviar a los OGAgent las operaciones pendientes; preparar su instalación en instalación y actualización.

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

  • Property mode set to 100755
File size: 35.9 KB
Line 
1#!/bin/bash
2#/**
3#@file    opengnsys_update.sh
4#@brief   Script actualización de OpenGnsys
5#@version 0.9 - basado en opengnsys_installer.sh
6#@author  Ramón Gómez - ETSII Univ. Sevilla
7#@date    2010/01/27
8#@version 1.0 - adaptación a OpenGnSys 1.0
9#@author  Ramón Gómez - ETSII Univ. Sevilla
10#@date    2011/03/02
11#@version 1.0.1 - control de auto actualización del script
12#@author  Ramón Gómez - ETSII Univ. Sevilla
13#@date    2011/05/17
14#@version 1.0.2a - obtiene valor de dirección IP por defecto
15#@author  Ramón Gómez - ETSII Univ. Sevilla
16#@date    2012/01/18
17#@version 1.0.3 - Compatibilidad con Debian y auto configuración de acceso a BD.
18#@author  Ramón Gómez - ETSII Univ. Sevilla
19#@date    2012/03/12
20#@version 1.0.4 - Detector de distribución y compatibilidad con CentOS.
21#@author  Ramón Gómez - ETSII Univ. Sevilla
22#@date    2012/05/04
23#@version 1.0.5 - Actualizar BD en la misma versión, compatibilidad con Fedora (systemd) y configuración de Rsync.
24#@author  Ramón Gómez - ETSII Univ. Sevilla
25#@date    2014/04/03
26#@version 1.0.6 - Redefinir URLs de ficheros de configuración usando HTTPS.
27#@author  Ramón Gómez - ETSII Univ. Sevilla
28#@date    2015/03/12
29#@version 1.1.0 - Instalación de API REST y configuración de zona horaria.
30#@author  Ramón Gómez - ETSII Univ. Sevilla
31#@date    2015/11/09
32#*/
33
34
35####  AVISO: NO EDITAR variables de configuración.
36####  WARNING: DO NOT EDIT configuration variables.
37INSTALL_TARGET=/opt/opengnsys           # Directorio de instalación
38PATH=$PATH:$INSTALL_TARGET/bin
39OPENGNSYS_CLIENTUSER="opengnsys"        # Usuario Samba
40
41
42# Sólo ejecutable por usuario root
43if [ "$(whoami)" != 'root' ]; then
44        echo "ERROR: this program must run under root privileges!!"
45        exit 1
46fi
47# Error si OpenGnsys no está instalado (no existe el directorio del proyecto)
48if [ ! -d $INSTALL_TARGET ]; then
49        echo "ERROR: OpenGnsys is not installed, cannot update!!"
50        exit 1
51fi
52# Cargar configuración de acceso a la base de datos.
53if [ -r $INSTALL_TARGET/etc/ogAdmServer.cfg ]; then
54        source $INSTALL_TARGET/etc/ogAdmServer.cfg
55elif [ -r $INSTALL_TARGET/etc/ogAdmAgent.cfg ]; then
56        source $INSTALL_TARGET/etc/ogAdmAgent.cfg
57fi
58OPENGNSYS_DATABASE=${OPENGNSYS_DATABASE:-"$CATALOG"}            # Base de datos
59OPENGNSYS_DBUSER=${OPENGNSYS_DBUSER:-"$USUARIO"}                # Usuario de acceso
60OPENGNSYS_DBPASSWORD=${OPENGNSYS_DBPASSWORD:-"$PASSWORD"}       # Clave del usuario
61if [ -z "$OPENGNSYS_DATABASE" -o -z "$OPENGNSYS_DBUSER" -o -z "$OPENGNSYS_DBPASSWORD" ]; then
62        echo "ERROR: set OPENGNSYS_DATABASE, OPENGNSYS_DBUSER and OPENGNSYS_DBPASSWORD"
63        echo "       variables, and run this script again."
64fi
65
66# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1).
67PROGRAMDIR=$(readlink -e $(dirname "$0"))
68PROGRAMNAME=$(basename "$0")
69OPENGNSYS_SERVER="opengnsys.es"
70if [ -d "$PROGRAMDIR/../installer" ]; then
71        USESVN=0
72else
73        USESVN=1
74fi
75SVN_URL="https://$OPENGNSYS_SERVER/svn/branches/version1.1/"
76
77WORKDIR=/tmp/opengnsys_update
78mkdir -p $WORKDIR
79
80# Registro de incidencias.
81OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log
82LOG_FILE=/tmp/$(basename $OGLOGFILE)
83
84
85
86#####################################################################
87####### Algunas funciones útiles de propósito general:
88#####################################################################
89
90# Generar variables de configuración del actualizador
91# Variables globales:
92# - OSDISTRIB - distribución Linux
93# - DEPENDENCIES - array de dependencias que deben estar instaladas
94# - UPDATEPKGLIST, INSTALLPKGS, CHECKPKG - comandos para gestión de paquetes
95# - APACHECFGDIR, APACHESERV, DHCPSERV, INETDCFGDIR - configuración y servicios
96function autoConfigure()
97{
98local i
99
100# Detectar sistema operativo del servidor (compatible con fichero os-release y con LSB).
101if [ -f /etc/os-release ]; then
102        source /etc/os-release
103        OSDISTRIB="$ID"
104        OSVERSION="$VERSION_ID"
105else
106        OSDISTRIB=$(lsb_release -is 2>/dev/null)
107        OSVERSION=$(lsb_release -rs 2>/dev/null)
108fi
109# Convertir distribución a minúsculas y obtener solo el 1er número de versión.
110OSDISTRIB="${OSDISTRIB,,}"
111OSVERSION="${OSVERSION%%.*}"
112
113# Configuración según la distribución de Linux.
114case "$OSDISTRIB" in
115        ubuntu|debian|linuxmint)
116                DEPENDENCIES=( php5-ldap xinetd curl rsync btrfs-tools procps arp-scan realpath php5-curl gettext moreutils jq )
117                UPDATEPKGLIST="apt-get update"
118                INSTALLPKGS="apt-get -y install --force-yes"
119                CHECKPKG="dpkg -s \$package 2>/dev/null | grep -q \"Status: install ok\""
120                if which service &>/dev/null; then
121                        STARTSERVICE="eval service \$service restart"
122                        STOPSERVICE="eval service \$service stop"
123                else
124                        STARTSERVICE="eval /etc/init.d/\$service restart"
125                        STOPSERVICE="eval /etc/init.d/\$service stop"
126                fi
127                ENABLESERVICE="eval update-rc.d \$service defaults"
128                APACHEUSER="www-data"
129                APACHEGROUP="www-data"
130                INETDCFGDIR=/etc/xinetd.d
131                ;;
132        fedora|centos)
133                DEPENDENCIES=( php-ldap xinetd curl rsync btrfs-progs procps-ng arp-scan gettext moreutils jq )
134                # En CentOS 7 instalar arp-scan de CentOS 6.
135                [ "$OSDISTRIB$OSVERSION" == "centos7" ] && DEPENDENCIES=( ${DEPENDENCIES[*]/arp-scan/http://dag.wieers.com/redhat/el6/en/$(arch)/dag/RPMS/arp-scan-1.9-1.el6.rf.$(arch).rpm} )
136                INSTALLPKGS="yum install -y"
137                CHECKPKG="rpm -q --quiet \$package"
138                if which systemctl &>/dev/null; then
139                        STARTSERVICE="eval systemctl start \$service.service"
140                        STOPSERVICE="eval systemctl stop \$service.service"
141                        ENABLESERVICE="eval systemctl enable \$service.service"
142                else
143                        STARTSERVICE="eval service \$service start"
144                        STOPSERVICE="eval service \$service stop"
145                        ENABLESERVICE="eval chkconfig \$service on"
146                fi
147                APACHEUSER="apache"
148                APACHEGROUP="apache"
149                INETDCFGDIR=/etc/xinetd.d
150                ;;
151        *)      # Otras distribuciones.
152                ;;
153esac
154for i in apache2 httpd; do
155        [ -d /etc/$i ] && APACHECFGDIR="/etc/$i"
156        [ -f /etc/init.d/$i ] && APACHESERV="/etc/init.d/$i"
157done
158for i in dhcpd dhcpd3-server isc-dhcp-server; do
159        [ -f /etc/init.d/$i ] && DHCPSERV="/etc/init.d/$i"
160done
161}
162
163
164# Comprobar auto-actualización.
165function checkAutoUpdate()
166{
167        local update=0
168
169        # Actaulizar el script si ha cambiado o no existe el original.
170        if [ $USESVN -eq 1 ]; then
171                svn export $SVN_URL/installer/$PROGRAMNAME
172                if ! diff -q $PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME 2>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
173                        mv $PROGRAMNAME $INSTALL_TARGET/lib
174                        update=1
175                else
176                        rm -f $PROGRAMNAME
177                fi
178        else
179                if ! diff -q $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME 2>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
180                        cp -a $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib
181                        update=1
182                fi
183        fi
184
185        return $update
186}
187
188
189function getDateTime()
190{
191        date "+%Y%m%d-%H%M%S"
192}
193
194# Escribe a fichero y muestra por pantalla
195function echoAndLog()
196{
197        echo $1
198        DATETIME=`getDateTime`
199        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
200}
201
202function errorAndLog()
203{
204        echo "ERROR: $1"
205        DATETIME=`getDateTime`
206        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
207}
208
209# Escribe a fichero y muestra mensaje de aviso
210function warningAndLog()
211{
212        local DATETIME=`getDateTime`
213        echo "Warning: $1"
214        echo "$DATETIME;$SSH_CLIENT;Warning: $1" >> $LOG_FILE
215}
216
217
218#####################################################################
219####### Funciones de copia de seguridad y restauración de ficheros
220#####################################################################
221
222# Hace un backup del fichero pasado por parámetro
223# deja un -last y uno para el día
224function backupFile()
225{
226        if [ $# -ne 1 ]; then
227                errorAndLog "${FUNCNAME}(): invalid number of parameters"
228                exit 1
229        fi
230
231        local fichero=$1
232        local fecha=`date +%Y%m%d`
233
234        if [ ! -f $fichero ]; then
235                warningAndLog "${FUNCNAME}(): file $fichero doesn't exists"
236                return 1
237        fi
238
239        echoAndLog "${FUNCNAME}(): Making $fichero back-up"
240
241        # realiza una copia de la última configuración como last
242        cp -a $fichero "${fichero}-LAST"
243
244        # si para el día no hay backup lo hace, sino no
245        if [ ! -f "${fichero}-${fecha}" ]; then
246                cp -a $fichero "${fichero}-${fecha}"
247        fi
248}
249
250# Restaura un fichero desde su copia de seguridad
251function restoreFile()
252{
253        if [ $# -ne 1 ]; then
254                errorAndLog "${FUNCNAME}(): invalid number of parameters"
255                exit 1
256        fi
257
258        local fichero=$1
259
260        echoAndLog "${FUNCNAME}(): restoring file $fichero"
261        if [ -f "${fichero}-LAST" ]; then
262                cp -a "$fichero-LAST" "$fichero"
263        fi
264}
265
266
267#####################################################################
268####### Funciones de acceso a base de datos
269#####################################################################
270
271# Actualizar la base datos
272function importSqlFile()
273{
274        if [ $# -ne 4 ]; then
275                errorAndLog "${FNCNAME}(): invalid number of parameters"
276                exit 1
277        fi
278
279        local dbuser="$1"
280        local dbpassword="$2"
281        local database="$3"
282        local sqlfile="$4"
283        local tmpfile=$(mktemp)
284        local mycnf=/tmp/.my.cnf.$$
285        local status
286        local APIKEY=$(php -r 'echo md5(uniqid(rand(), true));')
287        REPOKEY=$(php -r 'echo md5(uniqid(rand(), true));')
288
289        if [ ! -r $sqlfile ]; then
290                errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!"
291                return 1
292        fi
293
294        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
295        chmod 600 $tmpfile
296        sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
297            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
298            -e "s/APIKEY/$APIKEY/g" -e "s/REPOKEY/$REPOKEY/g" $sqlfile > $tmpfile
299        # Componer fichero con credenciales de conexión. 
300        touch $mycnf
301        chmod 600 $mycnf
302        cat << EOT > $mycnf
303[client]
304user=$dbuser
305password=$dbpassword
306EOT
307        # Ejecutar actualización y borrar fichero de credenciales.
308        mysql --defaults-extra-file=$mycnf --default-character-set=utf8 -D "$database" < $tmpfile
309        status=$?
310        rm -f $mycnf $tmpfile
311        if [ $status -ne 0 ]; then
312                errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database"
313                return 1
314        fi
315        echoAndLog "${FUNCNAME}(): file imported to database $database"
316        return 0
317}
318
319# Comprobar configuración de MySQL y recomendar cambios necesarios.
320function checkMysqlConfig()
321{
322        if [ $# -ne 2 ]; then
323                errorAndLog "${FNCNAME}(): invalid number of parameters"
324                exit 1
325        fi
326
327        local dbuser="$1"
328        local dbpassword="$2"
329        local mycnf=/tmp/.my.cnf.$$
330
331        echoAndLog "${FUNCNAME}(): checking MySQL configuration."
332        touch $mycnf
333        cat << EOT > $mycnf
334[client]
335user=$dbuser
336password=$dbpassword
337EOT
338        # Check if scheduler is active.
339        if [ "$(mysql --defaults-extra-file=$mycnf -Nse 'SELECT @@GLOBAL.event_scheduler;')" = "OFF" ]; then
340                MYSQLCONFIG="SET GLOBAL event_scheduler = ON; "
341        fi
342        rm -f $mycnf
343
344        echoAndLog "${FUNCNAME}(): MySQL configuration has checked"
345        return 0
346}
347
348#####################################################################
349####### Funciones de instalación de paquetes
350#####################################################################
351
352# Instalar las deependencias necesarias para el actualizador.
353function installDependencies()
354{
355        local package
356
357        if [ $# = 0 ]; then
358                echoAndLog "${FUNCNAME}(): no deps needed."
359        else
360                PHP5VERSION=$(apt-cache pkgnames php5 2>/dev/null | sort | head -1)
361                while [ $# -gt 0 ]; do
362                        package="${1/php5/$PHP5VERSION}"
363                        eval $CHECKPKG || INSTALLDEPS="$INSTALLDEPS $package"
364                        shift
365                done
366                if [ -n "$INSTALLDEPS" ]; then
367                        $UPDATEPKGLIST
368                        $INSTALLPKGS $INSTALLDEPS
369                        if [ $? -ne 0 ]; then
370                                errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
371                                return 1
372                        fi
373                fi
374        fi
375}
376
377
378#####################################################################
379####### Funciones para el manejo de Subversion
380#####################################################################
381
382function svnExportCode()
383{
384        if [ $# -ne 1 ]; then
385                errorAndLog "${FUNCNAME}(): invalid number of parameters"
386                exit 1
387        fi
388
389        local url="$1"
390
391        echoAndLog "${FUNCNAME}(): downloading subversion code..."
392
393        svn checkout "${url}" opengnsys
394        if [ $? -ne 0 ]; then
395                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
396                return 1
397        fi
398        echoAndLog "${FUNCNAME}(): subversion code downloaded"
399        return 0
400}
401
402
403############################################################
404###  Detectar red
405############################################################
406
407# Comprobar si existe conexión.
408function checkNetworkConnection()
409{
410        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"opengnsys.es"}
411        wget --spider -q $OPENGNSYS_SERVER
412}
413
414# Obtener los parámetros de red del servidor.
415function getNetworkSettings()
416{
417        # Variables globales definidas:
418        # - SERVERIP:   IP local de la interfaz por defecto.
419
420        local DEVICES
421        local dev
422
423        echoAndLog "${FUNCNAME}(): Detecting network parameters."
424        SERVERIP="$ServidorAdm"
425        DEVICES="$(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}')"
426        for dev in $DEVICES; do
427                [ -z "$SERVERIP" ] && SERVERIP=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
428        done
429}
430
431
432#####################################################################
433####### Funciones específicas de la instalación de Opengnsys
434#####################################################################
435
436# Actualizar cliente OpenGnsys.
437function updateClientFiles()
438{
439        local ENGINECFG=$INSTALL_TARGET/client/etc/engine.cfg
440
441        # Actualizar ficheros del cliente.
442        backupFile $ENGINECFG
443        echoAndLog "${FUNCNAME}(): Updating OpenGnsys Client files."
444        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
445        if [ $? -ne 0 ]; then
446                errorAndLog "${FUNCNAME}(): error while updating client structure"
447                exit 1
448        fi
449        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
450
451        # Actualizar librerías del motor de clonación.
452        echoAndLog "${FUNCNAME}(): Updating OpenGnsys Cloning Engine files."
453        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
454        if [ $? -ne 0 ]; then
455                errorAndLog "${FUNCNAME}(): error while updating engine files"
456                exit 1
457        fi
458        # Actualizar fichero de configuración del motor de clonación.
459        if ! grep -q "^TZ" $ENGINECFG; then
460                TZ=$(timedatectl status | awk -F"[:()]" '/Time.*zone/ {print $2}')
461                cat << EOT >> $ENGINECFG
462# OpenGnsys Server timezone.
463TZ="${TZ// /}"
464EOT
465        fi
466        if ! diff -q ${ENGINECFG}{,-LAST} &>/dev/null; then
467                NEWFILES="$NEWFILES $ENGINECFG"
468        else
469                rm -f ${ENGINECFG}-LAST
470        fi
471        # Obtener URL para descargas adicionales.
472        DOWNLOADURL=$(oglivecli config download-url 2>/dev/null)
473        DOWNLOADURL=${DOWNLOADURL:-"https://$OPENGNSYS_SERVER/trac/downloads"}
474
475        echoAndLog "${FUNCNAME}(): client files update success."
476}
477
478# Configurar HTTPS y exportar usuario y grupo del servicio Apache.
479function apacheConfiguration ()
480{
481        local config template
482
483        # Activar HTTPS (solo actualizando desde versiones anteriores a 1.0.2) y
484        #    activar módulo Rewrite (solo actualizaciones desde 1.0.x a 1.1.x).
485        if [ -e $APACHECFGDIR/sites-available/opengnsys.conf ]; then
486                echoAndLog "${FUNCNAME}(): Configuring Apache modules."
487                a2ensite default-ssl
488                a2enmod ssl
489                a2enmod rewrite
490                a2ensite opengnsys
491        elif [ -e $APACHECFGDIR/conf.modules.d ]; then
492                echoAndLog "${FUNCNAME}(): Configuring Apache modules."
493                sed -i '/rewrite/s/^#//' $APACHECFGDIR/*.conf
494        fi
495        # Actualizar configuración de Apache a partir de fichero de plantilla.
496        for config in $APACHECFGDIR/{,sites-available/}opengnsys.conf; do
497                # Elegir plantilla según versión de Apache.
498                if [ -n "$(apachectl -v | grep "2\.[0-2]")" ]; then
499                       template=$WORKDIR/opengnsys/server/etc/apache-prev2.4.conf.tmpl > $config
500                else
501                       template=$WORKDIR/opengnsys/server/etc/apache.conf.tmpl
502                fi
503                sed -e "s,CONSOLEDIR,$INSTALL_TARGET/www,g" $template > $config
504        done
505
506        # Reiniciar Apache.
507        $APACHESERV restart
508
509        # Variables de ejecución de Apache.
510        # - APACHE_RUN_USER
511        # - APACHE_RUN_GROUP
512        if [ -f $APACHECFGDIR/envvars ]; then
513                source $APACHECFGDIR/envvars
514        fi
515        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
516        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
517}
518
519# Configurar servicio Rsync.
520function rsyncConfigure()
521{
522        local service
523
524        # Configurar acceso a Rsync.
525        if [ ! -f /etc/rsyncd.conf ]; then
526                echoAndLog "${FUNCNAME}(): Configuring Rsync service."
527                NEWFILES="$NEWFILES /etc/rsyncd.conf"
528                sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENTUSER/g" \
529                    $WORKDIR/opengnsys/repoman/etc/rsyncd.conf.tmpl > /etc/rsyncd.conf
530                # Habilitar Rsync.
531                if [ -f /etc/default/rsync ]; then
532                        perl -pi -e 's/RSYNC_ENABLE=.*/RSYNC_ENABLE=inetd/' /etc/default/rsync
533                fi
534                if [ -f $INETDCFGDIR/rsync ]; then
535                        perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/rsync
536                else
537                        cat << EOT > $INETDCFGDIR/rsync
538service rsync
539{
540        disable = no
541        socket_type = stream
542        wait = no
543        user = root
544        server = $(which rsync)
545        server_args = --daemon
546        log_on_failure += USERID
547        flags = IPv6
548}
549EOT
550                fi
551                # Activar e iniciar Rsync.
552                service="rsync"  $ENABLESERVICE
553                service="xinetd"
554                $ENABLESERVICE; $STARTSERVICE
555        fi
556}
557
558# Copiar ficheros del OpenGnsys Web Console.
559function updateWebFiles()
560{
561        local ERRCODE COMPATDIR f
562
563        echoAndLog "${FUNCNAME}(): Updating web files..."
564
565        # Copiar los ficheros nuevos conservando el archivo de configuración de acceso.
566        backupFile $INSTALL_TARGET/www/controlacceso.php
567        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
568        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
569        ERRCODE=$?
570        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
571        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
572        unzip -o $WORKDIR/opengnsys/admin/slim-2.6.1.zip -d $INSTALL_TARGET/www/rest
573        unzip -o $WORKDIR/opengnsys/admin/swagger-ui-2.2.5.zip -d $INSTALL_TARGET/www/rest
574        if [ $ERRCODE != 0 ]; then
575                errorAndLog "${FUNCNAME}(): Error updating web files."
576                exit 1
577        fi
578        restoreFile $INSTALL_TARGET/www/controlacceso.php
579
580        # Cambiar acceso a protocolo HTTPS.
581        if grep -q "http://" $INSTALL_TARGET/www/controlacceso.php 2>/dev/null; then
582                echoAndLog "${FUNCNAME}(): updating web access file"
583                perl -pi -e 's!http://!https://!g' $INSTALL_TARGET/www/controlacceso.php
584                NEWFILES="$NEWFILES $INSTALL_TARGET/www/controlacceso.php"
585        fi
586
587        # Compatibilidad con dispositivos móviles.
588        COMPATDIR="$INSTALL_TARGET/www/principal"
589        for f in acciones administracion aula aulas hardwares imagenes menus repositorios softwares; do
590                sed 's/clickcontextualnodo/clicksupnodo/g' $COMPATDIR/$f.php > $COMPATDIR/$f.device.php
591        done
592        cp -a $COMPATDIR/imagenes.device.php $COMPATDIR/imagenes.device4.php
593
594        # Fichero de log de la API REST.
595        touch $INSTALL_TARGET/log/{ogagent,rest,remotepc}.log
596        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/{log/ogagent,rest,remotepc}.log
597
598        echoAndLog "${FUNCNAME}(): Web files updated successfully."
599}
600
601# Copiar ficheros en la zona de descargas de OpenGnsys Web Console.
602function updateDownloadableFiles()
603{
604        local FILENAME=ogagentpkgs-$INSTVERSION.tar.gz
605        local TARGETFILE=$WORKDIR/$FILENAME
606
607        # Descargar archivo comprimido, si es necesario.
608        if [ -s $PROGRAMDIR/$FILENAME ]; then
609                echoAndLog "${FUNCNAME}(): Moving $PROGRAMDIR/$FILENAME file to $(dirname $TARGETFILE)"
610                mv $PROGRAMDIR/$FILENAME $TARGETFILE
611        else
612                echoAndLog "${FUNCNAME}(): Downloading $FILENAME"
613                wget $DOWNLOADURL/$FILENAME -O $TARGETFILE
614        fi
615        if [ ! -s $TARGETFILE ]; then
616                errorAndLog "${FUNCNAME}(): Cannot download $FILENAME"
617                return 1
618        fi
619
620        # Descomprimir fichero en zona de descargas.
621        tar xvzf $TARGETFILE -C $INSTALL_TARGET/www/descargas
622        if [ $? != 0 ]; then
623                errorAndLog "${FUNCNAME}(): Error uncompressing archive."
624                exit 1
625        fi
626}
627
628# Copiar carpeta de Interface
629function updateInterfaceAdm()
630{
631        local errcode=0
632
633        # Crear carpeta y copiar Interface
634        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
635        mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface
636        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client
637        errcoce=$?
638        mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm
639        if [ $errcode -ne 0 ]; then
640                echoAndLog "${FUNCNAME}(): error while updating admin interface"
641                exit 1
642        fi
643        echoAndLog "${FUNCNAME}(): Admin interface updated successfully."
644}
645
646# Crear documentación Doxygen para la consola web.
647function makeDoxygenFiles()
648{
649        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
650        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
651                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
652        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
653                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
654                return 1
655        fi
656        rm -fr "$INSTALL_TARGET/www/api"
657        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
658        rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
659        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
660}
661
662
663# Crea la estructura base de la instalación de opengnsys
664function createDirs()
665{
666        # Crear estructura de directorios.
667        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
668        local dir
669
670        mkdir -p ${INSTALL_TARGET}/{bin,doc,etc,lib,sbin,www}
671        mkdir -p ${INSTALL_TARGET}/{client,images/group}
672        mkdir -p ${INSTALL_TARGET}/log/clients
673        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
674        # Detectar directorio de instalación de TFTP.
675        if [ ! -L ${INSTALL_TARGET}/tftpboot ]; then
676                for dir in /var/lib/tftpboot /srv/tftp; do
677                        [ -d $dir ] && ln -fs $dir ${INSTALL_TARGET}/tftpboot
678                done
679        fi
680        mkdir -p $INSTALL_TARGET/tftpboot/menu.lst/examples
681        if [ $? -ne 0 ]; then
682                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
683                return 1
684        fi
685        ! [ -f $INSTALL_TARGET/tftpboot/menu.lst/templates/00unknown ] && mv $INSTALL_TARGET/tftpboot/menu.lst/templates/* $INSTALL_TARGET/tftpboot/menu.lst/examples
686
687        # Crear usuario ficticio.
688        if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then
689                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created"
690        else
691                echoAndLog "${FUNCNAME}(): creating OpenGnsys user"
692                useradd $OPENGNSYS_CLIENTUSER 2>/dev/null
693                if [ $? -ne 0 ]; then
694                        errorAndLog "${FUNCNAME}(): error creating OpenGnsys user"
695                        return 1
696                fi
697        fi
698
699        # Mover el fichero de registro al directorio de logs.
700        echoAndLog "${FUNCNAME}(): moving update log file"
701        mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE
702        chmod 600 $LOG_FILE
703
704        echoAndLog "${FUNCNAME}(): directory paths created"
705        return 0
706}
707
708# Actualización incremental de la BD (versión actaul a actaul+1, hasta final-1 a final).
709function updateDatabase()
710{
711        local OLDVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
712        local NEWVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
713        local DBDIR="$WORKDIR/opengnsys/admin/Database"
714        local file FILES=""
715
716        echoAndLog "${FUNCNAME}(): looking for database updates"
717        pushd $DBDIR >/dev/null
718        # Bucle de actualización incremental desde versión actual a la final.
719        for file in $OPENGNSYS_DATABASE-*-*.sql; do
720                case "$file" in
721                        $OPENGNSYS_DATABASE-$OLDVERSION-$NEWVERSION.sql)
722                                # Actualización única de versión inicial y final.
723                                FILES="$FILES $file"
724                                break
725                                ;;
726                        $OPENGNSYS_DATABASE-*-postinst.sql)
727                                # Ignorar fichero específico de post-instalación.
728                                ;;
729                        $OPENGNSYS_DATABASE-$OLDVERSION-*.sql)
730                                # Actualización de versión n a n+1.
731                                FILES="$FILES $file"
732                                OLDVERSION="$(echo $file | cut -f3 -d-)"
733                                ;;
734                        $OPENGNSYS_DATABASE-*-$NEWVERSION.sql)
735                                # Última actualización de versión final-1 a final.
736                                if [ -n "$FILES" ]; then
737                                        FILES="$FILES $file"
738                                        break
739                                fi
740                                ;;
741                esac
742        done
743        # Aplicar posible actualización propia para la versión final.
744        file=$OPENGNSYS_DATABASE-$NEWVERSION.sql
745        if [ -n "$FILES" -o "$OLDVERSION" = "$NEWVERSION" -a -r $file ]; then
746                FILES="$FILES $file"
747        fi
748
749        popd >/dev/null
750        if [ -n "$FILES" ]; then
751                for file in $FILES; do
752                        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $DBDIR/$file
753                done
754                echoAndLog "${FUNCNAME}(): database is update"
755        else
756                echoAndLog "${FUNCNAME}(): database unchanged"
757        fi
758        INSTVERSION="$NEWVERSION"
759}
760
761# Copia ficheros de configuración y ejecutables genéricos del servidor.
762function updateServerFiles()
763{
764        # No copiar ficheros del antiguo cliente Initrd
765        local SOURCES=( repoman/bin \
766                        server/bin \
767                        server/lib \
768                        admin/Sources/Services/ogAdmServerAux \
769                        admin/Sources/Services/ogAdmRepoAux \
770                        server/tftpboot \
771                        installer/opengnsys_uninstall.sh \
772                        installer/opengnsys_export.sh \
773                        installer/opengnsys_import.sh \
774                        doc )
775        local TARGETS=( bin \
776                        bin \
777                        lib \
778                        sbin/ogAdmServerAux \
779                        sbin/ogAdmRepoAux \
780                        tftpboot \
781                        lib/opengnsys_uninstall.sh \
782                        lib/opengnsys_export.sh \
783                        lib/opengnsys_import.sh \
784                        doc )
785
786        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
787                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
788                exit 1
789        fi
790
791        echoAndLog "${FUNCNAME}(): updating files in server directories"
792        pushd $WORKDIR/opengnsys >/dev/null
793        local i
794        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
795                if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then
796                        rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}"))
797                else
798                        rsync -irplt "${SOURCES[i]}" $(readlink -m "$INSTALL_TARGET/${TARGETS[i]}")
799                fi
800        done
801        popd >/dev/null
802        NEWFILES=""             # Ficheros de configuración que han cambiado de formato.
803        if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then
804                echoAndLog "${FUNCNAME}(): updating DHCP files"
805                perl -pi -e 's/pxelinux.0/grldr/' /etc/dhcp*/dhcpd*.conf
806                $DHCPSERV restart
807                NEWFILES="/etc/dhcp*/dhcpd*.conf"
808        fi
809        if ! diff -q $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys 2>/dev/null; then
810                echoAndLog "${FUNCNAME}(): updating new init file"
811                backupFile /etc/init.d/opengnsys
812                cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
813                NEWFILES="$NEWFILES /etc/init.d/opengnsys"
814        fi
815        if egrep -q "(UrlMsg=.*msgbrowser.php)|(UrlMenu=http://)" $INSTALL_TARGET/client/etc/ogAdmClient.cfg 2>/dev/null; then
816                echoAndLog "${FUNCNAME}(): updating new client config file"
817                backupFile $INSTALL_TARGET/client/etc/ogAdmClient.cfg
818                perl -pi -e 's!UrlMsg=.*msgbrowser\.php!UrlMsg=http://localhost/cgi-bin/httpd-log\.sh!g; s!UrlMenu=http://!UrlMenu=https://!g' $INSTALL_TARGET/client/etc/ogAdmClient.cfg
819                NEWFILES="$NEWFILES $INSTALL_TARGET/client/etc/ogAdmClient.cfg"
820        fi
821
822        echoAndLog "${FUNCNAME}(): updating cron files"
823        [ ! -f /etc/cron.d/opengnsys ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys
824        [ ! -f /etc/cron.d/torrentcreator ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
825        [ ! -f /etc/cron.d/torrenttracker ] && echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
826        [ ! -f /etc/cron.d/imagedelete ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete
827        [ ! -f /etc/cron.d/ogagentqueue ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/ogagentqueue.cron ] && $INSTALL_TARGET/bin/ogagentqueue.cron" > /etc/cron.d/ogagentqueue
828        echoAndLog "${FUNCNAME}(): server files updated successfully."
829}
830
831####################################################################
832### Funciones de compilación de código fuente de servicios
833####################################################################
834
835# Mueve el fichero del nuevo servicio si es distinto al del directorio destino.
836function moveNewService()
837{
838        local service
839
840        # Recibe 2 parámetros: fichero origen y directorio destino.
841        [ $# == 2 ] || return 1
842        [ -f  $1 -a -d $2 ] || return 1
843
844        # Comparar los ficheros.
845        if ! diff -q $1 $2/$(basename $1) &>/dev/null; then
846                # Parar los servicios si fuese necesario.
847                [ -z "$NEWSERVICES" ] && service="opengnsys" $STOPSERVICE
848                # Nuevo servicio.
849                NEWSERVICES="$NEWSERVICES $(basename $1)"
850                # Mover el nuevo fichero de servicio
851                mv $1 $2
852        fi
853}
854
855
856# Recompilar y actualiza los serivicios y clientes.
857function compileServices()
858{
859        local hayErrores=0
860
861        # Compilar OpenGnsys Server
862        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Admin Server"
863        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
864        make && moveNewService ogAdmServer $INSTALL_TARGET/sbin
865        if [ $? -ne 0 ]; then
866                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Admin Server"
867                hayErrores=1
868        fi
869        popd
870        # Compilar OpenGnsys Repository Manager
871        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Repository Manager"
872        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
873        make && moveNewService ogAdmRepo $INSTALL_TARGET/sbin
874        if [ $? -ne 0 ]; then
875                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Repository Manager"
876                hayErrores=1
877        fi
878        popd
879        # Actualizar o insertar clave de acceso REST en el fichero de configuración del repositorio.
880        grep -q '^ApiToken=' $INSTALL_TARGET/etc/ogAdmRepo.cfg && \
881                sed -i "s/^ApiToken=.*$/ApiToken=$REPOKEY/" $INSTALL_TARGET/etc/ogAdmRepo.cfg || \
882                sed -i "$ a\ApiToken=$REPOKEY/" $INSTALL_TARGET/etc/ogAdmRepo.cfg
883        # Compilar OpenGnsys Agent
884        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Agent"
885        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
886        make && moveNewService ogAdmAgent $INSTALL_TARGET/sbin
887        if [ $? -ne 0 ]; then
888                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Agent"
889                hayErrores=1
890        fi
891        popd
892
893        # Compilar OpenGnsys Client
894        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Client"
895        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
896        make && mv ogAdmClient $INSTALL_TARGET/client/bin
897        if [ $? -ne 0 ]; then
898                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Client"
899                hayErrores=1
900        fi
901        popd
902
903        return $hayErrores
904}
905
906
907####################################################################
908### Funciones instalacion cliente OpenGnsys
909####################################################################
910
911# Actualizar cliente OpenGnsys
912function updateClient()
913{
914        #local FILENAME=ogLive-precise-3.2.0-23-generic-r5159.iso       # 1.1.0-rc6 (old)
915        local FILENAME=ogLive-xenial-4.8.0-39-generic-amd64-r5331.iso   # 1.1.0-rc6
916        local SOURCEFILE=$DOWNLOADURL/$FILENAME
917        local TARGETFILE=$(oglivecli config download-dir)/$FILENAME
918        local SOURCELENGTH
919        local TARGETLENGTH
920        local OGINITRD
921        local SAMBAPASS
922
923        # Comprobar si debe convertirse el antiguo cliente al nuevo formato ogLive.
924        if oglivecli check | grep -q "oglivecli convert"; then
925                echoAndLog "${FUNCNAME}(): Converting OpenGnsys Client to default ogLive"
926                oglivecli convert
927        fi
928        # Comprobar si debe actualizarse el cliente.
929        SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}')
930        TARGETLENGTH=$(stat -c "%s" $TARGETFILE 2>/dev/null)
931        [ -z $TARGETLENGTH ] && TARGETLENGTH=0
932        if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then
933                echoAndLog "${FUNCNAME}(): Downloading $FILENAME"
934                oglivecli download $FILENAME
935                if [ ! -s $TARGETFILE ]; then
936                        errorAndLog "${FUNCNAME}(): Error downloading $FILENAME"
937                        return 1
938                fi
939                # Actaulizar la imagen ISO del ogclient.
940                echoAndLog "${FUNCNAME}(): Updatting ogLive"
941                oglivecli install $FILENAME
942               
943                CLIENTUPDATED=${FILENAME%.*}
944
945                echoAndLog "${FUNCNAME}(): ogLive update successfully"
946        else
947                # Si no existe, crear el fichero de claves de Rsync.
948                if [ ! -f /etc/rsyncd.secrets ]; then
949                        echoAndLog "${FUNCNAME}(): Restoring ogLive access key"
950                        OGINITRD=$(oglivecli config install-dir)/$(jq -r ".oglive[.default].directory")/oginitrd.img
951                        SAMBAPASS=$(gzip -dc $OGINITRD | \
952                                    cpio -i --to-stdout scripts/ogfunctions 2>&1 | \
953                                    grep "^[    ].*OPTIONS=" | \
954                                    sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')
955                        echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | setsmbpass
956                else
957                        echoAndLog "${FUNCNAME}(): ogLive is already updated"
958                fi
959                # Versión del ogLive instalado.
960                echo "${FILENAME%.*}" > $INSTALL_TARGET/doc/veroglive.txt
961        fi
962}
963
964# Comprobar permisos y ficheros.
965function checkFiles()
966{
967        # Comprobar permisos adecuados.
968        if [ -x $INSTALL_TARGET/bin/checkperms ]; then
969                echoAndLog "${FUNCNAME}(): Checking permissions."
970                OPENGNSYS_DIR="$INSTALL_TARGET" OPENGNSYS_USER="$OPENGNSYS_CLIENTUSER" APACHE_USER="$APACHE_RUN_USER" APACHE_GROUP="$APACHE_RUN_GROUP" $INSTALL_TARGET/bin/checkperms
971        fi
972
973        # Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
974        if [ -f /tmp/dstate ]; then
975                echoAndLog "${FUNCNAME}(): Delete unused files."
976                rm -f /tmp/dstate
977        fi
978}
979
980# Resumen de actualización.
981function updateSummary()
982{
983        # Actualizar fichero de versión y revisión.
984        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
985        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}')
986
987        [ -f $VERSIONFILE ] || echo "OpenGnsys" >$VERSIONFILE
988        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
989
990        echo
991        echoAndLog "OpenGnsys Update Summary"
992        echo       "========================"
993        echoAndLog "Project version:                  $(cat $VERSIONFILE)"
994        echoAndLog "Update log file:                  $LOG_FILE"
995        if [ -n "$NEWFILES" ]; then
996                echoAndLog "Check new config files:           $(echo $NEWFILES)"
997        fi
998        if [ -n "$NEWSERVICES" ]; then
999                echoAndLog "New compiled services:            $(echo $NEWSERVICES)"
1000                # Indicar si se debe reiniciar servicios manualmente o usando el Cron.
1001                [ -f /etc/default/opengnsys ] && source /etc/default/opengnsys
1002                if [ "$RUN_CRONJOB" == "no" ]; then
1003                        echoAndLog "        WARNING: you must restart OpenGnsys services manually."
1004                else
1005                        echoAndLog "        New OpenGnsys services will be restarted by the cronjob."
1006                fi
1007        fi
1008        echoAndLog "Warnings:"
1009        echoAndLog " - You must to clear web browser cache before loading OpenGnsys page."
1010        echoAndLog " - Generated new key to access Repository REST API (file ogAdmRepo.cfg)."
1011        if [ -n "$CLIENTUPDATED" ]; then
1012                echoAndLog " - ogLive Client is updated to: $CLIENTUPDATED"
1013        fi
1014        if [ -n "$MYSQLCONFIG" ]; then
1015                echoAndLog " - MySQL must be reconfigured: execute next code as DB root user and restart service:"
1016                echoAndLog "      $MYSQLCONFIG"
1017        fi
1018        echo
1019}
1020
1021
1022
1023#####################################################################
1024####### Proceso de actualización de OpenGnsys
1025#####################################################################
1026
1027
1028echoAndLog "OpenGnsys update begins at $(date)"
1029
1030pushd $WORKDIR
1031
1032# Comprobar si hay conexión y detectar parámetros de red por defecto.
1033checkNetworkConnection
1034if [ $? -ne 0 ]; then
1035        errorAndLog "Error connecting to server. Causes:"
1036        errorAndLog " - Network is unreachable, review devices parameters."
1037        errorAndLog " - You are inside a private network, configure the proxy service."
1038        errorAndLog " - Server is temporally down, try agian later."
1039        exit 1
1040fi
1041getNetworkSettings
1042
1043# Comprobar auto-actualización del programa.
1044if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
1045        checkAutoUpdate
1046        if [ $? -ne 0 ]; then
1047                echoAndLog "OpenGnsys updater has been overwritten."
1048                echoAndLog "Please, re-execute this script."
1049                exit
1050        fi
1051fi
1052
1053# Detectar datos de auto-configuración del instalador.
1054autoConfigure
1055
1056# Instalar dependencias.
1057installDependencies ${DEPENDENCIES[*]}
1058if [ $? -ne 0 ]; then
1059        errorAndLog "Error: you may install all needed dependencies."
1060        exit 1
1061fi
1062
1063# Arbol de directorios de OpenGnsys.
1064createDirs ${INSTALL_TARGET}
1065if [ $? -ne 0 ]; then
1066        errorAndLog "Error while creating directory paths!"
1067        exit 1
1068fi
1069
1070# Si es necesario, descarga el repositorio de código en directorio temporal
1071if [ $USESVN -eq 1 ]; then
1072        svnExportCode $SVN_URL
1073        if [ $? -ne 0 ]; then
1074                errorAndLog "Error while getting code from svn"
1075                exit 1
1076        fi
1077else
1078        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
1079fi
1080
1081# Comprobar configuración de MySQL.
1082checkMysqlConfig $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD
1083
1084# Actualizar la BD.
1085updateDatabase
1086
1087# Actualizar ficheros complementarios del servidor
1088updateServerFiles
1089if [ $? -ne 0 ]; then
1090        errorAndLog "Error updating OpenGnsys Server files"
1091        exit 1
1092fi
1093
1094# Configurar Rsync.
1095rsyncConfigure
1096
1097# Actualizar ficheros del cliente
1098updateClientFiles
1099updateInterfaceAdm
1100
1101# Actualizar páqinas web
1102apacheConfiguration
1103updateWebFiles
1104if [ $? -ne 0 ]; then
1105        errorAndLog "Error updating OpenGnsys Web Admin files"
1106        exit 1
1107fi
1108# Actaulizar ficheros descargables.
1109updateDownloadableFiles
1110# Generar páginas Doxygen para instalar en el web
1111makeDoxygenFiles
1112
1113# Recompilar y actualizar los servicios del sistema
1114compileServices
1115
1116# Actaulizar ficheros auxiliares del cliente
1117updateClient
1118if [ $? -ne 0 ]; then
1119        errorAndLog "Error updating clients"
1120        exit 1
1121fi
1122
1123# Comprobar permisos y ficheros.
1124checkFiles
1125
1126# Mostrar resumen de actualización.
1127updateSummary
1128
1129#rm -rf $WORKDIR
1130echoAndLog "OpenGnsys update finished at $(date)"
1131
1132popd
1133
Note: See TracBrowser for help on using the repository browser.