source: installer/opengnsys_update.sh @ e2b08ad

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 e2b08ad was 6354c7b, checked in by ramon <ramongomez@…>, 15 years ago

Instalador detecta correctamente dependencias no instaladas; mejora en rendimiento descarga de paquetes udeb.

git-svn-id: https://opengnsys.es/svn/trunk@925 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 13.5 KB
Line 
1#!/bin/bash
2#/**
3#@file    opengnsys_update.sh
4#@brief   Script actualización de OpenGnSys
5#@warning No se actualiza BD, ni ficheros de configuración.
6#@version 0.9 - basado en opengnsys_installer.sh
7#@author  Ramón Gómez - ETSII Univ. Sevilla
8#@date    2010/01/27
9#*/
10
11
12# Sólo ejecutable por usuario root
13if [ "$(whoami)" != 'root' ]
14then
15        echo "ERROR: this program must run under root privileges!!"
16        exit 1
17fi
18
19# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1).
20PROGRAMDIR=$(readlink -e $(dirname "$0"))
21DEPS="rsync gcc"
22if [ -d "$PROGRAMDIR/../installer" ]; then
23    USESVN=0
24else
25    USESVN=1
26    SVN_URL=svn://www.informatica.us.es:3690/opengnsys/trunk
27    DEPS="$DEPS subversion"
28fi
29
30WORKDIR=/tmp/opengnsys_update
31mkdir -p $WORKDIR
32
33INSTALL_TARGET=/opt/opengnsys
34LOG_FILE=/tmp/opengnsys_update.log
35
36
37
38#####################################################################
39####### Algunas funciones útiles de propósito general:
40#####################################################################
41function getDateTime()
42{
43        echo `date +%Y%m%d-%H%M%S`
44}
45
46# Escribe a fichero y muestra por pantalla
47function echoAndLog()
48{
49        echo $1
50        FECHAHORA=`getDateTime`
51        echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE
52}
53
54function errorAndLog()
55{
56        echo "ERROR: $1"
57        FECHAHORA=`getDateTime`
58        echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
59}
60
61
62#####################################################################
63####### Funciones de copia de seguridad y restauración de ficheros
64#####################################################################
65
66# Hace un backup del fichero pasado por parámetro
67# deja un -last y uno para el día
68function backupFile()
69{
70        if [ $# -ne 1 ]; then
71                errorAndLog "${FUNCNAME}(): invalid number of parameters"
72                exit 1
73        fi
74
75        local fichero=$1
76        local fecha=`date +%Y%m%d`
77
78        if [ ! -f $fichero ]; then
79                errorAndLog "${FUNCNAME}(): file $fichero doesn't exists"
80                return 1
81        fi
82
83    echoAndLog "${FUNCNAME}(): Making $fichero back-up"
84
85        # realiza una copia de la última configuración como last
86        cp -p $fichero "${fichero}-LAST"
87
88        # si para el día no hay backup lo hace, sino no
89        if [ ! -f "${fichero}-${fecha}" ]; then
90                cp -p $fichero "${fichero}-${fecha}"
91        fi
92}
93
94# Restaura un fichero desde su copia de seguridad
95function restoreFile()
96{
97        if [ $# -ne 1 ]; then
98                errorAndLog "${FUNCNAME}(): invalid number of parameters"
99                exit 1
100        fi
101
102        local fichero=$1
103
104    echoAndLog "${FUNCNAME}(): restoring $fichero file"
105        if [ -f "${fichero}-LAST" ]; then
106                cp -p "$fichero-LAST" "$fichero"
107        fi
108}
109
110
111#####################################################################
112####### Funciones de instalación de paquetes
113#####################################################################
114
115# Instalar las deependencias necesarias para el actualizador.
116function installDependencies ()
117{
118        if [ $# = 0 ]; then
119                echoAndLog "${FUNCNAME}(): no deps needed."
120    else
121        while [ $# -gt 0 ]; do
122            dpkg -s $1 | grep Status | grep -qw install &>/dev/null
123            if [ $? -ne 0 ]; then
124                INSTALLDEPS="$INSTALLDEPS $1"
125            fi
126            shift
127        done
128        if [ -n "$INSTALLDEPS" ]; then
129            apt-get update && apt-get install $INSTALLDEPS
130                if [ $? -ne 0 ]; then
131                        errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
132                return 1
133                fi
134        fi
135    fi
136}
137
138
139#####################################################################
140####### Funciones para el manejo de Subversion
141#####################################################################
142
143function svnExportCode()
144{
145        if [ $# -ne 1 ]; then
146                errorAndLog "${FUNCNAME}(): invalid number of parameters"
147                exit 1
148        fi
149
150        local url=$1
151
152        echoAndLog "${FUNCNAME}(): downloading subversion code..."
153
154        svn checkout "${url}" opengnsys
155        if [ $? -ne 0 ]; then
156                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
157                return 1
158        fi
159        echoAndLog "${FUNCNAME}(): subversion code downloaded"
160        return 0
161}
162
163
164############################################################
165###  Detectar red
166############################################################
167
168function getNetworkSettings()
169{
170        local MAINDEV
171
172        echoAndLog "getNetworkSettings(): Detecting default network parameters."
173        MAINDEV=$(ip -o link show up | awk '!/loopback/ {d=d$2} END {sub(/:.*/,"",d); print d}')
174        if [ -z "$MAINDEV" ]; then
175                errorAndLog "${FUNCNAME}(): Network device not detected."
176                return 1
177        fi
178
179        # Variables de ejecución de Apache
180        # - APACHE_RUN_USER
181        # - APACHE_RUN_GROUP
182        if [ -f /etc/apache2/envvars ]; then
183                source /etc/apache2/envvars
184        fi
185        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
186        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
187}
188
189
190#####################################################################
191####### Funciones específicas de la instalación de Opengnsys
192#####################################################################
193
194# Copiar ficheros de arranque de los servicios del sistema de OpenGnSys
195
196function updateServicesStart(){
197        echoAndLog "${FUNCNAME}(): Updating /etc/init.d/opengnsys ..."
198    cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
199        if [ $? != 0 ]; then
200                errorAndLog "${FUNCNAME}(): Error updating /etc/init.d/opengnsys"
201                exit 1
202        fi
203        echoAndLog "${FUNCNAME}(): /etc/init.d/opengnsys updated successfully."
204}
205
206# Copiar ficheros del OpenGnSys Web Console.
207function updateWebFiles()
208{
209        local ERRCODE
210        echoAndLog "${FUNCNAME}(): Updating web files..."
211        backupFile $INSTALL_TARGET/www/controlacceso.php
212        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
213        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
214        ERRCODE=$?
215        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
216        if [ $ERRCODE != 0 ]; then
217                errorAndLog "${FUNCNAME}(): Error updating web files."
218                exit 1
219        fi
220        restoreFile $INSTALL_TARGET/www/controlacceso.php
221        # Cambiar permisos para ficheros especiales.
222        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP \
223                        $INSTALL_TARGET/www/includes \
224                        $INSTALL_TARGET/www/comandos/gestores/filescripts \
225                        $INSTALL_TARGET/www/images/iconos
226        echoAndLog "${FUNCNAME}(): Web files updated successfully."
227}
228
229
230# Crear documentación Doxygen para la consola web.
231function makeDoxygenFiles()
232{
233        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
234        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
235                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
236        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
237                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
238                return 1
239        fi
240        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
241        rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
242        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
243        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
244}
245
246
247# Crea la estructura base de la instalación de opengnsys
248function createDirs()
249{
250        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
251
252        mkdir -p ${INSTALL_TARGET}
253        mkdir -p ${INSTALL_TARGET}/admin/{autoexec,comandos,menus,usuarios}
254        mkdir -p ${INSTALL_TARGET}/bin
255        mkdir -p ${INSTALL_TARGET}/client
256        mkdir -p ${INSTALL_TARGET}/doc
257        mkdir -p ${INSTALL_TARGET}/etc
258        mkdir -p ${INSTALL_TARGET}/lib
259        mkdir -p ${INSTALL_TARGET}/log/clients
260        mkdir -p ${INSTALL_TARGET}/sbin
261        mkdir -p ${INSTALL_TARGET}/www
262        mkdir -p ${INSTALL_TARGET}/images
263        ln -fs /var/lib/tftpboot ${INSTALL_TARGET}
264        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
265
266        if [ $? -ne 0 ]; then
267                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
268                return 1
269        fi
270
271        echoAndLog "${FUNCNAME}(): directory paths created"
272        return 0
273}
274
275# Copia ficheros de configuración y ejecutables genéricos del servidor.
276function updateServerFiles () {
277
278        local SOURCES=( client/boot/initrd-generator \
279                        client/boot/upgrade-clients-udeb.sh \
280                        client/boot/udeblist.conf  \
281                        client/boot/udeblist-jaunty.conf  \
282                        client/boot/udeblist-karmic.conf \
283                        client/boot/udeblist-lucid.conf \
284                        doc )
285        local TARGETS=( bin/initrd-generator \
286                        bin/upgrade-clients-udeb.sh \
287                        etc/udeblist.conf \
288                        etc/udeblist-jaunty.conf  \
289                        etc/udeblist-karmic.conf \
290                        etc/udeblist-lucid.conf \
291                        doc )
292
293        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
294                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
295                exit 1
296        fi
297
298        echoAndLog "${FUNCNAME}(): updating files in server directories"
299        pushd $WORKDIR/opengnsys >/dev/null
300        local i
301        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
302                rsync --exclude .svn -irplt "${SOURCES[$i]}" "${INSTALL_TARGET}/${TARGETS[$i]}"
303        done
304        popd >/dev/null
305    echoAndLog "${FUNCNAME}(): server files updated successfully."
306}
307
308####################################################################
309### Funciones de compilación de código fuente de servicios
310####################################################################
311
312# Recompilar y actualiza el binario del clinete
313function recompileClient ()
314{
315        # Compilar OpenGnSys Client
316        echoAndLog "${FUNCNAME}(): recompiling OpenGnSys Client"
317        pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
318        make && mv ogAdmClient ../../../client/nfsexport/bin
319        if [ $? -ne 0 ]; then
320                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client"
321                hayErrores=1
322        fi
323        popd
324
325        return $hayErrores
326}
327
328
329####################################################################
330### Funciones instalacion cliente opengnsys
331####################################################################
332
333function updateClient()
334{
335        local OSDISTRIB OSCODENAME
336
337        local hayErrores=0
338
339        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
340        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
341        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
342        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
343        rsync -iplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
344        if [ $? -ne 0 ]; then
345                errorAndLog "${FUNCNAME}(): error while copying engine files"
346                hayErrores=1
347        fi
348
349        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
350        OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
351        OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
352        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
353                echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
354                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
355                if [ $? -ne 0 ]; then
356                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
357                        hayErrores=1
358                fi
359                echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
360                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
361                if [ $? -ne 0 ]; then
362                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
363                        hayErrores=1
364                fi
365        else
366                echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
367                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
368                if [ $? -ne 0 ]; then
369                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
370                        hayErrores=1
371                fi
372                echoAndLog "${FUNCNAME}(): Loading default udeb files."
373                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh
374                if [ $? -ne 0 ]; then
375                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
376                        hayErrores=1
377                fi
378        fi
379
380        if [ $hayErrores -eq 0 ]; then
381                echoAndLog "${FUNCNAME}(): Client generation success."
382        else
383                errorAndLog "${FUNCNAME}(): Client generation with errors"
384        fi
385
386        return $hayErrores
387}
388
389
390
391#####################################################################
392####### Proceso de actualización de OpenGnSys
393#####################################################################
394
395
396echoAndLog "OpenGnSys update begins at $(date)"
397
398# Instalar dependencia.
399installDependencies $DEPS
400if [ $? -ne 0 ]; then
401        errorAndLog "Error: you may install all needed dependencies."
402        exit 1
403fi
404
405pushd $WORKDIR
406
407# Detectar parámetros de red por defecto
408getNetworkSettings
409if [ $? -ne 0 ]; then
410        errorAndLog "Error reading default network settings."
411        exit 1
412fi
413
414# Arbol de directorios de OpenGnSys.
415createDirs ${INSTALL_TARGET}
416if [ $? -ne 0 ]; then
417        errorAndLog "Error while creating directory paths!"
418        exit 1
419fi
420
421# Si es necesario, descarga el repositorio de código en directorio temporal
422if [ $USESVN -eq 1 ]; then
423        svnExportCode $SVN_URL
424        if [ $? -ne 0 ]; then
425                errorAndLog "Error while getting code from svn"
426                exit 1
427        fi
428else
429        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
430fi
431
432# Copiando ficheros complementarios del servidor
433updateServerFiles
434if [ $? -ne 0 ]; then
435    errorAndLog "Error updating OpenGnSys Server files"
436        exit 1
437fi
438
439# Copiando paqinas web
440updateWebFiles
441if [ $? -ne 0 ]; then
442    errorAndLog "Error updating OpenGnSys Web Admin files"
443        exit 1
444fi
445# Generar páginas Doxygen para instalar en el web
446makeDoxygenFiles
447
448# Creando la estructura del cliente
449recompileClient
450updateClient
451if [ $? -ne 0 ]; then
452        errorAndLog "Error updating clients"
453        exit 1
454fi
455
456# Actualizamos el fichero que arranca los servicios de OpenGnSys
457
458updateServicesStart
459
460# Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
461if [ -r /tmp/dstate ]
462then
463    rm /tmp/dstate
464fi
465
466#rm -rf $WORKDIR
467echoAndLog "OpenGnSys update finished at $(date)"
468
469popd
470
Note: See TracBrowser for help on using the repository browser.