source: installer/opengnsys_update.sh @ 1c53cef

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 1c53cef was 57cf15b, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: añadir al cron un proceso de comprobación y reinicio ante caída de los servicios principales (modifica #426).

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

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