source: installer/opengnsys_update.sh @ d655cc4

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

Corrección en actualizar consola; cliente detecta versión del browser.

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

  • Property mode set to 100755
File size: 13.3 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            if ! dpkg -s $1 &>/dev/null; then
123                INSTALLDEPS="$INSTALLDEPS $1"
124            fi
125            shift
126        done
127        if [ -n "$INSTALLDEPS" ]; then
128            apt-get update && apt-get install $INSTALLDEPS
129                if [ $? -ne 0 ]; then
130                        errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
131                return 1
132                fi
133        fi
134    fi
135}
136
137
138#####################################################################
139####### Funciones para el manejo de Subversion
140#####################################################################
141
142function svnExportCode()
143{
144        if [ $# -ne 1 ]; then
145                errorAndLog "${FUNCNAME}(): invalid number of parameters"
146                exit 1
147        fi
148
149        local url=$1
150
151        echoAndLog "${FUNCNAME}(): downloading subversion code..."
152
153        svn checkout "${url}" opengnsys
154        if [ $? -ne 0 ]; then
155                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
156                return 1
157        fi
158        echoAndLog "${FUNCNAME}(): subversion code downloaded"
159        return 0
160}
161
162
163############################################################
164###  Detectar red
165############################################################
166
167function getNetworkSettings()
168{
169        local MAINDEV
170
171        echoAndLog "getNetworkSettings(): Detecting default network parameters."
172        MAINDEV=$(ip -o link show up | awk '!/loopback/ {d=d$2} END {sub(/:.*/,"",d); print d}')
173        if [ -z "$MAINDEV" ]; then
174                errorAndLog "${FUNCNAME}(): Network device not detected."
175                return 1
176        fi
177
178        # Variables de ejecución de Apache
179        # - APACHE_RUN_USER
180        # - APACHE_RUN_GROUP
181        if [ -f /etc/apache2/envvars ]; then
182                source /etc/apache2/envvars
183        fi
184        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
185        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
186}
187
188
189#####################################################################
190####### Funciones específicas de la instalación de Opengnsys
191#####################################################################
192
193# Copiar ficheros de arranque de los servicios del sistema de OpenGnSys
194
195function updateServicesStart(){
196        echoAndLog "${FUNCNAME}(): Updating /etc/init.d/opengnsys ..."
197    cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
198        if [ $? != 0 ]; then
199                errorAndLog "${FUNCNAME}(): Error updating /etc/init.d/opengnsys"
200                exit 1
201        fi
202        echoAndLog "${FUNCNAME}(): /etc/init.d/opengnsys updated successfully."
203}
204
205# Copiar ficheros del OpenGnSys Web Console.
206function updateWebFiles()
207{
208        local ERRCODE
209        echoAndLog "${FUNCNAME}(): Updating web files..."
210        backupFile $INSTALL_TARGET/www/controlacceso.php
211        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
212        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET/www
213        ERRCODE=$?
214        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
215        if [ $ERRCODE != 0 ]; then
216                errorAndLog "${FUNCNAME}(): Error updating web files."
217                exit 1
218        fi
219        restoreFile $INSTALL_TARGET/www/controlacceso.php
220        # Cambiar permisos para ficheros especiales.
221        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP \
222                        $INSTALL_TARGET/www/includes \
223                        $INSTALL_TARGET/www/comandos/gestores/filescripts \
224                        $INSTALL_TARGET/www/images/iconos
225        echoAndLog "${FUNCNAME}(): Web files updated successfully."
226}
227
228
229# Crear documentación Doxygen para la consola web.
230function makeDoxygenFiles()
231{
232        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
233        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
234                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
235        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
236                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
237                return 1
238        fi
239        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
240        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
241        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
242}
243
244
245# Crea la estructura base de la instalación de opengnsys
246function createDirs()
247{
248        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
249
250        mkdir -p ${INSTALL_TARGET}
251        mkdir -p ${INSTALL_TARGET}/admin/{autoexec,comandos,menus,usuarios}
252        mkdir -p ${INSTALL_TARGET}/bin
253        mkdir -p ${INSTALL_TARGET}/client
254        mkdir -p ${INSTALL_TARGET}/doc
255        mkdir -p ${INSTALL_TARGET}/etc
256        mkdir -p ${INSTALL_TARGET}/lib
257        mkdir -p ${INSTALL_TARGET}/log/clients
258        mkdir -p ${INSTALL_TARGET}/sbin
259        mkdir -p ${INSTALL_TARGET}/www
260        mkdir -p ${INSTALL_TARGET}/images
261        ln -fs /var/lib/tftpboot ${INSTALL_TARGET}
262        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
263
264        if [ $? -ne 0 ]; then
265                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
266                return 1
267        fi
268
269        echoAndLog "${FUNCNAME}(): directory paths created"
270        return 0
271}
272
273# Copia ficheros de configuración y ejecutables genéricos del servidor.
274function updateServerFiles () {
275
276        local SOURCES=( client/boot/initrd-generator \
277                        client/boot/upgrade-clients-udeb.sh \
278                        client/boot/udeblist.conf  \
279                        client/boot/udeblist-jaunty.conf  \
280                        client/boot/udeblist-karmic.conf \
281                        doc )
282        local TARGETS=( bin/initrd-generator \
283                        bin/upgrade-clients-udeb.sh \
284                        etc/udeblist.conf \
285                        etc/udeblist-jaunty.conf  \
286                        etc/udeblist-karmic.conf \
287                        doc )
288
289        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
290                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
291                exit 1
292        fi
293
294        echoAndLog "${FUNCNAME}(): updating files in server directories"
295        pushd $WORKDIR/opengnsys >/dev/null
296        local i
297        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
298                rsync --exclude .svn -irplt "${SOURCES[$i]}" "${INSTALL_TARGET}/${TARGETS[$i]}"
299        done
300        popd >/dev/null
301    echoAndLog "${FUNCNAME}(): server files updated successfully."
302}
303
304####################################################################
305### Funciones de compilación de código fuente de servicios
306####################################################################
307
308# Recompilar y actualiza el binario del clinete
309function recompileClient ()
310{
311        # Compilar OpenGnSys Client
312        echoAndLog "${FUNCNAME}(): recompiling OpenGnSys Client"
313        pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
314        make && mv ogAdmClient ../../../client/nfsexport/bin
315        if [ $? -ne 0 ]; then
316                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client"
317                hayErrores=1
318        fi
319        popd
320
321        return $hayErrores
322}
323
324
325####################################################################
326### Funciones instalacion cliente opengnsys
327####################################################################
328
329function updateClient()
330{
331        local OSDISTRIB OSCODENAME
332
333        local hayErrores=0
334
335        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
336        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
337        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
338        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
339        rsync -iplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
340        if [ $? -ne 0 ]; then
341                errorAndLog "${FUNCNAME}(): error while copying engine files"
342                hayErrores=1
343        fi
344
345        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
346        OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
347        OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
348        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
349                echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
350                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
351                if [ $? -ne 0 ]; then
352                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
353                        hayErrores=1
354                fi
355                echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
356                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
357                if [ $? -ne 0 ]; then
358                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
359                        hayErrores=1
360                fi
361        else
362                echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
363                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
364                if [ $? -ne 0 ]; then
365                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
366                        hayErrores=1
367                fi
368                echoAndLog "${FUNCNAME}(): Loading default udeb files."
369                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh
370                if [ $? -ne 0 ]; then
371                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
372                        hayErrores=1
373                fi
374        fi
375
376        if [ $hayErrores -eq 0 ]; then
377                echoAndLog "${FUNCNAME}(): Client generation success."
378        else
379                errorAndLog "${FUNCNAME}(): Client generation with errors"
380        fi
381
382        return $hayErrores
383}
384
385
386
387#####################################################################
388####### Proceso de actualización de OpenGnSys
389#####################################################################
390
391
392echoAndLog "OpenGnSys update begins at $(date)"
393
394# Instalar dependencia.
395installDependencies $DEPS
396if [ $? -ne 0 ]; then
397        errorAndLog "Error: you may install all needed dependencies."
398        exit 1
399fi
400
401pushd $WORKDIR
402
403# Detectar parámetros de red por defecto
404getNetworkSettings
405if [ $? -ne 0 ]; then
406        errorAndLog "Error reading default network settings."
407        exit 1
408fi
409
410# Arbol de directorios de OpenGnSys.
411createDirs ${INSTALL_TARGET}
412if [ $? -ne 0 ]; then
413        errorAndLog "Error while creating directory paths!"
414        exit 1
415fi
416
417# Si es necesario, descarga el repositorio de código en directorio temporal
418if [ $USESVN -eq 1 ]; then
419        svnExportCode $SVN_URL
420        if [ $? -ne 0 ]; then
421                errorAndLog "Error while getting code from svn"
422                exit 1
423        fi
424else
425        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
426fi
427
428# Copiando ficheros complementarios del servidor
429updateServerFiles
430if [ $? -ne 0 ]; then
431    errorAndLog "Error updating OpenGnSys Server files"
432        exit 1
433fi
434
435# Copiando paqinas web
436updateWebFiles
437if [ $? -ne 0 ]; then
438    errorAndLog "Error updating OpenGnSys Web Admin files"
439        exit 1
440fi
441# Generar páginas Doxygen para instalar en el web
442makeDoxygenFiles
443
444# Creando la estructura del cliente
445recompileClient
446updateClient
447if [ $? -ne 0 ]; then
448        errorAndLog "Error updating clients"
449        exit 1
450fi
451
452# Actualizamos el fichero que arranca los servicios de OpenGnSys
453
454updateServicesStart
455
456# Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
457if [ -r /tmp/dstate ]
458then
459    rm /tmp/dstate
460fi
461
462#rm -rf $WORKDIR
463echoAndLog "OpenGnSys update finished at $(date)"
464
465popd
466
Note: See TracBrowser for help on using the repository browser.