source: installer/opengnsys_update.sh @ a2649b0

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 a2649b0 was 6ef01d9, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: El instalador permite cambiar la clave por defecto del usuario Samba; limpieza de scripts de instlación, actualización y arranque (modifica #428 y #446).

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

  • Property mode set to 100755
File size: 22.0 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
[cf2142ea]267# Copiar ficheros de arranque de los servicios del sistema de OpenGnSys
[64dd765]268function updateServicesStart()
269{
[6ef01d9]270        local initfile=/etc/init.d/opengnsyso
271
272        if ! diff --quiet $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init $initfile 2>/dev/null; then
273                echoAndLog "${FUNCNAME}(): Copying OpenGnSys init file in $initfile.new"
274                cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init $initfile.new
275                if [ $? != 0 ]; then
276                        errorAndLog "${FUNCNAME}(): Error copying $initfile.new"
277                        exit 1
278                fi
279                echoAndLog "${FUNCNAME}(): Check the new init files."
[cf2142ea]280        fi
281}
282
[45f1fe8]283# Actualizar cliente OpenGnSys
[295b4ab]284function updateClientFiles()
[45f1fe8]285{
286        echoAndLog "${FUNCNAME}(): Updating OpenGnSys Client files."
287        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
288        if [ $? -ne 0 ]; then
289                errorAndLog "${FUNCNAME}(): error while updating client structure"
[51b179a]290                exit 1
[45f1fe8]291        fi
292        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
293       
294        echoAndLog "${FUNCNAME}(): Updating OpenGnSys Cloning Engine files."
[51b179a]295        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
[45f1fe8]296        if [ $? -ne 0 ]; then
297                errorAndLog "${FUNCNAME}(): error while updating engine files"
[51b179a]298                exit 1
[45f1fe8]299        fi
300       
[51b179a]301        echoAndLog "${FUNCNAME}(): client files update success."
[45f1fe8]302}
[4e51cb0]303
[3ce53a7]304# Configurar HTTPS y exportar usuario y grupo del servicio Apache.
305function apacheConfiguration ()
[4e51cb0]306{
[3ce53a7]307        local APACHECONF=/etc/apache2
308
309        # Activar HTTPS, si es necesario.
310        if [ -e $APACHECONF/sites-available/opengnsys.conf ]; then
311                echoAndLog "${FUNCNAME}(): Configuring HTTPS access..."
312                mv $APACHECONF/sites-available/opengnsys.conf $APACHECONF/sites-available/opengnsys
313                a2ensite default-ssl
314                a2enmod ssl
[3e24aa5]315                a2dissite opengnsys.conf
[3ce53a7]316                a2ensite opengnsys
317                /etc/init.d/apache2 restart
318        fi
319
320        # Variables de ejecución de Apache.
[4e51cb0]321        # - APACHE_RUN_USER
322        # - APACHE_RUN_GROUP
[3ce53a7]323        if [ -f $APACHECONF/envvars ]; then
324                source $APACHECONF/envvars
[4e51cb0]325        fi
326        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
327        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
328}
329
[a0867b37]330# Copiar ficheros del OpenGnSys Web Console.
331function updateWebFiles()
332{
[d655cc4]333        local ERRCODE
[a0867b37]334        echoAndLog "${FUNCNAME}(): Updating web files..."
[d655cc4]335        backupFile $INSTALL_TARGET/www/controlacceso.php
336        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
[1db2ed8]337        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
[d655cc4]338        ERRCODE=$?
339        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
[c1e00e4]340        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
[d655cc4]341        if [ $ERRCODE != 0 ]; then
[a0867b37]342                errorAndLog "${FUNCNAME}(): Error updating web files."
343                exit 1
344        fi
[d655cc4]345        restoreFile $INSTALL_TARGET/www/controlacceso.php
[a0867b37]346        # Cambiar permisos para ficheros especiales.
[ebbbfc01]347        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/includes $INSTALL_TARGET/www/images/iconos
[a0867b37]348        echoAndLog "${FUNCNAME}(): Web files updated successfully."
349}
350
[72134d5]351# Copiar carpeta de Interface
[64dd765]352function updateInterfaceAdm()
[72134d5]353{
[27dc5ff]354        local errcode=0
[72134d5]355         
356        # Crear carpeta y copiar Interface
357        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
358        mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface
359        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client
[27dc5ff]360        errcoce=$?
[72134d5]361        mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm
[27dc5ff]362        if [ $errcode -ne 0 ]; then
[72134d5]363                echoAndLog "${FUNCNAME}(): error while updating admin interface"
364                exit 1
365        fi
366        chmod -R +x $INSTALL_TARGET/client/interfaceAdm
[b6f1726]367        chown $OPENGNSYS_CLIENTUSER:$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[f6c1d2b]368        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[72134d5]369        echoAndLog "${FUNCNAME}(): Admin interface updated successfully."
370}
[a0867b37]371
[5d6bf97]372# Crear documentación Doxygen para la consola web.
373function makeDoxygenFiles()
374{
375        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
376        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
377                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
378        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
379                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
380                return 1
381        fi
[45f1fe8]382        rm -fr "$INSTALL_TARGET/www/api"
[15b2a4e]383        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
384        rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
[5d6bf97]385        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
386        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
387}
388
389
[a0867b37]390# Crea la estructura base de la instalación de opengnsys
391function createDirs()
392{
[eb9424f]393        # Crear estructura de directorios.
[a0867b37]394        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
[cfad47b]395        mkdir -p ${INSTALL_TARGET}/{bin,doc,etc,lib,sbin,www}
396        mkdir -p ${INSTALL_TARGET}/{client,images}
[a0867b37]397        mkdir -p ${INSTALL_TARGET}/log/clients
[eb9424f]398        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
[a0867b37]399        ln -fs /var/lib/tftpboot ${INSTALL_TARGET}
[cfad47b]400        mkdir -p ${INSTALL_TARGET}/tftpboot/{pxelinux.cfg,menu.lst}
[a0867b37]401        if [ $? -ne 0 ]; then
402                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
403                return 1
404        fi
405
[eb9424f]406        # Crear usuario ficticio.
407        if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then
408                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created"
409        else
410                echoAndLog "${FUNCNAME}(): creating OpenGnSys user"
411                useradd $OPENGNSYS_CLIENTUSER 2>/dev/null
412                if [ $? -ne 0 ]; then
413                        errorAndLog "${FUNCNAME}(): error creating OpenGnSys user"
414                        return 1
415                fi
416        fi
417
418        # Establecer los permisos básicos.
419        echoAndLog "${FUNCNAME}(): setting directory permissions"
[cfad47b]420        chmod -R 775 $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg,tftpboot/menu.lst}
421        chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg,tftpboot/menu.lst}
[eb9424f]422        if [ $? -ne 0 ]; then
423                errorAndLog "${FUNCNAME}(): error while setting permissions"
424                return 1
425        fi
426
[a0867b37]427        echoAndLog "${FUNCNAME}(): directory paths created"
428        return 0
429}
430
431# Copia ficheros de configuración y ejecutables genéricos del servidor.
[64dd765]432function updateServerFiles()
[bb30a50]433{
[c1e00e4]434        # No copiar ficheros del antiguo cliente Initrd
[873cf1e]435        local SOURCES=( repoman/bin \
[c1e00e4]436                        server/bin \
[873cf1e]437                        server/tftpboot \
[bb30a50]438                        installer/opengnsys_uninstall.sh \
[873cf1e]439                        doc )
440        local TARGETS=( bin \
441                        bin \
442                        tftpboot \
[4057c5d]443                        lib/opengnsys_uninstall.sh \
[873cf1e]444                        doc )
[a0867b37]445
446        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
447                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
448                exit 1
449        fi
450
451        echoAndLog "${FUNCNAME}(): updating files in server directories"
452        pushd $WORKDIR/opengnsys >/dev/null
453        local i
454        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
[27dc5ff]455                if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then
[4057c5d]456                        rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}"))
[aa36857]457                else
[4057c5d]458                        rsync --exclude .svn -irplt "${SOURCES[i]}" $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}")
[aa36857]459                fi
[a0867b37]460        done
461        popd >/dev/null
[75a296b]462        echoAndLog "${FUNCNAME}(): updating DHCP files"
[f80f839]463        if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then
464                perl -pi -e 's/pxelinux.0/grldr/' /etc/dhcp*/dhcpd*.conf
465                for i in isc-dhcp-server dhcpd3-server dhcpd; do
466                        [ -f /etc/init.d/$i ] && /etc/init.d/$i restart
467                done
468        fi
[9ee62ad]469        echoAndLog "${FUNCNAME}(): updating cron files"
[57cf15b]470        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys
[9ee62ad]471        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
[da8db11]472        echoAndLog "${FUNCNAME}(): server files updated successfully."
[a0867b37]473}
474
475####################################################################
476### Funciones de compilación de código fuente de servicios
477####################################################################
478
[bb30a50]479# Recompilar y actualiza los serivicios y clientes.
[64dd765]480function compileServices()
[a0867b37]481{
[bb30a50]482        local hayErrores=0
483
484        # Compilar OpenGnSys Server
485        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Admin Server"
486        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
487        make && mv ogAdmServer $INSTALL_TARGET/sbin
488        if [ $? -ne 0 ]; then
489                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
490                hayErrores=1
491        fi
492        popd
493        # Compilar OpenGnSys Repository Manager
494        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Repository Manager"
495        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
496        make && mv ogAdmRepo $INSTALL_TARGET/sbin
497        if [ $? -ne 0 ]; then
498                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
499                hayErrores=1
500        fi
501        popd
502        # Compilar OpenGnSys Agent
503        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Agent"
504        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
505        make && mv ogAdmAgent $INSTALL_TARGET/sbin
506        if [ $? -ne 0 ]; then
507                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent"
508                hayErrores=1
509        fi
510        popd
511
[a0867b37]512        # Compilar OpenGnSys Client
[bb30a50]513        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Client"
[72134d5]514        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[e473667]515        make && mv ogAdmClient $INSTALL_TARGET/client/bin
[a0867b37]516        if [ $? -ne 0 ]; then
517                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client"
518                hayErrores=1
519        fi
520        popd
521
522        return $hayErrores
523}
524
525
526####################################################################
[4e51cb0]527### Funciones instalacion cliente OpenGnSys
[a0867b37]528####################################################################
529
[c1e00e4]530# Actualizar nuevo cliente para OpenGnSys 1.0
531function updateClient()
532{
[d168a46]533        local DOWNLOADURL="http://www.opengnsys.es/downloads"
[fe293a7]534        local FILENAME=ogLive-natty-2.6.38-8-generic-pae-r2303.iso
[0b85cc93]535        local SOURCEFILE=$DOWNLOADURL/$FILENAME
536        local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
537        local SOURCELENGTH
538        local TARGETLENGTH
539        local TMPDIR=/tmp/${FILENAME%.iso}
[a63345ac]540        local OGINITRD=$INSTALL_TARGET/tftpboot/ogclient/oginitrd.img
541        local SAMBAPASS
[0b85cc93]542
543        # Comprobar si debe actualizarse el cliente.
[c3cc6b0]544        SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}')
[d168a46]545        TARGETLENGTH=$(ls -l $TARGETFILE 2>/dev/null | awk '{print $5}')
[d4e90c1]546        [ -z $TARGETLENGTH ] && TARGETLENGTH=0
[0b85cc93]547        if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then
548                echoAndLog "${FUNCNAME}(): Loading Client"
549                wget $DOWNLOADURL/$FILENAME -O $TARGETFILE
550                if [ ! -s $TARGETFILE ]; then
551                        errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client"
552                        return 1
553                fi
[a63345ac]554                # Obtener la clave actual de acceso a Samba para restaurarla.
555                if [ -f $OGINITRD ]; then
556                        SAMBAPASS=$(gzip -dc $OGINITRD | \
557                                    cpio -i --to-stdout scripts/ogfunctions 2>&1 | \
[c3cc6b0]558                                    grep "^[    ]*OPTIONS=" | \
[a63345ac]559                                    sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')
560                fi
561                # Montar la imagen ISO del ogclient, actualizar ficheros y desmontar.
562                echoAndLog "${FUNCNAME}(): Updatting ogclient files"
563                mkdir -p $TMPDIR
564                mount -o loop,ro $TARGETFILE $TMPDIR
565                rsync -irlt $TMPDIR/ogclient $INSTALL_TARGET/tftpboot
566                umount $TMPDIR
567                rmdir $TMPDIR
568                # Recuperar la clave de acceso a Samba.
569                if [ -n "$SAMBAPASS" ]; then
570                        echoAndLog "${FUNCNAME}(): Restoring client access key"
571                        echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | \
572                                        $INSTALL_TARGET/bin/setsmbpass
573                fi
574                # Establecer los permisos.
575                find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \;
576                find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \;
577                chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient
578                chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg}
[e1c01217]579               
[e8963d0]580                # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache
[6ef01d9]581                cp -arv $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot
582                cp -arv $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot
[e1c01217]583               
[a63345ac]584                echoAndLog "${FUNCNAME}(): Client update successfully"
[0b85cc93]585        else
[a63345ac]586                echoAndLog "${FUNCNAME}(): Client is already updated"
[c1e00e4]587        fi
588}
[a0867b37]589
[eb9424f]590# Resumen de actualización.
591function updateSummary()
592{
593        # Actualizar fichero de versión y revisión.
594        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
595        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Revision:/ {print "r"$2}')
596
597        [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE
598        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
599
600        echo
601        echoAndLog "OpenGnSys Update Summary"
602        echo       "========================"
603        echoAndLog "Project version:                  $(cat $VERSIONFILE)"
604        echo
605}
606
607
[a0867b37]608
609#####################################################################
[3320409]610####### Proceso de actualización de OpenGnSys
[a0867b37]611#####################################################################
612
613
614echoAndLog "OpenGnSys update begins at $(date)"
615
[bb30a50]616pushd $WORKDIR
617
[27dc5ff]618# Comprobar si hay conexión y detectar parámetros de red por defecto.
619checkNetworkConnection
620if [ $? -ne 0 ]; then
621        errorAndLog "Error connecting to server. Causes:"
622        errorAndLog " - Network is unreachable, review devices parameters."
623        errorAndLog " - You are inside a private network, configure the proxy service."
624        errorAndLog " - Server is temporally down, try agian later."
625        exit 1
626fi
627
[64dd765]628# Comprobar auto-actualización del programa.
629if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
630        checkAutoUpdate
631        if [ $? -ne 0 ]; then
[f580c51]632                echoAndLog "OpenGnSys updater has been overwritten."
633                echoAndLog "Please, re-execute this script."
[64dd765]634                exit
635        fi
636fi
637
[bb30a50]638# Instalar dependencias.
[a0867b37]639installDependencies $DEPS
640if [ $? -ne 0 ]; then
641        errorAndLog "Error: you may install all needed dependencies."
642        exit 1
643fi
644
645# Arbol de directorios de OpenGnSys.
646createDirs ${INSTALL_TARGET}
647if [ $? -ne 0 ]; then
648        errorAndLog "Error while creating directory paths!"
649        exit 1
650fi
651
652# Si es necesario, descarga el repositorio de código en directorio temporal
653if [ $USESVN -eq 1 ]; then
654        svnExportCode $SVN_URL
655        if [ $? -ne 0 ]; then
656                errorAndLog "Error while getting code from svn"
657                exit 1
658        fi
659else
660        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
661fi
662
[295b4ab]663# Si existe fichero de actualización de la base de datos; aplicar cambios.
664INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
665REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
666OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
667if [ -f $OPENGNSYS_DBUPDATEFILE ]; then
668        echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION"
669        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE
670else
671        echoAndLog "Database unchanged."
672fi
673
674# Actualizar ficheros complementarios del servidor
[a0867b37]675updateServerFiles
676if [ $? -ne 0 ]; then
[da8db11]677        errorAndLog "Error updating OpenGnSys Server files"
[a0867b37]678        exit 1
679fi
680
[295b4ab]681# Actualizar ficheros del cliente
682updateClientFiles
683updateInterfaceAdm
[45f1fe8]684
[295b4ab]685# Actualizar páqinas web
[3ce53a7]686apacheConfiguration
[a0867b37]687updateWebFiles
688if [ $? -ne 0 ]; then
[da8db11]689        errorAndLog "Error updating OpenGnSys Web Admin files"
[a0867b37]690        exit 1
691fi
[5d6bf97]692# Generar páginas Doxygen para instalar en el web
693makeDoxygenFiles
[a0867b37]694
[bb30a50]695# Recompilar y actualizar los servicios del sistema
696compileServices
697
698# Actaulizar ficheros auxiliares del cliente
[a0867b37]699updateClient
700if [ $? -ne 0 ]; then
701        errorAndLog "Error updating clients"
702        exit 1
703fi
704
[95f1f68]705# Actualizamos el fichero que arranca los servicios de OpenGnSys
706updateServicesStart
707
[3320409]708# Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
[ebbbfc01]709if [ -f /tmp/dstate ]; then
710        rm -f /tmp/dstate
[3320409]711fi
712
[eb9424f]713# Mostrar resumen de actualización.
714updateSummary
715
[a0867b37]716#rm -rf $WORKDIR
717echoAndLog "OpenGnSys update finished at $(date)"
718
719popd
720
Note: See TracBrowser for help on using the repository browser.