source: installer/opengnsys_update.sh @ b584da5

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 b584da5 was e00bb53, checked in by ramon <ramongomez@…>, 9 years ago

#708: Mover la generación de la clave REST a la función de modificación de la BD del script de actualización.

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

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