source: installer/opengnsys_update.sh @ 27c67d9

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 27c67d9 was 663cd905, checked in by ramon <ramongomez@…>, 8 years ago

#730: Actaulizador no cambiar permisos, usa script checkperms.

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

  • Property mode set to 100755
File size: 34.2 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)
[3554392]115                DEPENDENCIES=( php5-ldap xinetd rsync btrfs-tools procps arp-scan realpath php5-curl gettext moreutils jq )
[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)
[3554392]132                DEPENDENCIES=( php-ldap xinetd rsync btrfs-progs procps-ng arp-scan gettext moreutils jq )
[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
[6f4d39b]154        [ -d /etc/$i ] && APACHECFGDIR="/etc/$i"
[2e38f60]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));')
[f9b5714]286        REPOKEY=$(php -r 'echo md5(uniqid(rand(), true));')
[295b4ab]287
288        if [ ! -r $sqlfile ]; then
289                errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!"
290                return 1
291        fi
292
293        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
294        chmod 600 $tmpfile
295        sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
[e00bb53]296            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
[8e0f770]297            -e "s/APIKEY/$APIKEY/g" -e "s/REPOKEY/$REPOKEY/g" $sqlfile > $tmpfile
[632bd45]298        # Componer fichero con credenciales de conexión. 
299        touch $mycnf
300        chmod 600 $mycnf
301        cat << EOT > $mycnf
[c073224]302[client]
[09bf701]303user=$dbuser
304password=$dbpassword
[632bd45]305EOT
306        # Ejecutar actualización y borrar fichero de credenciales.
[09bf701]307        mysql --defaults-extra-file=$mycnf --default-character-set=utf8 -D "$database" < $tmpfile
[295b4ab]308        status=$?
[632bd45]309        rm -f $mycnf $tmpfile
[295b4ab]310        if [ $status -ne 0 ]; then
311                errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database"
312                return 1
313        fi
314        echoAndLog "${FUNCNAME}(): file imported to database $database"
315        return 0
316}
317
318
319#####################################################################
[a0867b37]320####### Funciones de instalación de paquetes
321#####################################################################
322
323# Instalar las deependencias necesarias para el actualizador.
[64dd765]324function installDependencies()
[a0867b37]325{
[db9e706]326        local package
327
[a0867b37]328        if [ $# = 0 ]; then
329                echoAndLog "${FUNCNAME}(): no deps needed."
[c1e00e4]330        else
[b6fd406]331                PHP5VERSION=$(apt-cache pkgnames php5 2>/dev/null | sort | head -1)
[c1e00e4]332                while [ $# -gt 0 ]; do
[b6fd406]333                        package="${1/php5/$PHP5VERSION}"
334                        eval $CHECKPKG || INSTALLDEPS="$INSTALLDEPS $package"
[c1e00e4]335                        shift
336                done
337                if [ -n "$INSTALLDEPS" ]; then
[db9e706]338                        $UPDATEPKGLIST
339                        $INSTALLPKGS $INSTALLDEPS
[c1e00e4]340                        if [ $? -ne 0 ]; then
341                                errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
342                                return 1
343                        fi
344                fi
345        fi
[a0867b37]346}
347
348
349#####################################################################
350####### Funciones para el manejo de Subversion
351#####################################################################
352
353function svnExportCode()
354{
355        if [ $# -ne 1 ]; then
356                errorAndLog "${FUNCNAME}(): invalid number of parameters"
357                exit 1
358        fi
359
[27dc5ff]360        local url="$1"
[a0867b37]361
362        echoAndLog "${FUNCNAME}(): downloading subversion code..."
363
[7ad4465]364        svn checkout "${url}" opengnsys
[a0867b37]365        if [ $? -ne 0 ]; then
366                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
367                return 1
368        fi
369        echoAndLog "${FUNCNAME}(): subversion code downloaded"
370        return 0
371}
372
373
374############################################################
375###  Detectar red
376############################################################
377
[07c3a59]378# Comprobar si existe conexión.
379function checkNetworkConnection()
380{
381        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"}
382        wget --spider -q $OPENGNSYS_SERVER
383}
384
[739fb00]385# Obtener los parámetros de red del servidor.
386function getNetworkSettings()
387{
388        # Variables globales definidas:
389        # - SERVERIP:   IP local de la interfaz por defecto.
390
391        local DEVICES
392        local dev
393
394        echoAndLog "${FUNCNAME}(): Detecting network parameters."
[90b507d]395        SERVERIP="$ServidorAdm"
[739fb00]396        DEVICES="$(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}')"
397        for dev in $DEVICES; do
398                [ -z "$SERVERIP" ] && SERVERIP=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
399        done
400}
401
[a0867b37]402
403#####################################################################
404####### Funciones específicas de la instalación de Opengnsys
405#####################################################################
406
[5f21d34]407# Actualizar cliente OpenGnsys.
[295b4ab]408function updateClientFiles()
[45f1fe8]409{
[74cd321]410        local ENGINECFG=$INSTALL_TARGET/client/etc/engine.cfg
411
[a43e90d]412        # Actualizar ficheros del cliente.
[74cd321]413        backupFile $ENGINECFG
[5f21d34]414        echoAndLog "${FUNCNAME}(): Updating OpenGnsys Client files."
[45f1fe8]415        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
416        if [ $? -ne 0 ]; then
417                errorAndLog "${FUNCNAME}(): error while updating client structure"
[51b179a]418                exit 1
[45f1fe8]419        fi
420        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
[a43e90d]421
422        # Actualizar librerías del motor de clonación.
[5f21d34]423        echoAndLog "${FUNCNAME}(): Updating OpenGnsys Cloning Engine files."
[51b179a]424        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
[45f1fe8]425        if [ $? -ne 0 ]; then
426                errorAndLog "${FUNCNAME}(): error while updating engine files"
[51b179a]427                exit 1
[45f1fe8]428        fi
[a3855dc]429        # Actualizar fichero de configuración del motor de clonación.
[c40710e]430        if ! grep -q "^TZ" $ENGINECFG; then
[a3855dc]431                TZ=$(timedatectl status | awk -F"[:()]" '/Time.*zone/ {print $2}')
[c40710e]432                cat << EOT >> $ENGINECFG
[a3855dc]433# OpenGnsys Server timezone.
434TZ="${TZ// /}"
435EOT
436        fi
[8fc7ce1]437        if ! diff -q ${ENGINECFG}{,-LAST} &>/dev/null; then
[c40710e]438                NEWFILES="$NEWFILES $ENGINECFG"
439        else
440                rm -f ${ENGINECFG}-LAST
441        fi
[a3855dc]442
[51b179a]443        echoAndLog "${FUNCNAME}(): client files update success."
[45f1fe8]444}
[4e51cb0]445
[3ce53a7]446# Configurar HTTPS y exportar usuario y grupo del servicio Apache.
447function apacheConfiguration ()
[4e51cb0]448{
[6f4d39b]449        local config template
450
[900be258]451        # Activar HTTPS (solo actualizando desde versiones anteriores a 1.0.2) y
452        #    activar módulo Rewrite (solo actualizaciones desde 1.0.x a 1.1.x).
[2e38f60]453        if [ -e $APACHECFGDIR/sites-available/opengnsys.conf ]; then
[5f21d34]454                echoAndLog "${FUNCNAME}(): Configuring Apache modules."
[3ce53a7]455                a2ensite default-ssl
456                a2enmod ssl
[900be258]457                a2enmod rewrite
[3ce53a7]458                a2ensite opengnsys
[5f21d34]459        elif [ -e $APACHECFGDIR/conf.modules.d ]; then
460                echoAndLog "${FUNCNAME}(): Configuring Apache modules."
461                sed -i '/rewrite/s/^#//' $APACHECFGDIR/*.conf
[3ce53a7]462        fi
[6f4d39b]463        # Actualizar configuración de Apache a partir de fichero de plantilla.
464        for config in $APACHECFGDIR/{,sites-available/}opengnsys.conf; do
465                # Elegir plantilla según versión de Apache.
466                if [ -n "$(apachectl -v | grep "2\.[0-2]")" ]; then
467                       template=$WORKDIR/opengnsys/server/etc/apache-prev2.4.conf.tmpl > $config
468                else
469                       template=$WORKDIR/opengnsys/server/etc/apache.conf.tmpl
[900be258]470                fi
[6f4d39b]471                sed -e "s,CONSOLEDIR,$INSTALL_TARGET/www,g" $template > $config
[900be258]472        done
473
474        # Reiniciar Apache.
475        $APACHESERV restart
476
[3ce53a7]477        # Variables de ejecución de Apache.
[4e51cb0]478        # - APACHE_RUN_USER
479        # - APACHE_RUN_GROUP
[2e38f60]480        if [ -f $APACHECFGDIR/envvars ]; then
481                source $APACHECFGDIR/envvars
[4e51cb0]482        fi
[2e38f60]483        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
[de8bbb1]484        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
[4e51cb0]485}
486
[4b96166]487# Configurar servicio Rsync.
488function rsyncConfigure()
489{
490        local service
491
492        # Configurar acceso a Rsync.
493        if [ ! -f /etc/rsyncd.conf ]; then
494                echoAndLog "${FUNCNAME}(): Configuring Rsync service."
[65baf16]495                NEWFILES="$NEWFILES /etc/rsyncd.conf"
[4b96166]496                sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENTUSER/g" \
497                    $WORKDIR/opengnsys/repoman/etc/rsyncd.conf.tmpl > /etc/rsyncd.conf
498                # Habilitar Rsync.
499                if [ -f /etc/default/rsync ]; then
500                        perl -pi -e 's/RSYNC_ENABLE=.*/RSYNC_ENABLE=inetd/' /etc/default/rsync
501                fi
502                if [ -f $INETDCFGDIR/rsync ]; then
503                        perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/rsync
504                else
505                        cat << EOT > $INETDCFGDIR/rsync
506service rsync
507{
508        disable = no
509        socket_type = stream
510        wait = no
511        user = root
512        server = $(which rsync)
513        server_args = --daemon
514        log_on_failure += USERID
515        flags = IPv6
516}
517EOT
518                fi
519                # Activar e iniciar Rsync.
520                service="rsync"  $ENABLESERVICE
[ab7f563]521                service="xinetd"
522                $ENABLESERVICE; $STARTSERVICE
[4b96166]523        fi
524}
525
[5f21d34]526# Copiar ficheros del OpenGnsys Web Console.
[a0867b37]527function updateWebFiles()
528{
[2b793a8]529        local ERRCODE COMPATDIR f
530
[a0867b37]531        echoAndLog "${FUNCNAME}(): Updating web files..."
[2b793a8]532
533        # Copiar los ficheros nuevos conservando el archivo de configuración de acceso.
534        backupFile $INSTALL_TARGET/www/controlacceso.php
535        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
[1db2ed8]536        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
[2b793a8]537        ERRCODE=$?
538        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
[c1e00e4]539        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
[900be258]540        unzip -o $WORKDIR/opengnsys/admin/slim-2.6.1.zip -d $INSTALL_TARGET/www/rest
[8b8e948]541        unzip -o $WORKDIR/opengnsys/admin/swagger-ui-2.2.5.zip -d $INSTALL_TARGET/www/rest
[d655cc4]542        if [ $ERRCODE != 0 ]; then
[a0867b37]543                errorAndLog "${FUNCNAME}(): Error updating web files."
544                exit 1
545        fi
[2b793a8]546        restoreFile $INSTALL_TARGET/www/controlacceso.php
547
[1a2fa9d8]548        # Cambiar acceso a protocolo HTTPS.
549        if grep -q "http://" $INSTALL_TARGET/www/controlacceso.php 2>/dev/null; then
550                echoAndLog "${FUNCNAME}(): updating web access file"
551                perl -pi -e 's!http://!https://!g' $INSTALL_TARGET/www/controlacceso.php
552                NEWFILES="$NEWFILES $INSTALL_TARGET/www/controlacceso.php"
553        fi
554
[2b793a8]555        # Compatibilidad con dispositivos móviles.
556        COMPATDIR="$INSTALL_TARGET/www/principal"
557        for f in acciones administracion aula aulas hardwares imagenes menus repositorios softwares; do
558                sed 's/clickcontextualnodo/clicksupnodo/g' $COMPATDIR/$f.php > $COMPATDIR/$f.device.php
559        done
[d70a45f]560        cp -a $COMPATDIR/imagenes.device.php $COMPATDIR/imagenes.device4.php
[2b793a8]561
[aad50e2]562        # Fichero de logs del agente OGAgent.
[b1735a7]563        touch $INSTALL_TARGET/log/ogagent.log
564        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/log/ogagent.log
[2b793a8]565
[a0867b37]566        echoAndLog "${FUNCNAME}(): Web files updated successfully."
567}
568
[72134d5]569# Copiar carpeta de Interface
[64dd765]570function updateInterfaceAdm()
[72134d5]571{
[27dc5ff]572        local errcode=0
[2b793a8]573
[72134d5]574        # Crear carpeta y copiar Interface
575        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
576        mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface
577        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client
[27dc5ff]578        errcoce=$?
[72134d5]579        mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm
[27dc5ff]580        if [ $errcode -ne 0 ]; then
[72134d5]581                echoAndLog "${FUNCNAME}(): error while updating admin interface"
582                exit 1
583        fi
584        echoAndLog "${FUNCNAME}(): Admin interface updated successfully."
585}
[a0867b37]586
[5d6bf97]587# Crear documentación Doxygen para la consola web.
588function makeDoxygenFiles()
589{
590        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
591        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
592                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
593        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
594                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
595                return 1
596        fi
[45f1fe8]597        rm -fr "$INSTALL_TARGET/www/api"
[15b2a4e]598        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
599        rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
[5d6bf97]600        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
601}
602
603
[a0867b37]604# Crea la estructura base de la instalación de opengnsys
605function createDirs()
606{
[eb9424f]607        # Crear estructura de directorios.
[a0867b37]608        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
[7bb72f7]609        local dir
610
[cfad47b]611        mkdir -p ${INSTALL_TARGET}/{bin,doc,etc,lib,sbin,www}
[6f4d39b]612        mkdir -p ${INSTALL_TARGET}/{client,images/group}
[a0867b37]613        mkdir -p ${INSTALL_TARGET}/log/clients
[eb9424f]614        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
[7bb72f7]615        # Detectar directorio de instalación de TFTP.
616        if [ ! -L ${INSTALL_TARGET}/tftpboot ]; then
617                for dir in /var/lib/tftpboot /srv/tftp; do
618                        [ -d $dir ] && ln -fs $dir ${INSTALL_TARGET}/tftpboot
619                done
620        fi
[663cd905]621        mkdir -p $INSTALL_TARGET/tftpboot/menu.lst/examples
[a0867b37]622        if [ $? -ne 0 ]; then
623                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
624                return 1
625        fi
[663cd905]626        ! [ -f $INSTALL_TARGET/tftpboot/menu.lst/templates/00unknown ] && mv $INSTALL_TARGET/tftpboot/menu.lst/templates/* $INSTALL_TARGET/tftpboot/menu.lst/examples
[a0867b37]627
[eb9424f]628        # Crear usuario ficticio.
629        if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then
630                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created"
631        else
[5f21d34]632                echoAndLog "${FUNCNAME}(): creating OpenGnsys user"
[eb9424f]633                useradd $OPENGNSYS_CLIENTUSER 2>/dev/null
634                if [ $? -ne 0 ]; then
[5f21d34]635                        errorAndLog "${FUNCNAME}(): error creating OpenGnsys user"
[eb9424f]636                        return 1
637                fi
638        fi
639
[57f7e9c]640        # Mover el fichero de registro al directorio de logs.
641        echoAndLog "${FUNCNAME}(): moving update log file"
642        mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE
[7669bca]643        chmod 600 $LOG_FILE
[57f7e9c]644
[a0867b37]645        echoAndLog "${FUNCNAME}(): directory paths created"
646        return 0
647}
648
[566e84f]649# Actualización incremental de la BD (versión actaul a actaul+1, hasta final-1 a final).
650function updateDatabase()
651{
652        local OLDVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
653        local NEWVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
654        local DBDIR="$WORKDIR/opengnsys/admin/Database"
655        local file FILES=""
656
657        echoAndLog "${FUNCNAME}(): looking for database updates"
658        pushd $DBDIR >/dev/null
659        # Bucle de actualización incremental desde versión actual a la final.
660        for file in $OPENGNSYS_DATABASE-*-*.sql; do
661                case "$file" in
662                        $OPENGNSYS_DATABASE-$OLDVERSION-$NEWVERSION.sql)
663                                # Actualización única de versión inicial y final.
664                                FILES="$FILES $file"
665                                break
666                                ;;
667                        $OPENGNSYS_DATABASE-*-postinst.sql)
668                                # Ignorar fichero específico de post-instalación.
669                                ;;
670                        $OPENGNSYS_DATABASE-$OLDVERSION-*.sql)
671                                # Actualización de versión n a n+1.
672                                FILES="$FILES $file"
673                                OLDVERSION="$(echo $file | cut -f3 -d-)"
674                                ;;
675                        $OPENGNSYS_DATABASE-*-$NEWVERSION.sql)
676                                # Última actualización de versión final-1 a final.
677                                if [ -n "$FILES" ]; then
678                                        FILES="$FILES $file"
679                                        break
680                                fi
681                                ;;
682                esac
683        done
684        # Aplicar posible actualización propia para la versión final.
685        file=$OPENGNSYS_DATABASE-$NEWVERSION.sql
686        if [ -n "$FILES" -o "$OLDVERSION" = "$NEWVERSION" -a -r $file ]; then
687                FILES="$FILES $file"
688        fi
689
690        popd >/dev/null
691        if [ -n "$FILES" ]; then
692                for file in $FILES; do
[0cfe47a]693                        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $DBDIR/$file
[566e84f]694                done
695                echoAndLog "${FUNCNAME}(): database is update"
696        else
697                echoAndLog "${FUNCNAME}(): database unchanged"
698        fi
699}
700
[a0867b37]701# Copia ficheros de configuración y ejecutables genéricos del servidor.
[64dd765]702function updateServerFiles()
[bb30a50]703{
[c1e00e4]704        # No copiar ficheros del antiguo cliente Initrd
[873cf1e]705        local SOURCES=( repoman/bin \
[c1e00e4]706                        server/bin \
[3e7d77b]707                        server/lib \
[42a0e41]708                        admin/Sources/Services/ogAdmServerAux \
709                        admin/Sources/Services/ogAdmRepoAux \
[873cf1e]710                        server/tftpboot \
[bb30a50]711                        installer/opengnsys_uninstall.sh \
[6777e3e]712                        installer/opengnsys_export.sh \
713                        installer/opengnsys_import.sh \
[873cf1e]714                        doc )
715        local TARGETS=( bin \
716                        bin \
[3e7d77b]717                        lib \
[cdad332]718                        sbin/ogAdmServerAux \
719                        sbin/ogAdmRepoAux \
[873cf1e]720                        tftpboot \
[9a2c0f9d]721                        lib/opengnsys_uninstall.sh \
[6777e3e]722                        lib/opengnsys_export.sh \
723                        lib/opengnsys_import.sh \
[873cf1e]724                        doc )
[a0867b37]725
726        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
727                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
728                exit 1
729        fi
730
731        echoAndLog "${FUNCNAME}(): updating files in server directories"
732        pushd $WORKDIR/opengnsys >/dev/null
733        local i
734        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
[27dc5ff]735                if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then
[4057c5d]736                        rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}"))
[aa36857]737                else
[56f100f]738                        rsync -irplt "${SOURCES[i]}" $(readlink -m "$INSTALL_TARGET/${TARGETS[i]}")
[aa36857]739                fi
[a0867b37]740        done
741        popd >/dev/null
[df3cd7f]742        NEWFILES=""             # Ficheros de configuración que han cambiado de formato.
[f80f839]743        if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then
[df3cd7f]744                echoAndLog "${FUNCNAME}(): updating DHCP files"
[f80f839]745                perl -pi -e 's/pxelinux.0/grldr/' /etc/dhcp*/dhcpd*.conf
[2e38f60]746                $DHCPSERV restart
[df3cd7f]747                NEWFILES="/etc/dhcp*/dhcpd*.conf"
748        fi
[d372e6e]749        if ! diff -q $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys 2>/dev/null; then
[df3cd7f]750                echoAndLog "${FUNCNAME}(): updating new init file"
751                backupFile /etc/init.d/opengnsys
752                cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
753                NEWFILES="$NEWFILES /etc/init.d/opengnsys"
754        fi
[1a2fa9d8]755        if egrep -q "(UrlMsg=.*msgbrowser.php)|(UrlMenu=http://)" $INSTALL_TARGET/client/etc/ogAdmClient.cfg 2>/dev/null; then
[df3cd7f]756                echoAndLog "${FUNCNAME}(): updating new client config file"
757                backupFile $INSTALL_TARGET/client/etc/ogAdmClient.cfg
[1a2fa9d8]758                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]759                NEWFILES="$NEWFILES $INSTALL_TARGET/client/etc/ogAdmClient.cfg"
[f80f839]760        fi
[a3855dc]761
[9ee62ad]762        echoAndLog "${FUNCNAME}(): updating cron files"
[db9e706]763        [ ! -f /etc/cron.d/opengnsys ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys
764        [ ! -f /etc/cron.d/torrentcreator ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
765        [ ! -f /etc/cron.d/torrenttracker ] && echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
[dc762088]766        [ ! -f /etc/cron.d/imagedelete ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete
[da8db11]767        echoAndLog "${FUNCNAME}(): server files updated successfully."
[a0867b37]768}
769
770####################################################################
771### Funciones de compilación de código fuente de servicios
772####################################################################
773
[dde65c7]774# Mueve el fichero del nuevo servicio si es distinto al del directorio destino.
775function moveNewService()
776{
777        local service
778
779        # Recibe 2 parámetros: fichero origen y directorio destino.
780        [ $# == 2 ] || return 1
[ddcb0cf]781        [ -f  $1 -a -d $2 ] || return 1
[dde65c7]782
783        # Comparar los ficheros.
[ddcb0cf]784        if ! diff -q $1 $2/$(basename $1) &>/dev/null; then
[dde65c7]785                # Parar los servicios si fuese necesario.
786                [ -z "$NEWSERVICES" ] && service="opengnsys" $STOPSERVICE
787                # Nuevo servicio.
788                NEWSERVICES="$NEWSERVICES $(basename $1)"
789                # Mover el nuevo fichero de servicio
790                mv $1 $2
791        fi
792}
793
794
[bb30a50]795# Recompilar y actualiza los serivicios y clientes.
[64dd765]796function compileServices()
[a0867b37]797{
[bb30a50]798        local hayErrores=0
799
[5f21d34]800        # Compilar OpenGnsys Server
801        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Admin Server"
[bb30a50]802        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
[dde65c7]803        make && moveNewService ogAdmServer $INSTALL_TARGET/sbin
[bb30a50]804        if [ $? -ne 0 ]; then
[5f21d34]805                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Admin Server"
[bb30a50]806                hayErrores=1
807        fi
808        popd
[5f21d34]809        # Compilar OpenGnsys Repository Manager
810        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Repository Manager"
[bb30a50]811        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
[dde65c7]812        make && moveNewService ogAdmRepo $INSTALL_TARGET/sbin
[bb30a50]813        if [ $? -ne 0 ]; then
[5f21d34]814                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Repository Manager"
[bb30a50]815                hayErrores=1
816        fi
817        popd
[f9b5714]818        # Actualizar o insertar clave de acceso REST en el fichero de configuración del repositorio.
[f6284d2]819        grep -q '^ApiToken=' $INSTALL_TARGET/etc/ogAdmRepo.cfg && \
820                sed -i "s/^ApiToken=.*$/ApiToken=$REPOKEY/" $INSTALL_TARGET/etc/ogAdmRepo.cfg || \
821                sed -i "$ a\ApiToken=$REPOKEY/" $INSTALL_TARGET/etc/ogAdmRepo.cfg
[5f21d34]822        # Compilar OpenGnsys Agent
823        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Agent"
[bb30a50]824        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
[dde65c7]825        make && moveNewService ogAdmAgent $INSTALL_TARGET/sbin
[bb30a50]826        if [ $? -ne 0 ]; then
[5f21d34]827                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Agent"
[bb30a50]828                hayErrores=1
829        fi
830        popd
831
[5f21d34]832        # Compilar OpenGnsys Client
833        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Client"
[72134d5]834        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[e473667]835        make && mv ogAdmClient $INSTALL_TARGET/client/bin
[a0867b37]836        if [ $? -ne 0 ]; then
[5f21d34]837                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Client"
[a0867b37]838                hayErrores=1
839        fi
840        popd
841
842        return $hayErrores
843}
844
845
846####################################################################
[5f21d34]847### Funciones instalacion cliente OpenGnsys
[a0867b37]848####################################################################
849
[5f21d34]850# Actualizar cliente OpenGnsys
[c1e00e4]851function updateClient()
852{
[0496417]853        PATH=$PATH:$INSTALL_TARGET/bin
854        local DOWNLOADURL=$(oglivecli config download-url)
[79c119c]855        #local FILENAME=ogLive-wily-4.2.0-35-generic-r4919.iso          # 1.1.0-rc3
856        local FILENAME=ogLive-xenial-4.4.0-34-generic-r4999.iso         # 1.1.0-rc4
[0b85cc93]857        local SOURCEFILE=$DOWNLOADURL/$FILENAME
[0496417]858        local TARGETFILE=$(oglivecli config download-dir)/$FILENAME
[0b85cc93]859        local SOURCELENGTH
860        local TARGETLENGTH
[0496417]861        local OGINITRD
[a63345ac]862        local SAMBAPASS
[ee4beb4]863        local KERNELVERSION
[0b85cc93]864
[0496417]865        # Comprobar si debe convertirse el antiguo cliente al nuevo formato ogLive.
866        if oglivecli check | grep -q "oglivecli convert"; then
867                echoAndLog "${FUNCNAME}(): Converting OpenGnsys Client to default ogLive"
868                oglivecli convert
869        fi
[0b85cc93]870        # Comprobar si debe actualizarse el cliente.
[c3cc6b0]871        SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}')
[0496417]872        TARGETLENGTH=$(stat -c "%s" $TARGETFILE 2>/dev/null)
[d4e90c1]873        [ -z $TARGETLENGTH ] && TARGETLENGTH=0
[0b85cc93]874        if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then
[0496417]875                echoAndLog "${FUNCNAME}(): Downloading ogLive"
876                oglivecli download $FILENAME
[0b85cc93]877                if [ ! -s $TARGETFILE ]; then
[5f21d34]878                        errorAndLog "${FUNCNAME}(): Error loading OpenGnsys Client"
[0b85cc93]879                        return 1
880                fi
[1893b9d]881                # Actaulizar la imagen ISO del ogclient.
[0496417]882                echoAndLog "${FUNCNAME}(): Updatting ogLive"
883                oglivecli install $FILENAME
[e1c01217]884               
[ee4beb4]885                # Obtiene versión del Kernel del cliente (con 2 decimales).
[46f8e8b]886                KERNELVERSION=$(jq -r ".oglive[.default].kernel" |
[2f9cd767]887                                awk -F. '{printf("%d",$1); $1=""; printf(".%02d",$0)}')
[ee4beb4]888                # Actaulizar la base de datos adaptada al Kernel del cliente.
889                OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-postinst.sql"
890                if [ -f $OPENGNSYS_DBUPDATEFILE ]; then
[e00bb53]891                        perl -pi -e "s/KERNELVERSION/$KERNELVERSION/g" $OPENGNSYS_DBUPDATEFILE
[ee4beb4]892                        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE
893                fi
[8b2da718]894                CLIENTUPDATED=${FILENAME%.*}
[ee4beb4]895
[a63345ac]896                echoAndLog "${FUNCNAME}(): Client update successfully"
[0b85cc93]897        else
[65baf16]898                # Si no existe, crear el fichero de claves de Rsync.
899                if [ ! -f /etc/rsyncd.secrets ]; then
900                        echoAndLog "${FUNCNAME}(): Restoring client access key"
[0496417]901                        OGINITRD=$(oglivecli config install-dir)/$(jq -r ".oglive[.default].directory")/oginitrd.img
[65baf16]902                        SAMBAPASS=$(gzip -dc $OGINITRD | \
903                                    cpio -i --to-stdout scripts/ogfunctions 2>&1 | \
904                                    grep "^[    ].*OPTIONS=" | \
905                                    sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')
[0496417]906                        echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | setsmbpass
[65baf16]907                else
908                        echoAndLog "${FUNCNAME}(): Client is already updated"
909                fi
[04e5d96]910                # Versión del ogLive instalado.
911                echo "${FILENAME%.*}" > $INSTALL_TARGET/doc/veroglive.txt
[c1e00e4]912        fi
913}
[a0867b37]914
[5b95ab6]915# Comprobar permisos y ficheros.
916function checkFiles()
917{
918        # Comprobar permisos adecuados.
919        if [ -x $INSTALL_TARGET/bin/checkperms ]; then
920                echoAndLog "${FUNCNAME}(): Checking permissions."
921                OPENGNSYS_DIR="$INSTALL_TARGET" OPENGNSYS_USER="$OPENGNSYS_CLIENTUSER" APACHE_USER="$APACHE_RUN_USER" APACHE_GROUP="$APACHE_RUN_GROUP" $INSTALL_TARGET/bin/checkperms
922        fi
923
924        # Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
925        if [ -f /tmp/dstate ]; then
926                echoAndLog "${FUNCNAME}(): Delete unused files."
927                rm -f /tmp/dstate
928        fi
929}
930
[eb9424f]931# Resumen de actualización.
932function updateSummary()
933{
934        # Actualizar fichero de versión y revisión.
935        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
[57f7e9c]936        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}')
[eb9424f]937
[5f21d34]938        [ -f $VERSIONFILE ] || echo "OpenGnsys" >$VERSIONFILE
[eb9424f]939        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
940
941        echo
[5f21d34]942        echoAndLog "OpenGnsys Update Summary"
[df3cd7f]943        echo       "========================"
944        echoAndLog "Project version:                  $(cat $VERSIONFILE)"
[57f7e9c]945        echoAndLog "Update log file:                  $LOG_FILE"
[df3cd7f]946        if [ -n "$NEWFILES" ]; then
[a3855dc]947                echoAndLog "Check new config files:           $(echo $NEWFILES)"
[df3cd7f]948        fi
[dde65c7]949        if [ -n "$NEWSERVICES" ]; then
950                echoAndLog "New compiled services:            $(echo $NEWSERVICES)"
951                # Indicar si se debe reiniciar servicios manualmente o usando el Cron.
952                [ -f /etc/default/opengnsys ] && source /etc/default/opengnsys
953                if [ "$RUN_CRONJOB" == "no" ]; then
[5f21d34]954                        echoAndLog "        WARNING: you must restart OpenGnsys services manually."
[dde65c7]955                else
[5f21d34]956                        echoAndLog "        New OpenGnsys services will be restarted by the cronjob."
[dde65c7]957                fi
958        fi
[8b2da718]959        echoAndLog "Warnings:"
960        echoAndLog " - You must to clear web browser cache before loading OpenGnSys page."
961        if [ -n "$CLIENTUPDATED" ]; then
962                echoAndLog " - ogLive Client is updated to: $CLIENTUPDATED"
963        fi
[eb9424f]964        echo
965}
966
967
[a0867b37]968
969#####################################################################
[5f21d34]970####### Proceso de actualización de OpenGnsys
[a0867b37]971#####################################################################
972
973
[5f21d34]974echoAndLog "OpenGnsys update begins at $(date)"
[a0867b37]975
[bb30a50]976pushd $WORKDIR
977
[27dc5ff]978# Comprobar si hay conexión y detectar parámetros de red por defecto.
979checkNetworkConnection
980if [ $? -ne 0 ]; then
981        errorAndLog "Error connecting to server. Causes:"
982        errorAndLog " - Network is unreachable, review devices parameters."
983        errorAndLog " - You are inside a private network, configure the proxy service."
984        errorAndLog " - Server is temporally down, try agian later."
985        exit 1
986fi
[739fb00]987getNetworkSettings
[27dc5ff]988
[64dd765]989# Comprobar auto-actualización del programa.
990if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
991        checkAutoUpdate
992        if [ $? -ne 0 ]; then
[5f21d34]993                echoAndLog "OpenGnsys updater has been overwritten."
[f580c51]994                echoAndLog "Please, re-execute this script."
[64dd765]995                exit
996        fi
997fi
998
[db9e706]999# Detectar datos de auto-configuración del instalador.
1000autoConfigure
1001
[bb30a50]1002# Instalar dependencias.
[d70a45f]1003installDependencies ${DEPENDENCIES[*]}
[a0867b37]1004if [ $? -ne 0 ]; then
1005        errorAndLog "Error: you may install all needed dependencies."
1006        exit 1
1007fi
1008
[5f21d34]1009# Arbol de directorios de OpenGnsys.
[a0867b37]1010createDirs ${INSTALL_TARGET}
1011if [ $? -ne 0 ]; then
1012        errorAndLog "Error while creating directory paths!"
1013        exit 1
1014fi
1015
1016# Si es necesario, descarga el repositorio de código en directorio temporal
1017if [ $USESVN -eq 1 ]; then
1018        svnExportCode $SVN_URL
1019        if [ $? -ne 0 ]; then
1020                errorAndLog "Error while getting code from svn"
1021                exit 1
1022        fi
1023else
1024        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
1025fi
1026
[566e84f]1027# Actualizar la BD.
1028updateDatabase
[295b4ab]1029
1030# Actualizar ficheros complementarios del servidor
[a0867b37]1031updateServerFiles
1032if [ $? -ne 0 ]; then
[5f21d34]1033        errorAndLog "Error updating OpenGnsys Server files"
[a0867b37]1034        exit 1
1035fi
1036
[be49575]1037# Configurar Rsync.
1038rsyncConfigure
1039
[295b4ab]1040# Actualizar ficheros del cliente
1041updateClientFiles
1042updateInterfaceAdm
[45f1fe8]1043
[295b4ab]1044# Actualizar páqinas web
[3ce53a7]1045apacheConfiguration
[a0867b37]1046updateWebFiles
1047if [ $? -ne 0 ]; then
[5f21d34]1048        errorAndLog "Error updating OpenGnsys Web Admin files"
[a0867b37]1049        exit 1
1050fi
[5d6bf97]1051# Generar páginas Doxygen para instalar en el web
1052makeDoxygenFiles
[a0867b37]1053
[bb30a50]1054# Recompilar y actualizar los servicios del sistema
1055compileServices
1056
1057# Actaulizar ficheros auxiliares del cliente
[a0867b37]1058updateClient
1059if [ $? -ne 0 ]; then
1060        errorAndLog "Error updating clients"
1061        exit 1
1062fi
1063
[5b95ab6]1064# Comprobar permisos y ficheros.
1065checkFiles
[3320409]1066
[eb9424f]1067# Mostrar resumen de actualización.
1068updateSummary
1069
[a0867b37]1070#rm -rf $WORKDIR
[5f21d34]1071echoAndLog "OpenGnsys update finished at $(date)"
[a0867b37]1072
1073popd
1074
Note: See TracBrowser for help on using the repository browser.