source: installer/opengnsys_update.sh @ 98db1ad

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 98db1ad was 873cf1e, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.1: actualizador incluye ficheros de tftpboot (cerrar #408).

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

  • Property mode set to 100755
File size: 22.3 KB
Line 
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
9#@version 1.0 - adaptación a OpenGnSys 1.0
10#@author  Ramón Gómez - ETSII Univ. Sevilla
11#@date    2011/03/02
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
15#*/
16
17
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
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"))
36PROGRAMNAME=$(basename "$0")
37DEPS="build-essential g++-multilib rsync ctorrent samba unzip netpipes debootstrap schroot squashfs-tools"
38OPENGNSYS_SERVER="www.opengnsys.es"
39if [ -d "$PROGRAMDIR/../installer" ]; then
40    USESVN=0
41else
42    USESVN=1
43    DEPS="$DEPS subversion"
44fi
45SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/"
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#####################################################################
58
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
66                svn export $SVN_URL/installer/$PROGRAMNAME
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
84function getDateTime()
85{
86        date "+%Y%m%d-%H%M%S"
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
126        echoAndLog "${FUNCNAME}(): Making $fichero back-up"
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
147        echoAndLog "${FUNCNAME}(): restoring file $fichero"
148        if [ -f "${fichero}-LAST" ]; then
149                cp -p "$fichero-LAST" "$fichero"
150        fi
151}
152
153
154#####################################################################
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#####################################################################
195####### Funciones de instalación de paquetes
196#####################################################################
197
198# Instalar las deependencias necesarias para el actualizador.
199function installDependencies()
200{
201        if [ $# = 0 ]; then
202                echoAndLog "${FUNCNAME}(): no deps needed."
203        else
204                while [ $# -gt 0 ]; do
205                        dpkg -s $1 2>/dev/null | grep -q "Status: install ok"
206                        if [ $? -ne 0 ]; then
207                                INSTALLDEPS="$INSTALLDEPS $1"
208                        fi
209                        shift
210                done
211                if [ -n "$INSTALLDEPS" ]; then
212                        apt-get update && apt-get -y install --force-yes $INSTALLDEPS
213                        if [ $? -ne 0 ]; then
214                                errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
215                                return 1
216                        fi
217                fi
218        fi
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
237        svn checkout "${url}" opengnsys
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
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.
259function getNetworkSettings()
260{
261        local MAINDEV
262
263        echoAndLog "$FUNCNAME(): Detecting default network parameters."
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
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
285# Copiar ficheros de arranque de los servicios del sistema de OpenGnSys
286
287function updateServicesStart()
288{
289        echoAndLog "${FUNCNAME}(): Updating /etc/init.d/opengnsys ..."
290        cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
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
298# Actualizar cliente OpenGnSys
299function updateClientFiles()
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}
326# Copiar ficheros del OpenGnSys Web Console.
327function updateWebFiles()
328{
329        local ERRCODE
330        echoAndLog "${FUNCNAME}(): Updating web files..."
331        backupFile $INSTALL_TARGET/www/controlacceso.php
332        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
333        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
334        ERRCODE=$?
335        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
336        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
337        if [ $ERRCODE != 0 ]; then
338                errorAndLog "${FUNCNAME}(): Error updating web files."
339                exit 1
340        fi
341        restoreFile $INSTALL_TARGET/www/controlacceso.php
342        # Cambiar permisos para ficheros especiales.
343        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/includes $INSTALL_TARGET/www/images/iconos
344        echoAndLog "${FUNCNAME}(): Web files updated successfully."
345       
346}
347
348# Copiar carpeta de Interface
349function updateInterfaceAdm()
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
364        chown $OPENGNSYS_CLIENTUSER:$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
365        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
366        echoAndLog "${FUNCNAME}(): Admin interface updated successfully."
367}
368
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
379        rm -fr "$INSTALL_TARGET/www/api"
380        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
381    rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
382        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
383        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
384}
385
386
387# Crea la estructura base de la instalación de opengnsys
388function createDirs()
389{
390        # Crear estructura de directorios.
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
399        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
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}
404        mkdir -p ${INSTALL_TARGET}/tftpboot/pxelinux.cfg
405        if [ $? -ne 0 ]; then
406                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
407                return 1
408        fi
409
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
431        echoAndLog "${FUNCNAME}(): directory paths created"
432        return 0
433}
434
435# Copia ficheros de configuración y ejecutables genéricos del servidor.
436function updateServerFiles()
437{
438        # No copiar ficheros del antiguo cliente Initrd
439        local SOURCES=( repoman/bin \
440                        server/bin \
441                        server/tftpboot \
442                        installer/opengnsys_uninstall.sh \
443                        doc )
444        local TARGETS=( bin \
445                        bin \
446                        tftpboot \
447                        lib \
448                        doc )
449
450        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
451                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
452                exit 1
453        fi
454
455        echoAndLog "${FUNCNAME}(): updating files in server directories"
456        pushd $WORKDIR/opengnsys >/dev/null
457        local i
458        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
459                rsync --exclude .svn -irplt "${SOURCES[$i]}" $(dirname "${INSTALL_TARGET}/${TARGETS[$i]}")
460        done
461        popd >/dev/null
462        echoAndLog "${FUNCNAME}(): updating cron files"
463        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
464        echoAndLog "${FUNCNAME}(): server files updated successfully."
465}
466
467####################################################################
468### Funciones de compilación de código fuente de servicios
469####################################################################
470
471# Recompilar y actualiza los serivicios y clientes.
472function compileServices()
473{
474        local hayErrores=0
475
476        # Compilar OpenGnSys Server
477        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Admin Server"
478        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
479        make && mv ogAdmServer $INSTALL_TARGET/sbin
480        if [ $? -ne 0 ]; then
481                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
482                hayErrores=1
483        fi
484        popd
485        # Compilar OpenGnSys Repository Manager
486        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Repository Manager"
487        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
488        make && mv ogAdmRepo $INSTALL_TARGET/sbin
489        if [ $? -ne 0 ]; then
490                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
491                hayErrores=1
492        fi
493        popd
494        # Compilar OpenGnSys Agent
495        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Agent"
496        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
497        make && mv ogAdmAgent $INSTALL_TARGET/sbin
498        if [ $? -ne 0 ]; then
499                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent"
500                hayErrores=1
501        fi
502        popd
503
504        # Compilar OpenGnSys Client
505        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Client"
506        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
507        make && mv ogAdmClient $INSTALL_TARGET/client/bin
508        if [ $? -ne 0 ]; then
509                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client"
510                hayErrores=1
511        fi
512        popd
513
514        return $hayErrores
515}
516
517
518####################################################################
519### Funciones instalacion cliente opengnsys
520####################################################################
521
522# Actualizar antiguo cliente Initrd.
523function updateOldClient()
524{
525        local OSDISTRIB OSCODENAME
526
527        local hayErrores=0
528
529        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
530        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
531        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
532        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
533        rsync -iplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
534        if [ $? -ne 0 ]; then
535                errorAndLog "${FUNCNAME}(): error while copying engine files"
536                hayErrores=1
537        fi
538
539        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
540        OSDISTRIB=$(lsb_release -is) 2>/dev/null
541        OSCODENAME=$(lsb_release -cs) 2>/dev/null
542        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
543                echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
544                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v $OSCODENAME 2>&1 | tee -a $LOG_FILE
545                if [ $? -ne 0 ]; then
546                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
547                        hayErrores=1
548                fi
549                echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
550                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh $OSCODENAME 2>&1 | tee -a $LOG_FILE
551                if [ $? -ne 0 ]; then
552                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
553                        hayErrores=1
554                fi
555        else
556                echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
557                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot 2>&1 | tee -a $LOG_FILE
558                if [ $? -ne 0 ]; then
559                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
560                        hayErrores=1
561                fi
562                echoAndLog "${FUNCNAME}(): Loading default udeb files."
563                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh 2>&1 | tee -a $LOG_FILE
564                if [ $? -ne 0 ]; then
565                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
566                        hayErrores=1
567                fi
568        fi
569
570        if [ $hayErrores -eq 0 ]; then
571                echoAndLog "${FUNCNAME}(): Client generation success."
572        else
573                errorAndLog "${FUNCNAME}(): Client generation with errors"
574        fi
575
576        return $hayErrores
577}
578
579# Actualizar nuevo cliente para OpenGnSys 1.0
580function updateClient()
581{
582        local DOWNLOADURL=http://www.opengnsys.es/downloads
583        local FILENAME=ogclient-1.0.1-lucid-32bit.tar.gz
584        local TMPFILE=/tmp/$FILENAME
585
586        echoAndLog "${FUNCNAME}(): Loading Client"
587        # Descargar y descomprimir cliente ogclient
588        wget $DOWNLOADURL/$FILENAME -O $TMPFILE
589        if [ ! -s $TMPFILE ]; then
590                errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client"
591                return 1
592        fi
593        echoAndLog "${FUNCNAME}(): Extracting Client files"
594        tar xzvf $TMPFILE -C $INSTALL_TARGET/tftpboot
595        rm -f $TMPFILE
596        # Usar la versión más reciente del Kernel y del Initrd para el cliente.
597        ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/vmlinuz-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz
598        ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/initrd.img-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img
599        # Establecer los permisos.
600        chmod -R 755 $INSTALL_TARGET/tftpboot/ogclient
601        chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient
602        echoAndLog "${FUNCNAME}(): Client update successfully"
603}
604
605# Resumen de actualización.
606function updateSummary()
607{
608        # Actualizar fichero de versión y revisión.
609        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
610        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Revision:/ {print "r"$2}')
611
612        [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE
613        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
614
615        echo
616        echoAndLog "OpenGnSys Update Summary"
617        echo       "========================"
618        echoAndLog "Project version:                  $(cat $VERSIONFILE)"
619        echo
620}
621
622
623
624#####################################################################
625####### Proceso de actualización de OpenGnSys
626#####################################################################
627
628
629echoAndLog "OpenGnSys update begins at $(date)"
630
631pushd $WORKDIR
632
633# Comprobar auto-actualización del programa.
634if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
635        checkAutoUpdate
636        if [ $? -ne 0 ]; then
637                echoAndLog "OpenGnSys updater has been overwritten."
638                echoAndLog "Please, re-execute this script."
639                exit
640        fi
641fi
642
643# Instalar dependencias.
644installDependencies $DEPS
645if [ $? -ne 0 ]; then
646        errorAndLog "Error: you may install all needed dependencies."
647        exit 1
648fi
649
650# Comprobar si hay conexión y detectar parámetros de red por defecto.
651checkNetworkConnection
652if [ $? -ne 0 ]; then
653        errorAndLog "Error connecting to server. Causes:"
654        errorAndLog " - Network is unreachable, review devices parameters."
655        errorAndLog " - You are inside a private network, configure the proxy service."
656        errorAndLog " - Server is temporally down, try agian later."
657        exit 1
658fi
659getNetworkSettings
660if [ $? -ne 0 ]; then
661        errorAndLog "Error reading default network settings."
662        exit 1
663fi
664
665# Arbol de directorios de OpenGnSys.
666createDirs ${INSTALL_TARGET}
667if [ $? -ne 0 ]; then
668        errorAndLog "Error while creating directory paths!"
669        exit 1
670fi
671
672# Si es necesario, descarga el repositorio de código en directorio temporal
673if [ $USESVN -eq 1 ]; then
674        svnExportCode $SVN_URL
675        if [ $? -ne 0 ]; then
676                errorAndLog "Error while getting code from svn"
677                exit 1
678        fi
679else
680        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
681fi
682
683# Si existe fichero de actualización de la base de datos; aplicar cambios.
684INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
685REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
686OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
687if [ -f $OPENGNSYS_DBUPDATEFILE ]; then
688        echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION"
689        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE
690else
691        echoAndLog "Database unchanged."
692fi
693
694# Actualizar ficheros complementarios del servidor
695updateServerFiles
696if [ $? -ne 0 ]; then
697        errorAndLog "Error updating OpenGnSys Server files"
698        exit 1
699fi
700
701# Actualizar ficheros del cliente
702updateClientFiles
703updateInterfaceAdm
704
705# Actualizar páqinas web
706updateWebFiles
707if [ $? -ne 0 ]; then
708        errorAndLog "Error updating OpenGnSys Web Admin files"
709        exit 1
710fi
711# Generar páginas Doxygen para instalar en el web
712makeDoxygenFiles
713
714# Recompilar y actualizar los servicios del sistema
715compileServices
716
717# Actaulizar ficheros auxiliares del cliente
718updateClient
719if [ $? -ne 0 ]; then
720        errorAndLog "Error updating clients"
721        exit 1
722fi
723
724# Actualizamos el fichero que arranca los servicios de OpenGnSys
725updateServicesStart
726
727# Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
728if [ -f /tmp/dstate ]; then
729        rm -f /tmp/dstate
730fi
731
732# Mostrar resumen de actualización.
733updateSummary
734
735#rm -rf $WORKDIR
736echoAndLog "OpenGnSys update finished at $(date)"
737
738popd
739
Note: See TracBrowser for help on using the repository browser.