source: installer/opengnsys_update.sh @ 0a735488

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 0a735488 was 2c8b9ed, checked in by ramon <ramongomez@…>, 10 years ago

#647: Instalar/actualizar usando arp-scan de CentOS 6 para servidores CentOS 7 (no existe en esta versión).

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

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