source: installer/opengnsys_update.sh @ d9905b9

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 d9905b9 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
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
[6ef01d9]28if [ "$(whoami)" != 'root' ]; then
[a0867b37]29        echo "ERROR: this program must run under root privileges!!"
30        exit 1
31fi
[4e51cb0]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
[a0867b37]38
39# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1).
40PROGRAMDIR=$(readlink -e $(dirname "$0"))
[64dd765]41PROGRAMNAME=$(basename "$0")
[c1e00e4]42DEPS="build-essential g++-multilib rsync ctorrent samba unzip netpipes debootstrap schroot squashfs-tools"
[07c3a59]43OPENGNSYS_SERVER="www.opengnsys.es"
[a0867b37]44if [ -d "$PROGRAMDIR/../installer" ]; then
[6ef01d9]45        USESVN=0
[a0867b37]46else
[6ef01d9]47        USESVN=1
48        DEPS="$DEPS subversion"
[a0867b37]49fi
[eb9424f]50SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/"
[a0867b37]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#####################################################################
[295b4ab]62
[64dd765]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
[7b0c6ff]70                svn export $SVN_URL/installer/$PROGRAMNAME
[64dd765]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
[a0867b37]88function getDateTime()
89{
[5eb61a6]90        date "+%Y%m%d-%H%M%S"
[a0867b37]91}
92
93# Escribe a fichero y muestra por pantalla
94function echoAndLog()
95{
[5eb61a6]96        echo $1
[6ef01d9]97        DATETIME=`getDateTime`
98        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
[a0867b37]99}
100
101function errorAndLog()
102{
[5eb61a6]103        echo "ERROR: $1"
104        DATETIME=`getDateTime`
[6ef01d9]105        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
[a0867b37]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
[ebbbfc01]130        echoAndLog "${FUNCNAME}(): Making $fichero back-up"
[a0867b37]131
132        # realiza una copia de la última configuración como last
[6ef01d9]133        cp -a $fichero "${fichero}-LAST"
[a0867b37]134
135        # si para el día no hay backup lo hace, sino no
136        if [ ! -f "${fichero}-${fecha}" ]; then
[6ef01d9]137                cp -a $fichero "${fichero}-${fecha}"
[a0867b37]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
[ebbbfc01]151        echoAndLog "${FUNCNAME}(): restoring file $fichero"
[a0867b37]152        if [ -f "${fichero}-LAST" ]; then
[6ef01d9]153                cp -a "$fichero-LAST" "$fichero"
[a0867b37]154        fi
155}
156
157
158#####################################################################
[295b4ab]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#####################################################################
[a0867b37]199####### Funciones de instalación de paquetes
200#####################################################################
201
202# Instalar las deependencias necesarias para el actualizador.
[64dd765]203function installDependencies()
[a0867b37]204{
205        if [ $# = 0 ]; then
206                echoAndLog "${FUNCNAME}(): no deps needed."
[c1e00e4]207        else
208                while [ $# -gt 0 ]; do
[ebbbfc01]209                        dpkg -s $1 2>/dev/null | grep -q "Status: install ok"
[c1e00e4]210                        if [ $? -ne 0 ]; then
211                                INSTALLDEPS="$INSTALLDEPS $1"
212                        fi
213                        shift
214                done
215                if [ -n "$INSTALLDEPS" ]; then
[ebbbfc01]216                        apt-get update && apt-get -y install --force-yes $INSTALLDEPS
[c1e00e4]217                        if [ $? -ne 0 ]; then
218                                errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
219                                return 1
220                        fi
221                fi
222        fi
[a0867b37]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
[27dc5ff]237        local url="$1"
[a0867b37]238
239        echoAndLog "${FUNCNAME}(): downloading subversion code..."
240
[7ad4465]241        svn checkout "${url}" opengnsys
[a0867b37]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
[07c3a59]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
[a0867b37]262
263#####################################################################
264####### Funciones específicas de la instalación de Opengnsys
265#####################################################################
266
[45f1fe8]267# Actualizar cliente OpenGnSys
[295b4ab]268function updateClientFiles()
[45f1fe8]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"
[51b179a]274                exit 1
[45f1fe8]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."
[51b179a]279        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
[45f1fe8]280        if [ $? -ne 0 ]; then
281                errorAndLog "${FUNCNAME}(): error while updating engine files"
[51b179a]282                exit 1
[45f1fe8]283        fi
284       
[51b179a]285        echoAndLog "${FUNCNAME}(): client files update success."
[45f1fe8]286}
[4e51cb0]287
[3ce53a7]288# Configurar HTTPS y exportar usuario y grupo del servicio Apache.
289function apacheConfiguration ()
[4e51cb0]290{
[3ce53a7]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
[3e24aa5]299                a2dissite opengnsys.conf
[3ce53a7]300                a2ensite opengnsys
301                /etc/init.d/apache2 restart
302        fi
303
304        # Variables de ejecución de Apache.
[4e51cb0]305        # - APACHE_RUN_USER
306        # - APACHE_RUN_GROUP
[3ce53a7]307        if [ -f $APACHECONF/envvars ]; then
308                source $APACHECONF/envvars
[4e51cb0]309        fi
310        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
311        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
312}
313
[a0867b37]314# Copiar ficheros del OpenGnSys Web Console.
315function updateWebFiles()
316{
[d655cc4]317        local ERRCODE
[a0867b37]318        echoAndLog "${FUNCNAME}(): Updating web files..."
[d655cc4]319        backupFile $INSTALL_TARGET/www/controlacceso.php
320        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
[1db2ed8]321        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
[d655cc4]322        ERRCODE=$?
323        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
[c1e00e4]324        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
[d655cc4]325        if [ $ERRCODE != 0 ]; then
[a0867b37]326                errorAndLog "${FUNCNAME}(): Error updating web files."
327                exit 1
328        fi
[d655cc4]329        restoreFile $INSTALL_TARGET/www/controlacceso.php
[a0867b37]330        # Cambiar permisos para ficheros especiales.
[ebbbfc01]331        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/includes $INSTALL_TARGET/www/images/iconos
[a0867b37]332        echoAndLog "${FUNCNAME}(): Web files updated successfully."
333}
334
[72134d5]335# Copiar carpeta de Interface
[64dd765]336function updateInterfaceAdm()
[72134d5]337{
[27dc5ff]338        local errcode=0
[72134d5]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
[27dc5ff]344        errcoce=$?
[72134d5]345        mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm
[27dc5ff]346        if [ $errcode -ne 0 ]; then
[72134d5]347                echoAndLog "${FUNCNAME}(): error while updating admin interface"
348                exit 1
349        fi
350        chmod -R +x $INSTALL_TARGET/client/interfaceAdm
[b6f1726]351        chown $OPENGNSYS_CLIENTUSER:$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[f6c1d2b]352        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[72134d5]353        echoAndLog "${FUNCNAME}(): Admin interface updated successfully."
354}
[a0867b37]355
[5d6bf97]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
[45f1fe8]366        rm -fr "$INSTALL_TARGET/www/api"
[15b2a4e]367        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
368        rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
[5d6bf97]369        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
370        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
371}
372
373
[a0867b37]374# Crea la estructura base de la instalación de opengnsys
375function createDirs()
376{
[eb9424f]377        # Crear estructura de directorios.
[a0867b37]378        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
[cfad47b]379        mkdir -p ${INSTALL_TARGET}/{bin,doc,etc,lib,sbin,www}
380        mkdir -p ${INSTALL_TARGET}/{client,images}
[a0867b37]381        mkdir -p ${INSTALL_TARGET}/log/clients
[eb9424f]382        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
[a0867b37]383        ln -fs /var/lib/tftpboot ${INSTALL_TARGET}
[cfad47b]384        mkdir -p ${INSTALL_TARGET}/tftpboot/{pxelinux.cfg,menu.lst}
[a0867b37]385        if [ $? -ne 0 ]; then
386                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
387                return 1
388        fi
389
[eb9424f]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"
[cfad47b]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}
[eb9424f]406        if [ $? -ne 0 ]; then
407                errorAndLog "${FUNCNAME}(): error while setting permissions"
408                return 1
409        fi
410
[a0867b37]411        echoAndLog "${FUNCNAME}(): directory paths created"
412        return 0
413}
414
415# Copia ficheros de configuración y ejecutables genéricos del servidor.
[64dd765]416function updateServerFiles()
[bb30a50]417{
[c1e00e4]418        # No copiar ficheros del antiguo cliente Initrd
[873cf1e]419        local SOURCES=( repoman/bin \
[c1e00e4]420                        server/bin \
[873cf1e]421                        server/tftpboot \
[bb30a50]422                        installer/opengnsys_uninstall.sh \
[873cf1e]423                        doc )
424        local TARGETS=( bin \
425                        bin \
426                        tftpboot \
[4057c5d]427                        lib/opengnsys_uninstall.sh \
[873cf1e]428                        doc )
[a0867b37]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
[27dc5ff]439                if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then
[4057c5d]440                        rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}"))
[aa36857]441                else
[4057c5d]442                        rsync --exclude .svn -irplt "${SOURCES[i]}" $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}")
[aa36857]443                fi
[a0867b37]444        done
445        popd >/dev/null
[df3cd7f]446        NEWFILES=""             # Ficheros de configuración que han cambiado de formato.
[f80f839]447        if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then
[df3cd7f]448                echoAndLog "${FUNCNAME}(): updating DHCP files"
[f80f839]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
[df3cd7f]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
[984093e]461        if grep -q "UrlMsg=.*msgbrowser.php" $INSTALL_TARGET/client/etc/ogAdmClient.cfg 2>/dev/null; then
[df3cd7f]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"
[f80f839]466        fi
[9ee62ad]467        echoAndLog "${FUNCNAME}(): updating cron files"
[57cf15b]468        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys
[9ee62ad]469        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
[da8db11]470        echoAndLog "${FUNCNAME}(): server files updated successfully."
[a0867b37]471}
472
473####################################################################
474### Funciones de compilación de código fuente de servicios
475####################################################################
476
[bb30a50]477# Recompilar y actualiza los serivicios y clientes.
[64dd765]478function compileServices()
[a0867b37]479{
[bb30a50]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
[a0867b37]510        # Compilar OpenGnSys Client
[bb30a50]511        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Client"
[72134d5]512        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[e473667]513        make && mv ogAdmClient $INSTALL_TARGET/client/bin
[a0867b37]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####################################################################
[4e51cb0]525### Funciones instalacion cliente OpenGnSys
[a0867b37]526####################################################################
527
[c1e00e4]528# Actualizar nuevo cliente para OpenGnSys 1.0
529function updateClient()
530{
[df3cd7f]531        local DOWNLOADURL="http://$OPENGNSYS_SERVER/downloads"
[fe293a7]532        local FILENAME=ogLive-natty-2.6.38-8-generic-pae-r2303.iso
[0b85cc93]533        local SOURCEFILE=$DOWNLOADURL/$FILENAME
534        local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
535        local SOURCELENGTH
536        local TARGETLENGTH
537        local TMPDIR=/tmp/${FILENAME%.iso}
[a63345ac]538        local OGINITRD=$INSTALL_TARGET/tftpboot/ogclient/oginitrd.img
539        local SAMBAPASS
[0b85cc93]540
541        # Comprobar si debe actualizarse el cliente.
[c3cc6b0]542        SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}')
[d168a46]543        TARGETLENGTH=$(ls -l $TARGETFILE 2>/dev/null | awk '{print $5}')
[d4e90c1]544        [ -z $TARGETLENGTH ] && TARGETLENGTH=0
[0b85cc93]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
[a63345ac]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 | \
[c3cc6b0]556                                    grep "^[    ]*OPTIONS=" | \
[a63345ac]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}
[e1c01217]577               
[e8963d0]578                # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache
[6ef01d9]579                cp -arv $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot
580                cp -arv $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot
[e1c01217]581               
[a63345ac]582                echoAndLog "${FUNCNAME}(): Client update successfully"
[0b85cc93]583        else
[a63345ac]584                echoAndLog "${FUNCNAME}(): Client is already updated"
[c1e00e4]585        fi
586}
[a0867b37]587
[eb9424f]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"
[df3cd7f]600        echo       "========================"
601        echoAndLog "Project version:                  $(cat $VERSIONFILE)"
602        if [ -n "$NEWFILES" ]; then
603                echoAndLog "Check the new config files:       $(echo $NEWFILES)"
604        fi
[eb9424f]605        echo
606}
607
608
[a0867b37]609
610#####################################################################
[3320409]611####### Proceso de actualización de OpenGnSys
[a0867b37]612#####################################################################
613
614
615echoAndLog "OpenGnSys update begins at $(date)"
616
[bb30a50]617pushd $WORKDIR
618
[27dc5ff]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
[64dd765]629# Comprobar auto-actualización del programa.
630if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
631        checkAutoUpdate
632        if [ $? -ne 0 ]; then
[f580c51]633                echoAndLog "OpenGnSys updater has been overwritten."
634                echoAndLog "Please, re-execute this script."
[64dd765]635                exit
636        fi
637fi
638
[bb30a50]639# Instalar dependencias.
[a0867b37]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
[295b4ab]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
[a0867b37]676updateServerFiles
677if [ $? -ne 0 ]; then
[da8db11]678        errorAndLog "Error updating OpenGnSys Server files"
[a0867b37]679        exit 1
680fi
681
[295b4ab]682# Actualizar ficheros del cliente
683updateClientFiles
684updateInterfaceAdm
[45f1fe8]685
[295b4ab]686# Actualizar páqinas web
[3ce53a7]687apacheConfiguration
[a0867b37]688updateWebFiles
689if [ $? -ne 0 ]; then
[da8db11]690        errorAndLog "Error updating OpenGnSys Web Admin files"
[a0867b37]691        exit 1
692fi
[5d6bf97]693# Generar páginas Doxygen para instalar en el web
694makeDoxygenFiles
[a0867b37]695
[bb30a50]696# Recompilar y actualizar los servicios del sistema
697compileServices
698
699# Actaulizar ficheros auxiliares del cliente
[a0867b37]700updateClient
701if [ $? -ne 0 ]; then
702        errorAndLog "Error updating clients"
703        exit 1
704fi
705
[3320409]706# Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
[ebbbfc01]707if [ -f /tmp/dstate ]; then
708        rm -f /tmp/dstate
[3320409]709fi
710
[eb9424f]711# Mostrar resumen de actualización.
712updateSummary
713
[a0867b37]714#rm -rf $WORKDIR
715echoAndLog "OpenGnSys update finished at $(date)"
716
717popd
718
Note: See TracBrowser for help on using the repository browser.