source: installer/opengnsys_update.sh @ 695c8e6

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 695c8e6 was 900be258, checked in by ramon <ramongomez@…>, 10 years ago

#708: Preparar API REST en actualización (en pruebas).

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

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