source: installer/opengnsys_update.sh @ fdad5a6

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 fdad5a6 was f580c51, checked in by ramon <ramongomez@…>, 14 years ago

versión 1.0.1: corregir mensaje de actualizador modificado.

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

  • Property mode set to 100755
File size: 22.4 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
[a0867b37]15#*/
16
17
[295b4ab]18####  AVISO: Editar configuración de acceso por defecto a la Base de Datos.
19OPENGNSYS_DATABASE="ogAdmBD"            # Nombre de la base datos
20OPENGNSYS_DBUSER="usuog"                # Usuario de acceso
21OPENGNSYS_DBPASSWORD="passusuog"        # Clave del usuario
22
23####  AVISO: NO Editar variables de acceso desde el cliente
24OPENGNSYS_CLIENTUSER="opengnsys"        # Usuario Samba
25
26
[a0867b37]27# Sólo ejecutable por usuario root
28if [ "$(whoami)" != 'root' ]
29then
30        echo "ERROR: this program must run under root privileges!!"
31        exit 1
32fi
33
34# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1).
35PROGRAMDIR=$(readlink -e $(dirname "$0"))
[64dd765]36PROGRAMNAME=$(basename "$0")
[c1e00e4]37DEPS="build-essential g++-multilib rsync ctorrent samba unzip netpipes debootstrap schroot squashfs-tools"
[07c3a59]38OPENGNSYS_SERVER="www.opengnsys.es"
[a0867b37]39if [ -d "$PROGRAMDIR/../installer" ]; then
40    USESVN=0
41else
42    USESVN=1
43    DEPS="$DEPS subversion"
44fi
[eb9424f]45SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/"
[a0867b37]46
47WORKDIR=/tmp/opengnsys_update
48mkdir -p $WORKDIR
49
50INSTALL_TARGET=/opt/opengnsys
51LOG_FILE=/tmp/opengnsys_update.log
52
53
54
55#####################################################################
56####### Algunas funciones útiles de propósito general:
57#####################################################################
[295b4ab]58
[64dd765]59# Comprobar auto-actualización.
60function checkAutoUpdate()
61{
62        local update=0
63
64        # Actaulizar el script si ha cambiado o no existe el original.
65        if [ $USESVN -eq 1 ]; then
[7b0c6ff]66                svn export $SVN_URL/installer/$PROGRAMNAME
[64dd765]67                if ! diff --brief $PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME &>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
68                        mv $PROGRAMNAME $INSTALL_TARGET/lib
69                        update=1
70                else
71                        rm -f $PROGRAMNAME
72                fi
73        else
74                if ! diff --brief $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME &>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
75                        cp -a $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib
76                        update=1
77                fi
78        fi
79
80        return $update
81}
82
83
[a0867b37]84function getDateTime()
85{
[295b4ab]86        date "+%Y%m%d-%H%M%S"
[a0867b37]87}
88
89# Escribe a fichero y muestra por pantalla
90function echoAndLog()
91{
92        echo $1
93        FECHAHORA=`getDateTime`
94        echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE
95}
96
97function errorAndLog()
98{
99        echo "ERROR: $1"
100        FECHAHORA=`getDateTime`
101        echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
102}
103
104
105#####################################################################
106####### Funciones de copia de seguridad y restauración de ficheros
107#####################################################################
108
109# Hace un backup del fichero pasado por parámetro
110# deja un -last y uno para el día
111function backupFile()
112{
113        if [ $# -ne 1 ]; then
114                errorAndLog "${FUNCNAME}(): invalid number of parameters"
115                exit 1
116        fi
117
118        local fichero=$1
119        local fecha=`date +%Y%m%d`
120
121        if [ ! -f $fichero ]; then
122                errorAndLog "${FUNCNAME}(): file $fichero doesn't exists"
123                return 1
124        fi
125
[ebbbfc01]126        echoAndLog "${FUNCNAME}(): Making $fichero back-up"
[a0867b37]127
128        # realiza una copia de la última configuración como last
129        cp -p $fichero "${fichero}-LAST"
130
131        # si para el día no hay backup lo hace, sino no
132        if [ ! -f "${fichero}-${fecha}" ]; then
133                cp -p $fichero "${fichero}-${fecha}"
134        fi
135}
136
137# Restaura un fichero desde su copia de seguridad
138function restoreFile()
139{
140        if [ $# -ne 1 ]; then
141                errorAndLog "${FUNCNAME}(): invalid number of parameters"
142                exit 1
143        fi
144
145        local fichero=$1
146
[ebbbfc01]147        echoAndLog "${FUNCNAME}(): restoring file $fichero"
[a0867b37]148        if [ -f "${fichero}-LAST" ]; then
149                cp -p "$fichero-LAST" "$fichero"
150        fi
151}
152
153
154#####################################################################
[295b4ab]155####### Funciones de acceso a base de datos
156#####################################################################
157
158# Actualizar la base datos
159function importSqlFile()
160{
161        if [ $# -ne 4 ]; then
162                errorAndLog "${FNCNAME}(): invalid number of parameters"
163                exit 1
164        fi
165
166        local dbuser="$1"
167        local dbpassword="$2"
168        local database="$3"
169        local sqlfile="$4"
170        local tmpfile=$(mktemp)
171        local status
172
173        if [ ! -r $sqlfile ]; then
174                errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!"
175                return 1
176        fi
177
178        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
179        chmod 600 $tmpfile
180        sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
181            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" $sqlfile > $tmpfile
182        mysql -u$dbuser -p"$dbpassword" --default-character-set=utf8 "$database" < $tmpfile
183        status=$?
184        rm -f $tmpfile
185        if [ $status -ne 0 ]; then
186                errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database"
187                return 1
188        fi
189        echoAndLog "${FUNCNAME}(): file imported to database $database"
190        return 0
191}
192
193
194#####################################################################
[a0867b37]195####### Funciones de instalación de paquetes
196#####################################################################
197
198# Instalar las deependencias necesarias para el actualizador.
[64dd765]199function installDependencies()
[a0867b37]200{
201        if [ $# = 0 ]; then
202                echoAndLog "${FUNCNAME}(): no deps needed."
[c1e00e4]203        else
204                while [ $# -gt 0 ]; do
[ebbbfc01]205                        dpkg -s $1 2>/dev/null | grep -q "Status: install ok"
[c1e00e4]206                        if [ $? -ne 0 ]; then
207                                INSTALLDEPS="$INSTALLDEPS $1"
208                        fi
209                        shift
210                done
211                if [ -n "$INSTALLDEPS" ]; then
[ebbbfc01]212                        apt-get update && apt-get -y install --force-yes $INSTALLDEPS
[c1e00e4]213                        if [ $? -ne 0 ]; then
214                                errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
215                                return 1
216                        fi
217                fi
218        fi
[a0867b37]219}
220
221
222#####################################################################
223####### Funciones para el manejo de Subversion
224#####################################################################
225
226function svnExportCode()
227{
228        if [ $# -ne 1 ]; then
229                errorAndLog "${FUNCNAME}(): invalid number of parameters"
230                exit 1
231        fi
232
233        local url=$1
234
235        echoAndLog "${FUNCNAME}(): downloading subversion code..."
236
[7ad4465]237        svn checkout "${url}" opengnsys
[a0867b37]238        if [ $? -ne 0 ]; then
239                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
240                return 1
241        fi
242        echoAndLog "${FUNCNAME}(): subversion code downloaded"
243        return 0
244}
245
246
247############################################################
248###  Detectar red
249############################################################
250
[07c3a59]251# Comprobar si existe conexión.
252function checkNetworkConnection()
253{
254        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"}
255        wget --spider -q $OPENGNSYS_SERVER
256}
257
258# Obtener los parámetros de red de la interfaz por defecto.
[a0867b37]259function getNetworkSettings()
260{
[5d6bf97]261        local MAINDEV
262
[07c3a59]263        echoAndLog "$FUNCNAME(): Detecting default network parameters."
[5d6bf97]264        MAINDEV=$(ip -o link show up | awk '!/loopback/ {d=d$2} END {sub(/:.*/,"",d); print d}')
265        if [ -z "$MAINDEV" ]; then
266                errorAndLog "${FUNCNAME}(): Network device not detected."
267                return 1
[a0867b37]268        fi
269
270        # Variables de ejecución de Apache
271        # - APACHE_RUN_USER
272        # - APACHE_RUN_GROUP
273        if [ -f /etc/apache2/envvars ]; then
274                source /etc/apache2/envvars
275        fi
276        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
277        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
278}
279
280
281#####################################################################
282####### Funciones específicas de la instalación de Opengnsys
283#####################################################################
284
[cf2142ea]285# Copiar ficheros de arranque de los servicios del sistema de OpenGnSys
286
[64dd765]287function updateServicesStart()
288{
[cf2142ea]289        echoAndLog "${FUNCNAME}(): Updating /etc/init.d/opengnsys ..."
[6b65dfd]290        cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
[cf2142ea]291        if [ $? != 0 ]; then
292                errorAndLog "${FUNCNAME}(): Error updating /etc/init.d/opengnsys"
293                exit 1
294        fi
295        echoAndLog "${FUNCNAME}(): /etc/init.d/opengnsys updated successfully."
296}
297
[45f1fe8]298# Actualizar cliente OpenGnSys
[295b4ab]299function updateClientFiles()
[45f1fe8]300{
301        local hayErrores=0
302
303        echoAndLog "${FUNCNAME}(): Updating OpenGnSys Client files."
304        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
305        if [ $? -ne 0 ]; then
306                errorAndLog "${FUNCNAME}(): error while updating client structure"
307                hayErrores=1
308        fi
309        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
310       
311        echoAndLog "${FUNCNAME}(): Updating OpenGnSys Cloning Engine files."
312        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
313        if [ $? -ne 0 ]; then
314                errorAndLog "${FUNCNAME}(): error while updating engine files"
315                hayErrores=1
316        fi
317       
318        if [ $hayErrores -eq 0 ]; then
319                echoAndLog "${FUNCNAME}(): client  files update success."
320        else
321                errorAndLog "${FUNCNAME}(): client files update with errors"
322        fi
323
324        return $hayErrores
325}
[a0867b37]326# Copiar ficheros del OpenGnSys Web Console.
327function updateWebFiles()
328{
[d655cc4]329        local ERRCODE
[a0867b37]330        echoAndLog "${FUNCNAME}(): Updating web files..."
[d655cc4]331        backupFile $INSTALL_TARGET/www/controlacceso.php
332        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
[1db2ed8]333        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
[d655cc4]334        ERRCODE=$?
335        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
[c1e00e4]336        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
[d655cc4]337        if [ $ERRCODE != 0 ]; then
[a0867b37]338                errorAndLog "${FUNCNAME}(): Error updating web files."
339                exit 1
340        fi
[d655cc4]341        restoreFile $INSTALL_TARGET/www/controlacceso.php
[a0867b37]342        # Cambiar permisos para ficheros especiales.
[ebbbfc01]343        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/includes $INSTALL_TARGET/www/images/iconos
[a0867b37]344        echoAndLog "${FUNCNAME}(): Web files updated successfully."
[e473667]345       
[a0867b37]346}
347
[72134d5]348# Copiar carpeta de Interface
[64dd765]349function updateInterfaceAdm()
[72134d5]350{
351        local hayErrores=0
352         
353        # Crear carpeta y copiar Interface
354        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
355        mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface
356        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client
357        ERRCODE=$?
358        mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm
359        if [ $? -ne 0 ]; then
360                echoAndLog "${FUNCNAME}(): error while updating admin interface"
361                exit 1
362        fi
363        chmod -R +x $INSTALL_TARGET/client/interfaceAdm
[b6f1726]364        chown $OPENGNSYS_CLIENTUSER:$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[f6c1d2b]365        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[72134d5]366        echoAndLog "${FUNCNAME}(): Admin interface updated successfully."
367}
[a0867b37]368
[5d6bf97]369# Crear documentación Doxygen para la consola web.
370function makeDoxygenFiles()
371{
372        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
373        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
374                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
375        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
376                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
377                return 1
378        fi
[45f1fe8]379        rm -fr "$INSTALL_TARGET/www/api"
[5d6bf97]380        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
[45f1fe8]381    rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
[5d6bf97]382        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
383        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
384}
385
386
[a0867b37]387# Crea la estructura base de la instalación de opengnsys
388function createDirs()
389{
[eb9424f]390        # Crear estructura de directorios.
[a0867b37]391        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
392        mkdir -p ${INSTALL_TARGET}
393        mkdir -p ${INSTALL_TARGET}/bin
394        mkdir -p ${INSTALL_TARGET}/client
395        mkdir -p ${INSTALL_TARGET}/doc
396        mkdir -p ${INSTALL_TARGET}/etc
397        mkdir -p ${INSTALL_TARGET}/lib
398        mkdir -p ${INSTALL_TARGET}/log/clients
[eb9424f]399        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
[a0867b37]400        mkdir -p ${INSTALL_TARGET}/sbin
401        mkdir -p ${INSTALL_TARGET}/www
402        mkdir -p ${INSTALL_TARGET}/images
403        ln -fs /var/lib/tftpboot ${INSTALL_TARGET}
[eb9424f]404        mkdir -p ${INSTALL_TARGET}/tftpboot/pxelinux.cfg
[a0867b37]405        if [ $? -ne 0 ]; then
406                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
407                return 1
408        fi
409
[eb9424f]410        # Crear usuario ficticio.
411        if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then
412                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created"
413        else
414                echoAndLog "${FUNCNAME}(): creating OpenGnSys user"
415                useradd $OPENGNSYS_CLIENTUSER 2>/dev/null
416                if [ $? -ne 0 ]; then
417                        errorAndLog "${FUNCNAME}(): error creating OpenGnSys user"
418                        return 1
419                fi
420        fi
421
422        # Establecer los permisos básicos.
423        echoAndLog "${FUNCNAME}(): setting directory permissions"
424        chmod -R 775 $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg}
425        chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg}
426        if [ $? -ne 0 ]; then
427                errorAndLog "${FUNCNAME}(): error while setting permissions"
428                return 1
429        fi
430
[a0867b37]431        echoAndLog "${FUNCNAME}(): directory paths created"
432        return 0
433}
434
435# Copia ficheros de configuración y ejecutables genéricos del servidor.
[64dd765]436function updateServerFiles()
[bb30a50]437{
[c1e00e4]438        # No copiar ficheros del antiguo cliente Initrd
439        local SOURCES=( repoman/bin \
440                        server/bin \
[bb30a50]441                        installer/opengnsys_uninstall.sh \
[a0867b37]442                        doc )
[c1e00e4]443        local TARGETS=( bin \
[85b029f]444                        bin \
[bb30a50]445                        lib \
[a0867b37]446                        doc )
447
448        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
449                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
450                exit 1
451        fi
452
453        echoAndLog "${FUNCNAME}(): updating files in server directories"
454        pushd $WORKDIR/opengnsys >/dev/null
455        local i
456        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
[295b4ab]457                rsync --exclude .svn -irplt "${SOURCES[$i]}" $(dirname "${INSTALL_TARGET}/${TARGETS[$i]}")
[a0867b37]458        done
459        popd >/dev/null
[9ee62ad]460        echoAndLog "${FUNCNAME}(): updating cron files"
461        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
[da8db11]462        echoAndLog "${FUNCNAME}(): server files updated successfully."
[a0867b37]463}
464
465####################################################################
466### Funciones de compilación de código fuente de servicios
467####################################################################
468
[bb30a50]469# Recompilar y actualiza los serivicios y clientes.
[64dd765]470function compileServices()
[a0867b37]471{
[bb30a50]472        local hayErrores=0
473
474        # Compilar OpenGnSys Server
475        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Admin Server"
476        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
477        make && mv ogAdmServer $INSTALL_TARGET/sbin
478        if [ $? -ne 0 ]; then
479                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
480                hayErrores=1
481        fi
482        popd
483        # Compilar OpenGnSys Repository Manager
484        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Repository Manager"
485        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
486        make && mv ogAdmRepo $INSTALL_TARGET/sbin
487        if [ $? -ne 0 ]; then
488                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
489                hayErrores=1
490        fi
491        popd
492        # Compilar OpenGnSys Agent
493        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Agent"
494        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
495        make && mv ogAdmAgent $INSTALL_TARGET/sbin
496        if [ $? -ne 0 ]; then
497                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent"
498                hayErrores=1
499        fi
500        popd
501
[a0867b37]502        # Compilar OpenGnSys Client
[bb30a50]503        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Client"
[72134d5]504        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[e473667]505        make && mv ogAdmClient $INSTALL_TARGET/client/bin
[a0867b37]506        if [ $? -ne 0 ]; then
507                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client"
508                hayErrores=1
509        fi
510        popd
511
512        return $hayErrores
513}
514
515
516####################################################################
517### Funciones instalacion cliente opengnsys
518####################################################################
519
[c1e00e4]520# Actualizar antiguo cliente Initrd.
521function updateOldClient()
[a0867b37]522{
523        local OSDISTRIB OSCODENAME
524
525        local hayErrores=0
526
527        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
528        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
529        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
530        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
531        rsync -iplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
532        if [ $? -ne 0 ]; then
533                errorAndLog "${FUNCNAME}(): error while copying engine files"
534                hayErrores=1
535        fi
536
537        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
[72134d5]538        OSDISTRIB=$(lsb_release -is) 2>/dev/null
539        OSCODENAME=$(lsb_release -cs) 2>/dev/null
[a0867b37]540        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
541                echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
[da8db11]542                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v $OSCODENAME 2>&1 | tee -a $LOG_FILE
[a0867b37]543                if [ $? -ne 0 ]; then
544                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
545                        hayErrores=1
546                fi
547                echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
[da8db11]548                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh $OSCODENAME 2>&1 | tee -a $LOG_FILE
[a0867b37]549                if [ $? -ne 0 ]; then
550                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
551                        hayErrores=1
552                fi
553        else
554                echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
[da8db11]555                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot 2>&1 | tee -a $LOG_FILE
[a0867b37]556                if [ $? -ne 0 ]; then
557                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
558                        hayErrores=1
559                fi
560                echoAndLog "${FUNCNAME}(): Loading default udeb files."
[da8db11]561                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh 2>&1 | tee -a $LOG_FILE
[a0867b37]562                if [ $? -ne 0 ]; then
563                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
564                        hayErrores=1
565                fi
566        fi
567
568        if [ $hayErrores -eq 0 ]; then
569                echoAndLog "${FUNCNAME}(): Client generation success."
570        else
571                errorAndLog "${FUNCNAME}(): Client generation with errors"
572        fi
573
574        return $hayErrores
575}
576
[c1e00e4]577# Actualizar nuevo cliente para OpenGnSys 1.0
578function updateClient()
579{
580        local DOWNLOADURL=http://www.opengnsys.es/downloads
[e9722d2]581        local FILENAME=ogclient-1.0.1-lucid-32bit.tar.gz
[6ef9f23]582        local TMPFILE=/tmp/$FILENAME
[c1e00e4]583
584        echoAndLog "${FUNCNAME}(): Loading Client"
585        # Descargar y descomprimir cliente ogclient
[03882ae]586        wget $DOWNLOADURL/$FILENAME -O $TMPFILE
[6ef9f23]587        if [ ! -s $TMPFILE ]; then
588                errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client"
[c1e00e4]589                return 1
590        fi
[03882ae]591        echoAndLog "${FUNCNAME}(): Extracting Client files"
[6ef9f23]592        tar xzvf $TMPFILE -C $INSTALL_TARGET/tftpboot
593        rm -f $TMPFILE
[c1e00e4]594        # Usar la versión más reciente del Kernel y del Initrd para el cliente.
[295b4ab]595        ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/vmlinuz-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz
596        ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/initrd.img-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img
[c1e00e4]597        # Establecer los permisos.
598        chmod -R 755 $INSTALL_TARGET/tftpboot/ogclient
[295b4ab]599        chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient
[c1e00e4]600        echoAndLog "${FUNCNAME}(): Client update successfully"
601}
[a0867b37]602
[eb9424f]603# Resumen de actualización.
604function updateSummary()
605{
606        # Actualizar fichero de versión y revisión.
607        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
608        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Revision:/ {print "r"$2}')
609
610        [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE
611        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
612
613        echo
614        echoAndLog "OpenGnSys Update Summary"
615        echo       "========================"
616        echoAndLog "Project version:                  $(cat $VERSIONFILE)"
617        echo
618}
619
620
[a0867b37]621
622#####################################################################
[3320409]623####### Proceso de actualización de OpenGnSys
[a0867b37]624#####################################################################
625
626
627echoAndLog "OpenGnSys update begins at $(date)"
628
[bb30a50]629pushd $WORKDIR
630
[64dd765]631# Comprobar auto-actualización del programa.
632if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
633        checkAutoUpdate
634        if [ $? -ne 0 ]; then
[f580c51]635                echoAndLog "OpenGnSys updater has been overwritten."
636                echoAndLog "Please, re-execute this script."
[64dd765]637                exit
638        fi
639fi
640
[bb30a50]641# Instalar dependencias.
[a0867b37]642installDependencies $DEPS
643if [ $? -ne 0 ]; then
644        errorAndLog "Error: you may install all needed dependencies."
645        exit 1
646fi
647
[07c3a59]648# Comprobar si hay conexión y detectar parámetros de red por defecto.
649checkNetworkConnection
650if [ $? -ne 0 ]; then
651        errorAndLog "Error connecting to server. Causes:"
652        errorAndLog " - Network is unreachable, review devices parameters."
653        errorAndLog " - You are inside a private network, configure the proxy service."
654        errorAndLog " - Server is temporally down, try agian later."
655        exit 1
656fi
[a0867b37]657getNetworkSettings
658if [ $? -ne 0 ]; then
659        errorAndLog "Error reading default network settings."
660        exit 1
661fi
662
663# Arbol de directorios de OpenGnSys.
664createDirs ${INSTALL_TARGET}
665if [ $? -ne 0 ]; then
666        errorAndLog "Error while creating directory paths!"
667        exit 1
668fi
669
670# Si es necesario, descarga el repositorio de código en directorio temporal
671if [ $USESVN -eq 1 ]; then
672        svnExportCode $SVN_URL
673        if [ $? -ne 0 ]; then
674                errorAndLog "Error while getting code from svn"
675                exit 1
676        fi
677else
678        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
679fi
680
[295b4ab]681# Si existe fichero de actualización de la base de datos; aplicar cambios.
682INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
683REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
684OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
685if [ -f $OPENGNSYS_DBUPDATEFILE ]; then
686        echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION"
687        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE
688else
689        echoAndLog "Database unchanged."
690fi
691
692# Actualizar ficheros complementarios del servidor
[a0867b37]693updateServerFiles
694if [ $? -ne 0 ]; then
[da8db11]695        errorAndLog "Error updating OpenGnSys Server files"
[a0867b37]696        exit 1
697fi
698
[295b4ab]699# Actualizar ficheros del cliente
700updateClientFiles
701updateInterfaceAdm
[45f1fe8]702
[295b4ab]703# Actualizar páqinas web
[a0867b37]704updateWebFiles
705if [ $? -ne 0 ]; then
[da8db11]706        errorAndLog "Error updating OpenGnSys Web Admin files"
[a0867b37]707        exit 1
708fi
[5d6bf97]709# Generar páginas Doxygen para instalar en el web
710makeDoxygenFiles
[a0867b37]711
[bb30a50]712# Recompilar y actualizar los servicios del sistema
713compileServices
714
715# Actaulizar ficheros auxiliares del cliente
[a0867b37]716updateClient
717if [ $? -ne 0 ]; then
718        errorAndLog "Error updating clients"
719        exit 1
720fi
721
[95f1f68]722# Actualizamos el fichero que arranca los servicios de OpenGnSys
723updateServicesStart
724
[3320409]725# Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
[ebbbfc01]726if [ -f /tmp/dstate ]; then
727        rm -f /tmp/dstate
[3320409]728fi
729
[eb9424f]730# Mostrar resumen de actualización.
731updateSummary
732
[a0867b37]733#rm -rf $WORKDIR
734echoAndLog "OpenGnSys update finished at $(date)"
735
736popd
737
Note: See TracBrowser for help on using the repository browser.