source: installer/opengnsys_update.sh @ 6addf73

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 6addf73 was 1175096, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.4: #515: Script opengnsys_update.sh toma valores de acceso de los ficheros de configuración; si no se encuentran, las toma de las variables de entorno o muestra mensaje de error.

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

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