source: installer/opengnsys_update.sh @ bf59ef1

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 bf59ef1 was 993c328, checked in by ramon <ramongomez@…>, 11 years ago

#616: Actualizar usando ogLive 1.0.4.

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

  • Property mode set to 100755
File size: 28.5 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
[739fb00]15#@version 1.0.2a - obtiene valor de dirección IP por defecto
16#@author  Ramón Gómez - ETSII Univ. Sevilla
17#@date    2012/01/18
[1175096]18#@version 1.0.3 - Compatibilidad con Debian y auto configuración de acceso a BD.
[7bb72f7]19#@author  Ramón Gómez - ETSII Univ. Sevilla
[1175096]20#@date    2012/03/12
[db9e706]21#@version 1.0.4 - Detector de distribución y compatibilidad con CentOS.
22#@author  Ramón Gómez - ETSII Univ. Sevilla
23#@date    2012/05/04
[dc103b6]24#@version 1.0.5 - Actualizar BD en la misma versión y compatibilidad con Fedora (systemd).
[0b8a1f1]25#@author  Ramón Gómez - ETSII Univ. Sevilla
26#@date    2012/12/14
[a0867b37]27#*/
28
29
[1175096]30####  AVISO: NO EDITAR variables de configuración.
31####  WARNING: DO NOT EDIT configuration variables.
32INSTALL_TARGET=/opt/opengnsys           # Directorio de instalación
[295b4ab]33OPENGNSYS_CLIENTUSER="opengnsys"        # Usuario Samba
34
35
[a0867b37]36# Sólo ejecutable por usuario root
[6ef01d9]37if [ "$(whoami)" != 'root' ]; then
[a0867b37]38        echo "ERROR: this program must run under root privileges!!"
39        exit 1
40fi
[4e51cb0]41# Error si OpenGnSys no está instalado (no existe el directorio del proyecto)
42if [ ! -d $INSTALL_TARGET ]; then
43        echo "ERROR: OpenGnSys is not installed, cannot update!!"
44        exit 1
45fi
[1175096]46# Cargar configuración de acceso a la base de datos.
47if [ -r $INSTALL_TARGET/etc/ogAdmServer.cfg ]; then
48        source $INSTALL_TARGET/etc/ogAdmServer.cfg
49elif [ -r $INSTALL_TARGET/etc/ogAdmAgent.cfg ]; then
50        source $INSTALL_TARGET/etc/ogAdmAgent.cfg
51fi
[42a0e41]52OPENGNSYS_DATABASE=${OPENGNSYS_DATABASE:-"$CATALOG"}            # Base de datos
[1175096]53OPENGNSYS_DBUSER=${OPENGNSYS_DBUSER:-"$USUARIO"}                # Usuario de acceso
54OPENGNSYS_DBPASSWORD=${OPENGNSYS_DBPASSWORD:-"$PASSWORD"}       # Clave del usuario
55if [ -z "$OPENGNSYS_DATABASE" -o -z "$OPENGNSYS_DBUSER" -o -z "$OPENGNSYS_DBPASSWORD" ]; then
56        echo "ERROR: set OPENGNSYS_DATABASE, OPENGNSYS_DBUSER and OPENGNSYS_DBPASSWORD"
57        echo "       variables, and run this script again."
58fi
[a0867b37]59
60# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1).
61PROGRAMDIR=$(readlink -e $(dirname "$0"))
[64dd765]62PROGRAMNAME=$(basename "$0")
[07c3a59]63OPENGNSYS_SERVER="www.opengnsys.es"
[a0867b37]64if [ -d "$PROGRAMDIR/../installer" ]; then
[6ef01d9]65        USESVN=0
[a0867b37]66else
[6ef01d9]67        USESVN=1
[a0867b37]68fi
[eb9424f]69SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/"
[a0867b37]70
71WORKDIR=/tmp/opengnsys_update
72mkdir -p $WORKDIR
73
[42a0e41]74# Registro de incidencias.
75OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log
[57f7e9c]76LOG_FILE=/tmp/$(basename $OGLOGFILE)
[a0867b37]77
78
79
80#####################################################################
81####### Algunas funciones útiles de propósito general:
82#####################################################################
[295b4ab]83
[db9e706]84# Generar variables de configuración del actualizador
85# Variables globales:
[2e38f60]86# - OSDISTRIB - distribución Linux
[db9e706]87# - DEPENDENCIES - array de dependencias que deben estar instaladas
88# - UPDATEPKGLIST, INSTALLPKGS, CHECKPKG - comandos para gestión de paquetes
[2e38f60]89# - APACHECFGDIR, APACHESERV, DHCPSERV - configuración y servicios
[db9e706]90function autoConfigure()
91{
[2e38f60]92local i
93
[db9e706]94# Detectar sistema operativo del servidor (debe soportar LSB).
95OSDISTRIB=$(lsb_release -is 2>/dev/null)
96
97# Configuración según la distribución de Linux.
98case "$OSDISTRIB" in
99        Ubuntu|Debian|LinuxMint)
[ef99606]100                DEPENDENCIES=( php5-ldap xinetd rsync btrfs-tools )
[db9e706]101                UPDATEPKGLIST="apt-get update"
102                INSTALLPKGS="apt-get -y install --force-yes"
103                CHECKPKG="dpkg -s \$package 2>/dev/null | grep -q \"Status: install ok\""
[4b96166]104                if which service &>/dev/null; then
105                        STARTSERVICE="eval service \$service restart"
106                else
107                        STARTSERVICE="eval /etc/init.d/\$service restart"
108                fi
109                ENABLESERVICE="eval update-rc.d \$service defaults"
[2e38f60]110                APACHEUSER="www-data"
111                APACHEGROUP="www-data"
[db9e706]112                ;;
113        Fedora|CentOS)
[ef99606]114                DEPENDENCIES=( php-ldap xinetd rsync btrfs-progs )
[db9e706]115                INSTALLPKGS="yum install -y"
116                CHECKPKG="rpm -q --quiet \$package"
[4b96166]117                if which systemctl &>/dev/null; then
118                        STARTSERVICE="eval systemctl start \$service.service"
119                        ENABLESERVICE="eval systemctl enable \$service.service"
120                else
121                        STARTSERVICE="eval service \$service start"
122                        ENABLESERVICE="eval chkconfig \$service on"
123                fi
[2a5c1a4]124                APACHEUSER="apache"
125                APACHEGROUP="apache"
[db9e706]126                ;;
[de8bbb1]127        *)      # Otras distribuciones.
[0b6304e]128                ;;
[db9e706]129esac
[2e38f60]130for i in apache2 httpd; do
131        [ -f /etc/$i ] && APACHECFGDIR="/etc/$i"
132        [ -f /etc/init.d/$i ] && APACHESERV="/etc/init.d/$i"
133done
134for i in dhcpd dhcpd3-server isc-dhcp-server; do
135        [ -f /etc/init.d/$i ] && DHCPSERV="/etc/init.d/$i"
136done
[db9e706]137}
138
139
[64dd765]140# Comprobar auto-actualización.
141function checkAutoUpdate()
142{
143        local update=0
144
145        # Actaulizar el script si ha cambiado o no existe el original.
146        if [ $USESVN -eq 1 ]; then
[7b0c6ff]147                svn export $SVN_URL/installer/$PROGRAMNAME
[d372e6e]148                if ! diff -q $PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME 2>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
[64dd765]149                        mv $PROGRAMNAME $INSTALL_TARGET/lib
150                        update=1
151                else
152                        rm -f $PROGRAMNAME
153                fi
154        else
[d372e6e]155                if ! diff -q $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME 2>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
[64dd765]156                        cp -a $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib
157                        update=1
158                fi
159        fi
160
161        return $update
162}
163
164
[a0867b37]165function getDateTime()
166{
[5eb61a6]167        date "+%Y%m%d-%H%M%S"
[a0867b37]168}
169
170# Escribe a fichero y muestra por pantalla
171function echoAndLog()
172{
[5eb61a6]173        echo $1
[6ef01d9]174        DATETIME=`getDateTime`
175        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
[a0867b37]176}
177
178function errorAndLog()
179{
[5eb61a6]180        echo "ERROR: $1"
181        DATETIME=`getDateTime`
[6ef01d9]182        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
[a0867b37]183}
184
185
186#####################################################################
187####### Funciones de copia de seguridad y restauración de ficheros
188#####################################################################
189
190# Hace un backup del fichero pasado por parámetro
191# deja un -last y uno para el día
192function backupFile()
193{
194        if [ $# -ne 1 ]; then
195                errorAndLog "${FUNCNAME}(): invalid number of parameters"
196                exit 1
197        fi
198
199        local fichero=$1
200        local fecha=`date +%Y%m%d`
201
202        if [ ! -f $fichero ]; then
203                errorAndLog "${FUNCNAME}(): file $fichero doesn't exists"
204                return 1
205        fi
206
[ebbbfc01]207        echoAndLog "${FUNCNAME}(): Making $fichero back-up"
[a0867b37]208
209        # realiza una copia de la última configuración como last
[6ef01d9]210        cp -a $fichero "${fichero}-LAST"
[a0867b37]211
212        # si para el día no hay backup lo hace, sino no
213        if [ ! -f "${fichero}-${fecha}" ]; then
[6ef01d9]214                cp -a $fichero "${fichero}-${fecha}"
[a0867b37]215        fi
216}
217
218# Restaura un fichero desde su copia de seguridad
219function restoreFile()
220{
221        if [ $# -ne 1 ]; then
222                errorAndLog "${FUNCNAME}(): invalid number of parameters"
223                exit 1
224        fi
225
226        local fichero=$1
227
[ebbbfc01]228        echoAndLog "${FUNCNAME}(): restoring file $fichero"
[a0867b37]229        if [ -f "${fichero}-LAST" ]; then
[6ef01d9]230                cp -a "$fichero-LAST" "$fichero"
[a0867b37]231        fi
232}
233
234
235#####################################################################
[295b4ab]236####### Funciones de acceso a base de datos
237#####################################################################
238
239# Actualizar la base datos
240function importSqlFile()
241{
242        if [ $# -ne 4 ]; then
243                errorAndLog "${FNCNAME}(): invalid number of parameters"
244                exit 1
245        fi
246
247        local dbuser="$1"
248        local dbpassword="$2"
249        local database="$3"
250        local sqlfile="$4"
251        local tmpfile=$(mktemp)
[632bd45]252        local mycnf=/tmp/.my.cnf.$$
[295b4ab]253        local status
254
255        if [ ! -r $sqlfile ]; then
256                errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!"
257                return 1
258        fi
259
260        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
261        chmod 600 $tmpfile
262        sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
263            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" $sqlfile > $tmpfile
[632bd45]264        # Componer fichero con credenciales de conexión. 
265        touch $mycnf
266        chmod 600 $mycnf
267        cat << EOT > $mycnf
[c073224]268[client]
[09bf701]269user=$dbuser
270password=$dbpassword
[632bd45]271EOT
272        # Ejecutar actualización y borrar fichero de credenciales.
[09bf701]273        mysql --defaults-extra-file=$mycnf --default-character-set=utf8 -D "$database" < $tmpfile
[295b4ab]274        status=$?
[632bd45]275        rm -f $mycnf $tmpfile
[295b4ab]276        if [ $status -ne 0 ]; then
277                errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database"
278                return 1
279        fi
280        echoAndLog "${FUNCNAME}(): file imported to database $database"
281        return 0
282}
283
284
285#####################################################################
[a0867b37]286####### Funciones de instalación de paquetes
287#####################################################################
288
289# Instalar las deependencias necesarias para el actualizador.
[64dd765]290function installDependencies()
[a0867b37]291{
[db9e706]292        local package
293
[a0867b37]294        if [ $# = 0 ]; then
295                echoAndLog "${FUNCNAME}(): no deps needed."
[c1e00e4]296        else
297                while [ $# -gt 0 ]; do
[db9e706]298                        package="$1"
299                        eval $CHECKPKG || INSTALLDEPS="$INSTALLDEPS $1"
[c1e00e4]300                        shift
301                done
302                if [ -n "$INSTALLDEPS" ]; then
[db9e706]303                        $UPDATEPKGLIST
304                        $INSTALLPKGS $INSTALLDEPS
[c1e00e4]305                        if [ $? -ne 0 ]; then
306                                errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS."
307                                return 1
308                        fi
309                fi
310        fi
[a0867b37]311}
312
313
314#####################################################################
315####### Funciones para el manejo de Subversion
316#####################################################################
317
318function svnExportCode()
319{
320        if [ $# -ne 1 ]; then
321                errorAndLog "${FUNCNAME}(): invalid number of parameters"
322                exit 1
323        fi
324
[27dc5ff]325        local url="$1"
[a0867b37]326
327        echoAndLog "${FUNCNAME}(): downloading subversion code..."
328
[7ad4465]329        svn checkout "${url}" opengnsys
[a0867b37]330        if [ $? -ne 0 ]; then
331                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
332                return 1
333        fi
334        echoAndLog "${FUNCNAME}(): subversion code downloaded"
335        return 0
336}
337
338
339############################################################
340###  Detectar red
341############################################################
342
[07c3a59]343# Comprobar si existe conexión.
344function checkNetworkConnection()
345{
346        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"}
347        wget --spider -q $OPENGNSYS_SERVER
348}
349
[739fb00]350# Obtener los parámetros de red del servidor.
351function getNetworkSettings()
352{
353        # Variables globales definidas:
354        # - SERVERIP:   IP local de la interfaz por defecto.
355
356        local DEVICES
357        local dev
358
359        echoAndLog "${FUNCNAME}(): Detecting network parameters."
360        DEVICES="$(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}')"
361        for dev in $DEVICES; do
362                [ -z "$SERVERIP" ] && SERVERIP=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
363        done
364}
365
[a0867b37]366
367#####################################################################
368####### Funciones específicas de la instalación de Opengnsys
369#####################################################################
370
[45f1fe8]371# Actualizar cliente OpenGnSys
[295b4ab]372function updateClientFiles()
[45f1fe8]373{
374        echoAndLog "${FUNCNAME}(): Updating OpenGnSys Client files."
375        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
376        if [ $? -ne 0 ]; then
377                errorAndLog "${FUNCNAME}(): error while updating client structure"
[51b179a]378                exit 1
[45f1fe8]379        fi
380        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
381       
382        echoAndLog "${FUNCNAME}(): Updating OpenGnSys Cloning Engine files."
[51b179a]383        rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
[45f1fe8]384        if [ $? -ne 0 ]; then
385                errorAndLog "${FUNCNAME}(): error while updating engine files"
[51b179a]386                exit 1
[45f1fe8]387        fi
388       
[51b179a]389        echoAndLog "${FUNCNAME}(): client files update success."
[45f1fe8]390}
[4e51cb0]391
[3ce53a7]392# Configurar HTTPS y exportar usuario y grupo del servicio Apache.
393function apacheConfiguration ()
[4e51cb0]394{
[2e38f60]395        # Activar HTTPS (solo actualizando desde versiones anteriores a 1.0.2).
396        if [ -e $APACHECFGDIR/sites-available/opengnsys.conf ]; then
[3ce53a7]397                echoAndLog "${FUNCNAME}(): Configuring HTTPS access..."
[2e38f60]398                mv $APACHECFGDIR/sites-available/opengnsys.conf $APACHECFGDIR/sites-available/opengnsys
[3ce53a7]399                a2ensite default-ssl
400                a2enmod ssl
[3e24aa5]401                a2dissite opengnsys.conf
[3ce53a7]402                a2ensite opengnsys
[2e38f60]403                $APACHESERV restart
[3ce53a7]404        fi
405
406        # Variables de ejecución de Apache.
[4e51cb0]407        # - APACHE_RUN_USER
408        # - APACHE_RUN_GROUP
[2e38f60]409        if [ -f $APACHECFGDIR/envvars ]; then
410                source $APACHECFGDIR/envvars
[4e51cb0]411        fi
[2e38f60]412        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
[de8bbb1]413        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
[4e51cb0]414}
415
[4b96166]416# Configurar servicio Rsync.
417function rsyncConfigure()
418{
419        local service
420
421        # Configurar acceso a Rsync.
422        if [ ! -f /etc/rsyncd.conf ]; then
423                echoAndLog "${FUNCNAME}(): Configuring Rsync service."
424                sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENTUSER/g" \
425                    $WORKDIR/opengnsys/repoman/etc/rsyncd.conf.tmpl > /etc/rsyncd.conf
426                # Habilitar Rsync.
427                if [ -f /etc/default/rsync ]; then
428                        perl -pi -e 's/RSYNC_ENABLE=.*/RSYNC_ENABLE=inetd/' /etc/default/rsync
429                fi
430                if [ -f $INETDCFGDIR/rsync ]; then
431                        perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/rsync
432                else
433                        cat << EOT > $INETDCFGDIR/rsync
434service rsync
435{
436        disable = no
437        socket_type = stream
438        wait = no
439        user = root
440        server = $(which rsync)
441        server_args = --daemon
442        log_on_failure += USERID
443        flags = IPv6
444}
445EOT
446                fi
447                # Activar e iniciar Rsync.
448                service="rsync"  $ENABLESERVICE
449                service="xinetd" $STARTSERVICE
450        fi
451}
452
[a0867b37]453# Copiar ficheros del OpenGnSys Web Console.
454function updateWebFiles()
455{
[2b793a8]456        local ERRCODE COMPATDIR f
457
[a0867b37]458        echoAndLog "${FUNCNAME}(): Updating web files..."
[2b793a8]459
460        # Copiar los ficheros nuevos conservando el archivo de configuración de acceso.
461        backupFile $INSTALL_TARGET/www/controlacceso.php
462        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
[1db2ed8]463        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
[2b793a8]464        ERRCODE=$?
465        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
[c1e00e4]466        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
[d655cc4]467        if [ $ERRCODE != 0 ]; then
[a0867b37]468                errorAndLog "${FUNCNAME}(): Error updating web files."
469                exit 1
470        fi
[2b793a8]471        restoreFile $INSTALL_TARGET/www/controlacceso.php
472
473        # Compatibilidad con dispositivos móviles.
474        COMPATDIR="$INSTALL_TARGET/www/principal"
475        for f in acciones administracion aula aulas hardwares imagenes menus repositorios softwares; do
476                sed 's/clickcontextualnodo/clicksupnodo/g' $COMPATDIR/$f.php > $COMPATDIR/$f.device.php
477        done
478        cp -a $COMPATDIR/imagenes.device.php > $COMPATDIR/imagenes.device4.php
479
[a0867b37]480        # Cambiar permisos para ficheros especiales.
[e6d22c6]481        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/{fotos,iconos}
[20685a9]482        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/tmp/
[2b793a8]483
[a0867b37]484        echoAndLog "${FUNCNAME}(): Web files updated successfully."
485}
486
[72134d5]487# Copiar carpeta de Interface
[64dd765]488function updateInterfaceAdm()
[72134d5]489{
[27dc5ff]490        local errcode=0
[2b793a8]491
[72134d5]492        # Crear carpeta y copiar Interface
493        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
494        mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface
495        rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client
[27dc5ff]496        errcoce=$?
[72134d5]497        mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm
[27dc5ff]498        if [ $errcode -ne 0 ]; then
[72134d5]499                echoAndLog "${FUNCNAME}(): error while updating admin interface"
500                exit 1
501        fi
502        chmod -R +x $INSTALL_TARGET/client/interfaceAdm
[b6f1726]503        chown $OPENGNSYS_CLIENTUSER:$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[f6c1d2b]504        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[72134d5]505        echoAndLog "${FUNCNAME}(): Admin interface updated successfully."
506}
[a0867b37]507
[5d6bf97]508# Crear documentación Doxygen para la consola web.
509function makeDoxygenFiles()
510{
511        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
512        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
513                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
514        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
515                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
516                return 1
517        fi
[45f1fe8]518        rm -fr "$INSTALL_TARGET/www/api"
[15b2a4e]519        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
520        rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
[5d6bf97]521        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
522        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
523}
524
525
[a0867b37]526# Crea la estructura base de la instalación de opengnsys
527function createDirs()
528{
[eb9424f]529        # Crear estructura de directorios.
[a0867b37]530        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
[7bb72f7]531        local dir
532
[cfad47b]533        mkdir -p ${INSTALL_TARGET}/{bin,doc,etc,lib,sbin,www}
534        mkdir -p ${INSTALL_TARGET}/{client,images}
[a0867b37]535        mkdir -p ${INSTALL_TARGET}/log/clients
[eb9424f]536        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
[7bb72f7]537        # Detectar directorio de instalación de TFTP.
538        if [ ! -L ${INSTALL_TARGET}/tftpboot ]; then
539                for dir in /var/lib/tftpboot /srv/tftp; do
540                        [ -d $dir ] && ln -fs $dir ${INSTALL_TARGET}/tftpboot
541                done
542        fi
[cfad47b]543        mkdir -p ${INSTALL_TARGET}/tftpboot/{pxelinux.cfg,menu.lst}
[a0867b37]544        if [ $? -ne 0 ]; then
545                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
546                return 1
547        fi
548
[eb9424f]549        # Crear usuario ficticio.
550        if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then
551                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created"
552        else
553                echoAndLog "${FUNCNAME}(): creating OpenGnSys user"
554                useradd $OPENGNSYS_CLIENTUSER 2>/dev/null
555                if [ $? -ne 0 ]; then
556                        errorAndLog "${FUNCNAME}(): error creating OpenGnSys user"
557                        return 1
558                fi
559        fi
560
561        # Establecer los permisos básicos.
562        echoAndLog "${FUNCNAME}(): setting directory permissions"
[cfad47b]563        chmod -R 775 $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg,tftpboot/menu.lst}
[dc103b6]564        mkdir -p $INSTALL_TARGET/tftpboot/menu.lst/examples
[e979faf]565        ! [ -f $INSTALL_TARGET/tftpboot/menu.lst/templates/00unknown ] && mv $INSTALL_TARGET/tftpboot/menu.lst/templates/* $INSTALL_TARGET/tftpboot/menu.lst/examples
[cfad47b]566        chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg,tftpboot/menu.lst}
[eb9424f]567        if [ $? -ne 0 ]; then
568                errorAndLog "${FUNCNAME}(): error while setting permissions"
569                return 1
570        fi
571
[57f7e9c]572        # Mover el fichero de registro al directorio de logs.
573        echoAndLog "${FUNCNAME}(): moving update log file"
574        mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE
[7669bca]575        chmod 600 $LOG_FILE
[57f7e9c]576
[a0867b37]577        echoAndLog "${FUNCNAME}(): directory paths created"
578        return 0
579}
580
581# Copia ficheros de configuración y ejecutables genéricos del servidor.
[64dd765]582function updateServerFiles()
[bb30a50]583{
[c1e00e4]584        # No copiar ficheros del antiguo cliente Initrd
[873cf1e]585        local SOURCES=( repoman/bin \
[c1e00e4]586                        server/bin \
[42a0e41]587                        admin/Sources/Services/ogAdmServerAux \
588                        admin/Sources/Services/ogAdmRepoAux \
[873cf1e]589                        server/tftpboot \
[bb30a50]590                        installer/opengnsys_uninstall.sh \
[a8bb7641]591                        installer/install_ticket_wolunicast.sh \
[873cf1e]592                        doc )
593        local TARGETS=( bin \
594                        bin \
[cdad332]595                        sbin/ogAdmServerAux \
596                        sbin/ogAdmRepoAux \
[873cf1e]597                        tftpboot \
[9a2c0f9d]598                        lib/opengnsys_uninstall.sh \
599                        lib/install_ticket_wolunicast.sh \
[873cf1e]600                        doc )
[a0867b37]601
602        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
603                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
604                exit 1
605        fi
606
607        echoAndLog "${FUNCNAME}(): updating files in server directories"
608        pushd $WORKDIR/opengnsys >/dev/null
609        local i
610        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
[27dc5ff]611                if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then
[4057c5d]612                        rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}"))
[aa36857]613                else
[56f100f]614                        rsync -irplt "${SOURCES[i]}" $(readlink -m "$INSTALL_TARGET/${TARGETS[i]}")
[aa36857]615                fi
[a0867b37]616        done
617        popd >/dev/null
[df3cd7f]618        NEWFILES=""             # Ficheros de configuración que han cambiado de formato.
[f80f839]619        if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then
[df3cd7f]620                echoAndLog "${FUNCNAME}(): updating DHCP files"
[f80f839]621                perl -pi -e 's/pxelinux.0/grldr/' /etc/dhcp*/dhcpd*.conf
[2e38f60]622                $DHCPSERV restart
[df3cd7f]623                NEWFILES="/etc/dhcp*/dhcpd*.conf"
624        fi
[d372e6e]625        if ! diff -q $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys 2>/dev/null; then
[df3cd7f]626                echoAndLog "${FUNCNAME}(): updating new init file"
627                backupFile /etc/init.d/opengnsys
628                cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
629                NEWFILES="$NEWFILES /etc/init.d/opengnsys"
630        fi
[984093e]631        if grep -q "UrlMsg=.*msgbrowser.php" $INSTALL_TARGET/client/etc/ogAdmClient.cfg 2>/dev/null; then
[df3cd7f]632                echoAndLog "${FUNCNAME}(): updating new client config file"
633                backupFile $INSTALL_TARGET/client/etc/ogAdmClient.cfg
634                perl -pi -e 's!UrlMsg=.*msgbrowser\.php!UrlMsg=http://localhost/cgi-bin/httpd-log\.sh!g' $INSTALL_TARGET/client/etc/ogAdmClient.cfg
635                NEWFILES="$NEWFILES $INSTALL_TARGET/client/etc/ogAdmClient.cfg"
[f80f839]636        fi
[9ee62ad]637        echoAndLog "${FUNCNAME}(): updating cron files"
[db9e706]638        [ ! -f /etc/cron.d/opengnsys ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys
639        [ ! -f /etc/cron.d/torrentcreator ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
640        [ ! -f /etc/cron.d/torrenttracker ] && echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
[dc762088]641        [ ! -f /etc/cron.d/imagedelete ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete
[da8db11]642        echoAndLog "${FUNCNAME}(): server files updated successfully."
[a0867b37]643}
644
645####################################################################
646### Funciones de compilación de código fuente de servicios
647####################################################################
648
[bb30a50]649# Recompilar y actualiza los serivicios y clientes.
[64dd765]650function compileServices()
[a0867b37]651{
[bb30a50]652        local hayErrores=0
653
654        # Compilar OpenGnSys Server
655        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Admin Server"
656        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
657        make && mv ogAdmServer $INSTALL_TARGET/sbin
658        if [ $? -ne 0 ]; then
659                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
660                hayErrores=1
661        fi
662        popd
663        # Compilar OpenGnSys Repository Manager
664        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Repository Manager"
665        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
666        make && mv ogAdmRepo $INSTALL_TARGET/sbin
667        if [ $? -ne 0 ]; then
668                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
669                hayErrores=1
670        fi
671        popd
672        # Compilar OpenGnSys Agent
673        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Agent"
674        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
675        make && mv ogAdmAgent $INSTALL_TARGET/sbin
676        if [ $? -ne 0 ]; then
677                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent"
678                hayErrores=1
679        fi
680        popd
681
[a0867b37]682        # Compilar OpenGnSys Client
[bb30a50]683        echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Client"
[72134d5]684        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[e473667]685        make && mv ogAdmClient $INSTALL_TARGET/client/bin
[a0867b37]686        if [ $? -ne 0 ]; then
687                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client"
688                hayErrores=1
689        fi
690        popd
691
692        return $hayErrores
693}
694
695
696####################################################################
[4e51cb0]697### Funciones instalacion cliente OpenGnSys
[a0867b37]698####################################################################
699
[595f397]700# Actualizar cliente OpenGnSys
[c1e00e4]701function updateClient()
702{
[df3cd7f]703        local DOWNLOADURL="http://$OPENGNSYS_SERVER/downloads"
[993c328]704        local FILENAME=ogLive-precise-3.2.0-23-generic-r3257.iso        # 1.0.4-rc2
705        #local FILENAME=ogLive-raring-3.8.0-22-generic-r3836.iso        # 1.0.5-rc3
[0b85cc93]706        local SOURCEFILE=$DOWNLOADURL/$FILENAME
707        local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
708        local SOURCELENGTH
709        local TARGETLENGTH
710        local TMPDIR=/tmp/${FILENAME%.iso}
[a63345ac]711        local OGINITRD=$INSTALL_TARGET/tftpboot/ogclient/oginitrd.img
712        local SAMBAPASS
[0b85cc93]713
714        # Comprobar si debe actualizarse el cliente.
[c3cc6b0]715        SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}')
[d168a46]716        TARGETLENGTH=$(ls -l $TARGETFILE 2>/dev/null | awk '{print $5}')
[d4e90c1]717        [ -z $TARGETLENGTH ] && TARGETLENGTH=0
[0b85cc93]718        if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then
719                echoAndLog "${FUNCNAME}(): Loading Client"
720                wget $DOWNLOADURL/$FILENAME -O $TARGETFILE
721                if [ ! -s $TARGETFILE ]; then
722                        errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client"
723                        return 1
724                fi
[a63345ac]725                # Obtener la clave actual de acceso a Samba para restaurarla.
726                if [ -f $OGINITRD ]; then
727                        SAMBAPASS=$(gzip -dc $OGINITRD | \
728                                    cpio -i --to-stdout scripts/ogfunctions 2>&1 | \
[c3cc6b0]729                                    grep "^[    ]*OPTIONS=" | \
[a63345ac]730                                    sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')
731                fi
732                # Montar la imagen ISO del ogclient, actualizar ficheros y desmontar.
733                echoAndLog "${FUNCNAME}(): Updatting ogclient files"
734                mkdir -p $TMPDIR
735                mount -o loop,ro $TARGETFILE $TMPDIR
736                rsync -irlt $TMPDIR/ogclient $INSTALL_TARGET/tftpboot
737                umount $TMPDIR
738                rmdir $TMPDIR
739                # Recuperar la clave de acceso a Samba.
740                if [ -n "$SAMBAPASS" ]; then
741                        echoAndLog "${FUNCNAME}(): Restoring client access key"
742                        echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | \
743                                        $INSTALL_TARGET/bin/setsmbpass
744                fi
745                # Establecer los permisos.
746                find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \;
747                find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \;
748                chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient
749                chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg}
[e1c01217]750               
[e8963d0]751                # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache
[7bb72f7]752                cp -av $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot
753                cp -av $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot
[e1c01217]754               
[a63345ac]755                echoAndLog "${FUNCNAME}(): Client update successfully"
[0b85cc93]756        else
[a63345ac]757                echoAndLog "${FUNCNAME}(): Client is already updated"
[c1e00e4]758        fi
759}
[a0867b37]760
[eb9424f]761# Resumen de actualización.
762function updateSummary()
763{
764        # Actualizar fichero de versión y revisión.
765        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
[57f7e9c]766        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}')
[eb9424f]767
768        [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE
769        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
770
771        echo
772        echoAndLog "OpenGnSys Update Summary"
[df3cd7f]773        echo       "========================"
774        echoAndLog "Project version:                  $(cat $VERSIONFILE)"
[57f7e9c]775        echoAndLog "Update log file:                  $LOG_FILE"
[df3cd7f]776        if [ -n "$NEWFILES" ]; then
777                echoAndLog "Check the new config files:       $(echo $NEWFILES)"
778        fi
[eb9424f]779        echo
780}
781
782
[a0867b37]783
784#####################################################################
[3320409]785####### Proceso de actualización de OpenGnSys
[a0867b37]786#####################################################################
787
788
789echoAndLog "OpenGnSys update begins at $(date)"
790
[bb30a50]791pushd $WORKDIR
792
[27dc5ff]793# Comprobar si hay conexión y detectar parámetros de red por defecto.
794checkNetworkConnection
795if [ $? -ne 0 ]; then
796        errorAndLog "Error connecting to server. Causes:"
797        errorAndLog " - Network is unreachable, review devices parameters."
798        errorAndLog " - You are inside a private network, configure the proxy service."
799        errorAndLog " - Server is temporally down, try agian later."
800        exit 1
801fi
[739fb00]802getNetworkSettings
[27dc5ff]803
[64dd765]804# Comprobar auto-actualización del programa.
805if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
806        checkAutoUpdate
807        if [ $? -ne 0 ]; then
[f580c51]808                echoAndLog "OpenGnSys updater has been overwritten."
809                echoAndLog "Please, re-execute this script."
[64dd765]810                exit
811        fi
812fi
813
[db9e706]814# Detectar datos de auto-configuración del instalador.
815autoConfigure
816
[bb30a50]817# Instalar dependencias.
[db9e706]818installDependencies $DEPENDENCIES
[a0867b37]819if [ $? -ne 0 ]; then
820        errorAndLog "Error: you may install all needed dependencies."
821        exit 1
822fi
823
824# Arbol de directorios de OpenGnSys.
825createDirs ${INSTALL_TARGET}
826if [ $? -ne 0 ]; then
827        errorAndLog "Error while creating directory paths!"
828        exit 1
829fi
830
831# Si es necesario, descarga el repositorio de código en directorio temporal
832if [ $USESVN -eq 1 ]; then
833        svnExportCode $SVN_URL
834        if [ $? -ne 0 ]; then
835                errorAndLog "Error while getting code from svn"
836                exit 1
837        fi
838else
839        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
840fi
841
[295b4ab]842# Si existe fichero de actualización de la base de datos; aplicar cambios.
843INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
844REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
[0b8a1f1]845if [ "$INSTVERSION" == "$REPOVERSION" ]; then
846        OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION.sql"
847else
848        OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
849fi
[295b4ab]850if [ -f $OPENGNSYS_DBUPDATEFILE ]; then
[0b8a1f1]851        echoAndLog "Updating tables from file: $(basename $OPENGNSYS_DBUPDATEFILE)"
[295b4ab]852        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE
853else
854        echoAndLog "Database unchanged."
855fi
856
857# Actualizar ficheros complementarios del servidor
[a0867b37]858updateServerFiles
859if [ $? -ne 0 ]; then
[da8db11]860        errorAndLog "Error updating OpenGnSys Server files"
[a0867b37]861        exit 1
862fi
863
[be49575]864# Configurar Rsync.
865rsyncConfigure
866
[295b4ab]867# Actualizar ficheros del cliente
868updateClientFiles
869updateInterfaceAdm
[45f1fe8]870
[295b4ab]871# Actualizar páqinas web
[3ce53a7]872apacheConfiguration
[a0867b37]873updateWebFiles
874if [ $? -ne 0 ]; then
[da8db11]875        errorAndLog "Error updating OpenGnSys Web Admin files"
[a0867b37]876        exit 1
877fi
[5d6bf97]878# Generar páginas Doxygen para instalar en el web
879makeDoxygenFiles
[a0867b37]880
[bb30a50]881# Recompilar y actualizar los servicios del sistema
882compileServices
883
884# Actaulizar ficheros auxiliares del cliente
[a0867b37]885updateClient
886if [ $? -ne 0 ]; then
887        errorAndLog "Error updating clients"
888        exit 1
889fi
890
[3320409]891# Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
[ebbbfc01]892if [ -f /tmp/dstate ]; then
893        rm -f /tmp/dstate
[3320409]894fi
895
[eb9424f]896# Mostrar resumen de actualización.
897updateSummary
898
[a0867b37]899#rm -rf $WORKDIR
900echoAndLog "OpenGnSys update finished at $(date)"
901
902popd
903
Note: See TracBrowser for help on using the repository browser.