source: installer/opengnsys_update.sh @ 01a36ca

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 01a36ca was 984093e, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.2: corregir errata en actualizador para parchear ogAdmClient.cfg (cerrar #464).

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