source: installer/opengnsys_update.sh @ 8182e59b

Last change on this file since 8182e59b was de687e3, checked in by ramon <ramongomez@…>, 10 years ago

#673: Integrar código de la versión 1.0.6 en rama principal.

git-svn-id: https://opengnsys.es/svn/trunk@4641 a21b9725-9963-47de-94b9-378ad31fedc9

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