source: installer/opengnsys_update.sh @ 4f70c64

configure-oglivelgromero-new-oglivemainmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineoglive-ipv6test-python-scriptsticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since 4f70c64 was d3ec014, checked in by Irina Gómez <irinagomez@…>, 13 months ago

Resolves vulnerabilities CVE-2024-3704, CVE-2024-3705, CVE-2024-3706 y CVE-2024-3707.

  • Property mode set to 100755
File size: 45.5 KB
RevLine 
[a0867b37]1#!/bin/bash
2#/**
3#@file    opengnsys_update.sh
[5f21d34]4#@brief   Script actualización de OpenGnsys
[a0867b37]5#@version 0.9 - basado en opengnsys_installer.sh
6#@author  Ramón Gómez - ETSII Univ. Sevilla
7#@date    2010/01/27
[c1e00e4]8#@version 1.0 - adaptación a OpenGnSys 1.0
9#@author  Ramón Gómez - ETSII Univ. Sevilla
10#@date    2011/03/02
[64dd765]11#@version 1.0.1 - control de auto actualización del script
12#@author  Ramón Gómez - ETSII Univ. Sevilla
13#@date    2011/05/17
[739fb00]14#@version 1.0.2a - obtiene valor de dirección IP por defecto
15#@author  Ramón Gómez - ETSII Univ. Sevilla
16#@date    2012/01/18
[1175096]17#@version 1.0.3 - Compatibilidad con Debian y auto configuración de acceso a BD.
[7bb72f7]18#@author  Ramón Gómez - ETSII Univ. Sevilla
[1175096]19#@date    2012/03/12
[db9e706]20#@version 1.0.4 - Detector de distribución y compatibilidad con CentOS.
21#@author  Ramón Gómez - ETSII Univ. Sevilla
22#@date    2012/05/04
[dde65c7]23#@version 1.0.5 - Actualizar BD en la misma versión, compatibilidad con Fedora (systemd) y configuración de Rsync.
[0b8a1f1]24#@author  Ramón Gómez - ETSII Univ. Sevilla
[dde65c7]25#@date    2014/04/03
[1a2fa9d8]26#@version 1.0.6 - Redefinir URLs de ficheros de configuración usando HTTPS.
27#@author  Ramón Gómez - ETSII Univ. Sevilla
28#@date    2015/03/12
[a3855dc]29#@version 1.1.0 - Instalación de API REST y configuración de zona horaria.
[900be258]30#@author  Ramón Gómez - ETSII Univ. Sevilla
[a3855dc]31#@date    2015/11/09
[fd45e9a]32#@version 1.1.1a - Elegir versión a actualizar.
33#@author  Ramón Gómez - ETSII Univ. Sevilla
34#@date    2019/12/13
[a0867b37]35#*/
36
37
[1175096]38####  AVISO: NO EDITAR variables de configuración.
39####  WARNING: DO NOT EDIT configuration variables.
40INSTALL_TARGET=/opt/opengnsys           # Directorio de instalación
[ec045b1]41PATH=$PATH:$INSTALL_TARGET/bin
[295b4ab]42OPENGNSYS_CLIENTUSER="opengnsys"        # Usuario Samba
43
44
[a0867b37]45# Sólo ejecutable por usuario root
[6ef01d9]46if [ "$(whoami)" != 'root' ]; then
[a0867b37]47        echo "ERROR: this program must run under root privileges!!"
48        exit 1
49fi
[5f21d34]50# Error si OpenGnsys no está instalado (no existe el directorio del proyecto)
[4e51cb0]51if [ ! -d $INSTALL_TARGET ]; then
[5f21d34]52        echo "ERROR: OpenGnsys is not installed, cannot update!!"
[4e51cb0]53        exit 1
54fi
[1175096]55# Cargar configuración de acceso a la base de datos.
56if [ -r $INSTALL_TARGET/etc/ogAdmServer.cfg ]; then
57        source $INSTALL_TARGET/etc/ogAdmServer.cfg
58elif [ -r $INSTALL_TARGET/etc/ogAdmAgent.cfg ]; then
59        source $INSTALL_TARGET/etc/ogAdmAgent.cfg
60fi
[42a0e41]61OPENGNSYS_DATABASE=${OPENGNSYS_DATABASE:-"$CATALOG"}            # Base de datos
[1175096]62OPENGNSYS_DBUSER=${OPENGNSYS_DBUSER:-"$USUARIO"}                # Usuario de acceso
63OPENGNSYS_DBPASSWORD=${OPENGNSYS_DBPASSWORD:-"$PASSWORD"}       # Clave del usuario
64if [ -z "$OPENGNSYS_DATABASE" -o -z "$OPENGNSYS_DBUSER" -o -z "$OPENGNSYS_DBPASSWORD" ]; then
65        echo "ERROR: set OPENGNSYS_DATABASE, OPENGNSYS_DBUSER and OPENGNSYS_DBPASSWORD"
66        echo "       variables, and run this script again."
[0304465]67        exit 1
[1175096]68fi
[a0867b37]69
[884b6ce]70# Comprobar si se ha descargado el paquete comprimido (REMOTE=0) o sólo el instalador (REMOTE=1).
[a0867b37]71PROGRAMDIR=$(readlink -e $(dirname "$0"))
[64dd765]72PROGRAMNAME=$(basename "$0")
[a0081b7]73OPENGNSYS_SERVER="opengnsys.es"
[a0867b37]74if [ -d "$PROGRAMDIR/../installer" ]; then
[884b6ce]75        REMOTE=0
[a0867b37]76else
[884b6ce]77        REMOTE=1
[a0867b37]78fi
79
80WORKDIR=/tmp/opengnsys_update
81mkdir -p $WORKDIR
82
[42a0e41]83# Registro de incidencias.
84OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log
[57f7e9c]85LOG_FILE=/tmp/$(basename $OGLOGFILE)
[a0867b37]86
87
88
89#####################################################################
90####### Algunas funciones útiles de propósito general:
91#####################################################################
[295b4ab]92
[db9e706]93# Generar variables de configuración del actualizador
94# Variables globales:
[2e38f60]95# - OSDISTRIB - distribución Linux
[db9e706]96# - DEPENDENCIES - array de dependencias que deben estar instaladas
97# - UPDATEPKGLIST, INSTALLPKGS, CHECKPKG - comandos para gestión de paquetes
[3b0436d]98# - APACHECFGDIR, APACHESERV, PHPFPMSERV, DHCPSERV, MYSQLSERV, MYSQLCFGDIR, INETDCFGDIR - configuración y servicios
[ec536c6]99
[db9e706]100function autoConfigure()
101{
[a37e5fc4]102        local service
[2e38f60]103
[a37e5fc4]104        # Detectar sistema operativo del servidor (compatible con fichero os-release y con LSB).
105        if [ -f /etc/os-release ]; then
106                source /etc/os-release
107                OSDISTRIB="$ID"
108                OSVERSION="$VERSION_ID"
109        else
110                OSDISTRIB=$(lsb_release -is 2>/dev/null)
111                OSVERSION=$(lsb_release -rs 2>/dev/null)
112        fi
113        # Convertir distribución a minúsculas y obtener solo el 1er número de versión.
114        OSDISTRIB="${OSDISTRIB,,}"
115        OSVERSION="${OSVERSION%%.*}"
116
117        # Configuración según la distribución de Linux.
118        if [ -f /etc/debian_version ]; then
[884b6ce]119                # Distribución basada en paquetes Deb.
[a5d9191]120                DEPENDENCIES=( curl rsync btrfs-tools procps arp-scan realpath php-curl gettext moreutils jq wakeonlan udpcast libev-dev libjansson-dev libssl-dev shim-signed grub-efi-amd64-signed php-fpm gawk libdbi-dev libdbi1 libdbd-mysql liblz4-tool )
[42c7e5f]121                # Paquete correcto para realpath.
122                [ -z "$(apt-cache pkgnames realpath)" ] && DEPENDENCIES=( ${DEPENDENCIES[@]//realpath/coreutils} )
[0304465]123                UPDATEPKGLIST="add-apt-repository -y ppa:ondrej/php; apt-get update"
[a37e5fc4]124                INSTALLPKGS="apt-get -y install"
125                DELETEPKGS="apt-get -y purge"
[db9e706]126                CHECKPKG="dpkg -s \$package 2>/dev/null | grep -q \"Status: install ok\""
[4b96166]127                if which service &>/dev/null; then
128                        STARTSERVICE="eval service \$service restart"
[dde65c7]129                        STOPSERVICE="eval service \$service stop"
[a37e5fc4]130                        SERVICESTATUS="eval service \$service status"
[4b96166]131                else
132                        STARTSERVICE="eval /etc/init.d/\$service restart"
[dde65c7]133                        STOPSERVICE="eval /etc/init.d/\$service stop"
[a37e5fc4]134                        SERVICESTATUS="eval /etc/init.d/\$service status"
[4b96166]135                fi
136                ENABLESERVICE="eval update-rc.d \$service defaults"
[9215580]137                APACHEENABLEMODS="ssl rewrite proxy_fcgi fastcgi actions alias"
138                APACHEDISABLEMODS="php"
[2e38f60]139                APACHEUSER="www-data"
140                APACHEGROUP="www-data"
[3b0436d]141                MYSQLCFGDIR=/etc/mysql/mysql.conf.d
142                MYSQLSERV="mysql"
[ec536c6]143                PHPFPMSERV="php-fpm"
[65baf16]144                INETDCFGDIR=/etc/xinetd.d
[a37e5fc4]145        elif [ -f /etc/redhat-release ]; then
[884b6ce]146                # Distribución basada en paquetes rpm.
[c089f29]147                DEPENDENCIES=( curl rsync btrfs-progs procps-ng arp-scan gettext moreutils jq net-tools udpcast libev-devel jansson-devel openssl-devel shim-x64 grub2-efi-x64 grub2-efi-x64-modules gawk libdbi-devel libdbi libdbi-dbd-mysql)
[ec536c6]148                # Repositorios para PHP 7 en CentOS.
149                [ "$OSDISTRIB" == "centos" ] && UPDATEPKGLIST="yum update -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$OSVERSION.noarch.rpm http://rpms.remirepo.net/enterprise/remi-release-$OSVERSION.rpm"
[db9e706]150                INSTALLPKGS="yum install -y"
[a37e5fc4]151                DELETEPKGS="yum remove -y"
[db9e706]152                CHECKPKG="rpm -q --quiet \$package"
[4b96166]153                if which systemctl &>/dev/null; then
[a37e5fc4]154                        STARTSERVICE="eval systemctl restart \$service.service"
[dde65c7]155                        STOPSERVICE="eval systemctl stop \$service.service"
[4b96166]156                        ENABLESERVICE="eval systemctl enable \$service.service"
[a37e5fc4]157                        SERVICESTATUS="eval systemctl status \$service.service"
[4b96166]158                else
[a37e5fc4]159                        STARTSERVICE="eval service \$service restart"
[dde65c7]160                        STOPSERVICE="eval service \$service stop"
[4b96166]161                        ENABLESERVICE="eval chkconfig \$service on"
[a37e5fc4]162                        SERVICESTATUS="eval service \$service status"
[4b96166]163                fi
[2a5c1a4]164                APACHEUSER="apache"
165                APACHEGROUP="apache"
[3b0436d]166                MYSQLCFGDIR=/etc/my.cnf.d
167                MYSQLSERV="mariadb"
[ec536c6]168                PHPFPMSERV="php-fpm"
[65baf16]169                INETDCFGDIR=/etc/xinetd.d
[a37e5fc4]170        else
171                # Otras distribuciones.
172                :
173        fi
174        for service in apache2 httpd; do
[5050850]175                [ -d "/etc/$service" ] && APACHECFGDIR="/etc/$service"
[a37e5fc4]176                if $SERVICESTATUS &>/dev/null; then APACHESERV="$service"; fi
177        done
178        for service in dhcpd dhcpd3-server isc-dhcp-server; do
179                if $SERVICESTATUS &>/dev/null; then DHCPSERV="$service"; fi
180        done
[db9e706]181}
182
183
[fd45e9a]184# Choose an available version to update.
185function chooseVersion()
186{
[d42d7c7]187    local RELEASES DOWNLOADS INSTVERSION INSTRELEASE RELDATE
[fd45e9a]188
189    # Development branch.
[73c5e1c]190    BRANCH="main"
[fd45e9a]191    API_URL="https://api.github.com/repos/opengnsys/OpenGnsys/branches/$BRANCH"
[66432fb]192
193    RELEASES=( )
194    DOWNLOADS=( )
[fd45e9a]195    # If updating from a local or very old version, use the default data.
196    if [ $REMOTE -eq 1 ] && which jq &>/dev/null && [ -f $INSTALL_TARGET/doc/VERSION.json ]; then
197        # Installed release.
198        read -pe INSTVERSION INSTRELEASE <<< $(jq -r '.version+" "+.release' $INSTALL_TARGET/doc/VERSION.json)
199        # Fetch tags (releases) data from GitHub.
200        while read -pe TAG URL; do
201            if [[ $TAG =~ ^opengnsys- ]]; then
[d42d7c7]202                [ "${TAG#opengnsys-}" \< "${INSTVERSION%pre}" ] && continue
203                RELDATE=$(curl -s "$URL" | jq -r '.commit.committer.date | split("-") | join("")[:8]')
204                RELEASES+=( "${TAG} ($RELDATE)" )
205                DOWNLOADS+=( "$URL" )
[fd45e9a]206            fi
207        done <<< $(curl -s "$API_URL/../../tags" | jq -r '.[] | .name+" "+.commit.url')
[73c5e1c]208        # Add development (main) branch.
[66432fb]209        RELEASES+=( "$BRANCH" )
210        DOWNLOADS+=( "$API_URL" )
[fd45e9a]211        # Show selection menu, if needed.
[ecdb637]212        if [ ${#RELEASES[@]} -gt 1 ]; then
[fd45e9a]213            echo "Installed version: $INSTVERSION $INSTRELEASE"
[66432fb]214            echo "Versions available for update (\"$BRANCH\" is the latest development branch):"
[d42d7c7]215            PS3="Enter a number (CTRL-C to exit): "
[fd45e9a]216            select opt in "${RELEASES[@]}"; do
217                if [ -n "$opt" ]; then
[d42d7c7]218                    BRANCH="${opt%% *}"
[fd45e9a]219                    API_URL="${DOWNLOADS[REPLY-1]}"
220                    break
221                fi
222            done
223        fi
224    fi
225    # Download URLs.
226    CODE_URL="https://codeload.github.com/opengnsys/OpenGnsys/zip/$BRANCH"
227    RAW_URL="https://raw.githubusercontent.com/opengnsys/OpenGnsys/$BRANCH"
228}
229
230
[64dd765]231# Comprobar auto-actualización.
232function checkAutoUpdate()
233{
234        local update=0
235
236        # Actaulizar el script si ha cambiado o no existe el original.
[884b6ce]237        if [ $REMOTE -eq 1 ]; then
238                curl -s $RAW_URL/installer/$PROGRAMNAME -o $PROGRAMNAME
[a3a1ff2]239                chmod +x $PROGRAMNAME
[d372e6e]240                if ! diff -q $PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME 2>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
[64dd765]241                        mv $PROGRAMNAME $INSTALL_TARGET/lib
242                        update=1
243                else
244                        rm -f $PROGRAMNAME
245                fi
246        else
[d372e6e]247                if ! diff -q $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME 2>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then
[64dd765]248                        cp -a $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib
249                        update=1
250                fi
251        fi
252
253        return $update
254}
255
256
[a0867b37]257function getDateTime()
258{
[5eb61a6]259        date "+%Y%m%d-%H%M%S"
[a0867b37]260}
261
262# Escribe a fichero y muestra por pantalla
263function echoAndLog()
264{
[a3a1ff2]265        echo "$1"
[6ef01d9]266        DATETIME=`getDateTime`
267        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
[a0867b37]268}
269
270function errorAndLog()
271{
[5eb61a6]272        echo "ERROR: $1"
273        DATETIME=`getDateTime`
[6ef01d9]274        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
[a0867b37]275}
276
[cd86637]277# Escribe a fichero y muestra mensaje de aviso
278function warningAndLog()
279{
280        local DATETIME=`getDateTime`
281        echo "Warning: $1"
282        echo "$DATETIME;$SSH_CLIENT;Warning: $1" >> $LOG_FILE
283}
284
[a0867b37]285
286#####################################################################
287####### Funciones de copia de seguridad y restauración de ficheros
288#####################################################################
289
290# Hace un backup del fichero pasado por parámetro
291# deja un -last y uno para el día
292function backupFile()
293{
294        if [ $# -ne 1 ]; then
295                errorAndLog "${FUNCNAME}(): invalid number of parameters"
296                exit 1
297        fi
298
299        local fichero=$1
300        local fecha=`date +%Y%m%d`
[d3ec014]301        local name ext
[a0867b37]302
303        if [ ! -f $fichero ]; then
[cd86637]304                warningAndLog "${FUNCNAME}(): file $fichero doesn't exists"
[a0867b37]305                return 1
306        fi
307
[ebbbfc01]308        echoAndLog "${FUNCNAME}(): Making $fichero back-up"
[a0867b37]309
310        # realiza una copia de la última configuración como last
[d3ec014]311        name="$(echo $fichero| awk -F. '{print $1}')"
312        ext="$(echo $fichero |awk -F. '{if (length($2) != 0)  for(i=2;i<=NF;++i)printf(".%s",$i)}')"
313
314        cp -a $fichero "${name}-LAST${ext}"
[a0867b37]315
316        # si para el día no hay backup lo hace, sino no
[d3ec014]317        if [ ! -f "${name}-${fecha}${ext}" ]; then
318                cp -a $fichero "${name}-${fecha}${ext}"
[a0867b37]319        fi
320}
321
322# Restaura un fichero desde su copia de seguridad
323function restoreFile()
324{
[d3ec014]325        local name ext
[a0867b37]326        if [ $# -ne 1 ]; then
327                errorAndLog "${FUNCNAME}(): invalid number of parameters"
328                exit 1
329        fi
330
331        local fichero=$1
332
[ebbbfc01]333        echoAndLog "${FUNCNAME}(): restoring file $fichero"
[a0867b37]334        if [ -f "${fichero}-LAST" ]; then
[6ef01d9]335                cp -a "$fichero-LAST" "$fichero"
[a0867b37]336        fi
[d3ec014]337
338        name="$(echo $fichero| awk -F. '{print $1}')"
339        ext="$(echo $fichero |awk -F. '{if (length($2) != 0)  for(i=2;i<=NF;++i)printf(".%s",$i)}')"
340
341        if [ -f "${name}-LAST${ext}" ]; then
342                cp -a "${name}-LAST${ext}" "$fichero"
343        fi
[a0867b37]344}
345
346
347#####################################################################
[295b4ab]348####### Funciones de acceso a base de datos
349#####################################################################
350
351# Actualizar la base datos
352function importSqlFile()
353{
354        if [ $# -ne 4 ]; then
355                errorAndLog "${FNCNAME}(): invalid number of parameters"
356                exit 1
357        fi
358
359        local dbuser="$1"
360        local dbpassword="$2"
361        local database="$3"
362        local sqlfile="$4"
363        local tmpfile=$(mktemp)
[632bd45]364        local mycnf=/tmp/.my.cnf.$$
[295b4ab]365        local status
366
367        if [ ! -r $sqlfile ]; then
368                errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!"
369                return 1
370        fi
371
372        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
373        chmod 600 $tmpfile
374        sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
[dde2db1]375            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" $sqlfile > $tmpfile
[632bd45]376        # Componer fichero con credenciales de conexión. 
377        touch $mycnf
378        chmod 600 $mycnf
379        cat << EOT > $mycnf
[c073224]380[client]
[09bf701]381user=$dbuser
382password=$dbpassword
[632bd45]383EOT
[785085b]384        # Antes de actualizar, reasignar valores para campos no nulos con nulo por defecto.
385        mysql --defaults-extra-file=$MYCNF -D "$database" -e \
386                "$(mysql --defaults-extra-file=$MYCNF -Nse "
387SELECT CASE WHEN DATA_TYPE LIKE '%int' THEN
388                 CONCAT_WS(' ', 'ALTER TABLE', TABLE_NAME, 'ALTER', COLUMN_NAME, 'SET DEFAULT 0;')
389            WHEN DATA_TYPE LIKE '%char' THEN
390                 CONCAT_WS(' ', 'ALTER TABLE', TABLE_NAME, 'ALTER', COLUMN_NAME, 'SET DEFAULT \'\';')
391            WHEN DATA_TYPE = 'text' THEN
392                 CONCAT_WS(' ', 'ALTER TABLE', TABLE_NAME, 'MODIFY', COLUMN_NAME, 'TEXT NOT NULL;')
393            ELSE ''
394       END
395  FROM information_schema.COLUMNS
396 WHERE TABLE_SCHEMA='$database'
397   AND IS_NULLABLE='NO'
398   AND COLUMN_DEFAULT IS NULL
399   AND COLUMN_KEY='';")"
[632bd45]400        # Ejecutar actualización y borrar fichero de credenciales.
[09bf701]401        mysql --defaults-extra-file=$mycnf --default-character-set=utf8 -D "$database" < $tmpfile
[295b4ab]402        status=$?
[632bd45]403        rm -f $mycnf $tmpfile
[295b4ab]404        if [ $status -ne 0 ]; then
405                errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database"
406                return 1
407        fi
408        echoAndLog "${FUNCNAME}(): file imported to database $database"
409        return 0
410}
411
[21372e8]412# Comprobar configuración de MySQL y recomendar cambios necesarios.
413function checkMysqlConfig()
414{
[0304465]415        echoAndLog "${FUNCNAME}(): checking MySQL configuration"
[3b0436d]416
417        cp -a $WORKDIR/opengnsys/server/etc/mysqld-og.cnf $MYSQLCFGDIR 2>/dev/null
418        service=$MYSQLSERV; $STARTSERVICE
[21372e8]419
420        echoAndLog "${FUNCNAME}(): MySQL configuration has checked"
421        return 0
422}
[295b4ab]423
424#####################################################################
[a0867b37]425####### Funciones de instalación de paquetes
426#####################################################################
427
428# Instalar las deependencias necesarias para el actualizador.
[64dd765]429function installDependencies()
[a0867b37]430{
[db9e706]431        local package
432
[a37e5fc4]433        # Comprobar si hay que actualizar PHP 5 a PHP 7.
434        eval $UPDATEPKGLIST
435        if [ -f /etc/debian_version ]; then
436                # Basado en paquetes Deb.
437                PHP7VERSION=$(apt-cache pkgnames php7 2>/dev/null | sort | head -1)
[ec536c6]438                PHPFPMSERV="${PHP7VERSION}-fpm"
439                PHP5PKGS=( $(dpkg -l | awk '$2~/^php5/ {print $2}') )
[a37e5fc4]440                if [ -n "$PHP5PKGS" ]; then
441                        $DELETEPKGS ${PHP5PKGS[@]}
[ec536c6]442                        PHP5PKGS[0]="$PHP7VERSION"
[a37e5fc4]443                        INSTALLDEPS=${PHP5PKGS[@]//php5*-/${PHP7VERSION}-}
444                fi
445        fi
[ec536c6]446        if [ "$OSDISTRIB" == "centos" ]; then
447                PHP7VERSION=$(yum list -q php7\* 2>/dev/null | awk -F. '/^php/ {print $1; exit;}')
[97b6579]448                PHPFPMSERV="${PHP7VERSION}-${PHPFPMSERV}"
[ec536c6]449                PHP5PKGS=( $(yum list installed | awk '$1~/^php/ && $2~/^5\./ {sub(/\..*$/, "", $1); print $1}') )
450                if [ -n "$PHP5PKGS" ]; then
451                        $DELETEPKGS ${PHP5PKGS[@]}
452                        PHP5PKGS[0]="$PHP7VERSION-php"
453                        INSTALLDEPS=${PHP5PKGS[@]//php-/${PHP7VERSION}-php}
454                fi
455        fi
[a37e5fc4]456
[a0867b37]457        if [ $# = 0 ]; then
[0304465]458                echoAndLog "${FUNCNAME}(): no dependencies are needed"
[c1e00e4]459        else
460                while [ $# -gt 0 ]; do
[a37e5fc4]461                        package="${1/php/$PHP7VERSION}"
[b6fd406]462                        eval $CHECKPKG || INSTALLDEPS="$INSTALLDEPS $package"
[c1e00e4]463                        shift
464                done
465                if [ -n "$INSTALLDEPS" ]; then
[db9e706]466                        $INSTALLPKGS $INSTALLDEPS
[c1e00e4]467                        if [ $? -ne 0 ]; then
[0304465]468                                errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS"
[c1e00e4]469                                return 1
470                        fi
471                fi
472        fi
[a0867b37]473}
474
475
476#####################################################################
[884b6ce]477####### Funciones para descargar código
[a0867b37]478#####################################################################
479
[884b6ce]480function downloadCode()
[a0867b37]481{
482        if [ $# -ne 1 ]; then
483                errorAndLog "${FUNCNAME}(): invalid number of parameters"
484                exit 1
485        fi
486
[27dc5ff]487        local url="$1"
[a0867b37]488
[884b6ce]489        echoAndLog "${FUNCNAME}(): downloading code..."
[a0867b37]490
[4f64fa1]491        curl "$url" -o opengnsys.zip && \
492                unzip -qo opengnsys.zip && \
493                rm -fr opengnsys && \
494                mv "OpenGnsys-$BRANCH" opengnsys
[a0867b37]495        if [ $? -ne 0 ]; then
496                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
497                return 1
498        fi
[884b6ce]499        rm -f opengnsys.zip
500        echoAndLog "${FUNCNAME}(): code was downloaded"
[a0867b37]501        return 0
502}
503
504
505############################################################
506###  Detectar red
507############################################################
508
[07c3a59]509# Comprobar si existe conexión.
510function checkNetworkConnection()
511{
[a0081b7]512        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"opengnsys.es"}
[884b6ce]513        if which curl &>/dev/null; then
[506c670]514                curl --connect-timeout 10 -s "https://$OPENGNSYS_SERVER" -o /dev/null && \
515                        curl --connect-timeout 10 -s "http://$OPENGNSYS_SERVER" -o /dev/null
[884b6ce]516        elif which wget &>/dev/null; then
[506c670]517                wget --spider -q "https://$OPENGNSYS_SERVER" && \
518                        wget --spider -q "http://$OPENGNSYS_SERVER"
[884b6ce]519        else
520                echoAndLog "${FUNCNAME}(): Cannot execute \"wget\" nor \"curl\"."
521                return 1
522        fi
[07c3a59]523}
524
[0304465]525# Comprobar si la versión es anterior a la actual.
526function checkVersion()
527{
528        local PRE
529
530        # Obtener versión actual y versión a actualizar.
[9815cac]531        [ -f $INSTALL_TARGET/doc/VERSION.txt ] && OLDVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt 2>/dev/null)
532        [ -f $INSTALL_TARGET/doc/VERSION.json ] && OLDVERSION=$(jq -r '.version' $INSTALL_TARGET/doc/VERSION.json 2>/dev/null)
[884b6ce]533        if [ $REMOTE -eq 1 ]; then
[9815cac]534                NEWVERSION=$(curl -s $RAW_URL/doc/VERSION.json 2>/dev/null | jq -r '.version')
[0304465]535        else
[5f0c2dd]536                NEWVERSION=$(jq -r '.version' $PROGRAMDIR/../doc/VERSION.json 2>/dev/null)
[0304465]537        fi
538        [[ "$NEWVERSION" =~ pre ]] && PRE=1
539
540        # Comparar versiones.
541        [[ "$NEWVERSION" < "${OLDVERSION/pre/}" ]] && return 1
542        [ "${NEWVERSION/pre/}" == "$OLDVERSION" -a "$PRE" == "1" ] && return 1
543
544        return 0
545}
546
[739fb00]547# Obtener los parámetros de red del servidor.
548function getNetworkSettings()
549{
550        # Variables globales definidas:
551        # - SERVERIP:   IP local de la interfaz por defecto.
552
553        local DEVICES
554        local dev
555
[90b507d]556        SERVERIP="$ServidorAdm"
[739fb00]557        DEVICES="$(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}')"
558        for dev in $DEVICES; do
[2c1b0cf]559                [ -z "$SERVERIP" ] && SERVERIP=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4); exit;}')
[739fb00]560        done
561}
562
[a0867b37]563
564#####################################################################
565####### Funciones específicas de la instalación de Opengnsys
566#####################################################################
567
[5f21d34]568# Actualizar cliente OpenGnsys.
[295b4ab]569function updateClientFiles()
[45f1fe8]570{
[74cd321]571        local ENGINECFG=$INSTALL_TARGET/client/etc/engine.cfg
572
[a43e90d]573        # Actualizar ficheros del cliente.
[74cd321]574        backupFile $ENGINECFG
[0304465]575        echoAndLog "${FUNCNAME}(): Updating OpenGnsys Client files"
[884b6ce]576        rsync -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
[45f1fe8]577        if [ $? -ne 0 ]; then
578                errorAndLog "${FUNCNAME}(): error while updating client structure"
[51b179a]579                exit 1
[45f1fe8]580        fi
[a43e90d]581
582        # Actualizar librerías del motor de clonación.
[0304465]583        echoAndLog "${FUNCNAME}(): Updating OpenGnsys Cloning Engine files"
[884b6ce]584        rsync -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
[45f1fe8]585        if [ $? -ne 0 ]; then
586                errorAndLog "${FUNCNAME}(): error while updating engine files"
[51b179a]587                exit 1
[45f1fe8]588        fi
[a3855dc]589        # Actualizar fichero de configuración del motor de clonación.
[c40710e]590        if ! grep -q "^TZ" $ENGINECFG; then
[a3855dc]591                TZ=$(timedatectl status | awk -F"[:()]" '/Time.*zone/ {print $2}')
[c40710e]592                cat << EOT >> $ENGINECFG
[a3855dc]593# OpenGnsys Server timezone.
594TZ="${TZ// /}"
595EOT
596        fi
[d3ec014]597        if ! diff -q ${ENGINECFG%.*}{.cfg,-LAST.cfg} &>/dev/null; then
[c40710e]598                NEWFILES="$NEWFILES $ENGINECFG"
599        else
[d3ec014]600                rm -f ${ENGINECFG%.*}-LAST.cfg
[c40710e]601        fi
[ec045b1]602        # Obtener URL para descargas adicionales.
603        DOWNLOADURL=$(oglivecli config download-url 2>/dev/null)
[a0081b7]604        DOWNLOADURL=${DOWNLOADURL:-"https://$OPENGNSYS_SERVER/trac/downloads"}
[a3855dc]605
[0304465]606        echoAndLog "${FUNCNAME}(): client files successfully updated"
[45f1fe8]607}
[4e51cb0]608
[5050850]609# Crear certificado para la firma de cargadores de arranque, si es necesario.
610function createCerts ()
611{
612        local SSLCFGDIR=$INSTALL_TARGET/client/etc/ssl
613        mkdir -p $SSLCFGDIR/{certs,private}
614        if [ ! -f $SSLCFGDIR/private/opengnsys.key ]; then
615                echoAndLog "${FUNCNAME}(): creating certificate files"
616                openssl req -new -x509 -newkey rsa:2048 -keyout $SSLCFGDIR/private/opengnsys.key -out $SSLCFGDIR/certs/opengnsys.crt -nodes -days 3650 -subj "/CN=OpenGnsys/"
617                openssl x509 -in $SSLCFGDIR/certs/opengnsys.crt -out $SSLCFGDIR/certs/opengnsys.cer -outform DER
618                echoAndLog "${FUNCNAME}(): certificate successfully created"
619        fi
620}
621
[3ce53a7]622# Configurar HTTPS y exportar usuario y grupo del servicio Apache.
623function apacheConfiguration ()
[4e51cb0]624{
[9215580]625        local config template module socketfile
[6f4d39b]626
[ec536c6]627        # Avtivar PHP-FPM.
628        echoAndLog "${FUNCNAME}(): configuring PHP-FPM"
629        service=$PHPFPMSERV
630        $ENABLESERVICE; $STARTSERVICE
631
[9215580]632        # Activar módulos de Apache.
[2e38f60]633        if [ -e $APACHECFGDIR/sites-available/opengnsys.conf ]; then
[0304465]634                echoAndLog "${FUNCNAME}(): Configuring Apache modules"
[3ce53a7]635                a2ensite default-ssl
[9215580]636                for module in $APACHEENABLEMODS; do a2enmod -q "$module"; done
637                for module in $APACHEDISABLEMODS; do a2dismod -q "${module//PHP7VERSION}"; done
[3ce53a7]638                a2ensite opengnsys
[5f21d34]639        elif [ -e $APACHECFGDIR/conf.modules.d ]; then
[0304465]640                echoAndLog "${FUNCNAME}(): Configuring Apache modules"
[5f21d34]641                sed -i '/rewrite/s/^#//' $APACHECFGDIR/*.conf
[3ce53a7]642        fi
[ec536c6]643        # Elegir plantilla según versión de Apache.
644        if [ -n "$(apachectl -v | grep "2\.[0-2]")" ]; then
645               template=$WORKDIR/opengnsys/server/etc/apache-prev2.4.conf.tmpl > $config
646        else
647               template=$WORKDIR/opengnsys/server/etc/apache.conf.tmpl
648        fi
[ea016a46]649        sockfile=$(find /run/php -name "php*.sock" -type s -print 2>/dev/null | tail -1)
[6f4d39b]650        # Actualizar configuración de Apache a partir de fichero de plantilla.
651        for config in $APACHECFGDIR/{,sites-available/}opengnsys.conf; do
[37481d8]652                if [ -e $config ]; then
653                        if [ -n "$sockfile" ]; then
654                                sed -e "s,CONSOLEDIR,$INSTALL_TARGET/www,g; s,proxy:fcgi:.*,proxy:unix:${sockfile%% *}|fcgi://localhost\",g" $template > $config
655                        else
656                                sed -e "s,CONSOLEDIR,$INSTALL_TARGET/www,g" $template > $config
657                        fi
658                fi
[900be258]659        done
660
661        # Reiniciar Apache.
[ec536c6]662        service=$APACHESERV; $STARTSERVICE
[900be258]663
[3ce53a7]664        # Variables de ejecución de Apache.
[4e51cb0]665        # - APACHE_RUN_USER
666        # - APACHE_RUN_GROUP
[2e38f60]667        if [ -f $APACHECFGDIR/envvars ]; then
668                source $APACHECFGDIR/envvars
[4e51cb0]669        fi
[2e38f60]670        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
[de8bbb1]671        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
[4e51cb0]672}
673
[4b96166]674# Configurar servicio Rsync.
675function rsyncConfigure()
676{
677        local service
678
679        # Configurar acceso a Rsync.
680        if [ ! -f /etc/rsyncd.conf ]; then
[0304465]681                echoAndLog "${FUNCNAME}(): Configuring Rsync service"
[65baf16]682                NEWFILES="$NEWFILES /etc/rsyncd.conf"
[4b96166]683                sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENTUSER/g" \
684                    $WORKDIR/opengnsys/repoman/etc/rsyncd.conf.tmpl > /etc/rsyncd.conf
685                # Habilitar Rsync.
686                if [ -f /etc/default/rsync ]; then
687                        perl -pi -e 's/RSYNC_ENABLE=.*/RSYNC_ENABLE=inetd/' /etc/default/rsync
688                fi
689                if [ -f $INETDCFGDIR/rsync ]; then
690                        perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/rsync
691                else
692                        cat << EOT > $INETDCFGDIR/rsync
693service rsync
694{
695        disable = no
696        socket_type = stream
697        wait = no
698        user = root
699        server = $(which rsync)
700        server_args = --daemon
701        log_on_failure += USERID
702        flags = IPv6
703}
704EOT
705                fi
706                # Activar e iniciar Rsync.
707                service="rsync"  $ENABLESERVICE
[ab7f563]708                service="xinetd"
709                $ENABLESERVICE; $STARTSERVICE
[4b96166]710        fi
711}
712
[5f21d34]713# Copiar ficheros del OpenGnsys Web Console.
[a0867b37]714function updateWebFiles()
715{
[2b793a8]716        local ERRCODE COMPATDIR f
717
[a0867b37]718        echoAndLog "${FUNCNAME}(): Updating web files..."
[2b793a8]719
720        # Copiar los ficheros nuevos conservando el archivo de configuración de acceso.
721        backupFile $INSTALL_TARGET/www/controlacceso.php
722        mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole
[884b6ce]723        rsync -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET
[2b793a8]724        ERRCODE=$?
725        mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www
[1635f45]726        rm -fr $INSTALL_TARGET/www/xajax
[900be258]727        unzip -o $WORKDIR/opengnsys/admin/slim-2.6.1.zip -d $INSTALL_TARGET/www/rest
[8b8e948]728        unzip -o $WORKDIR/opengnsys/admin/swagger-ui-2.2.5.zip -d $INSTALL_TARGET/www/rest
[d655cc4]729        if [ $ERRCODE != 0 ]; then
[a0867b37]730                errorAndLog "${FUNCNAME}(): Error updating web files."
731                exit 1
732        fi
[2b793a8]733        restoreFile $INSTALL_TARGET/www/controlacceso.php
734
[1a2fa9d8]735        # Cambiar acceso a protocolo HTTPS.
736        if grep -q "http://" $INSTALL_TARGET/www/controlacceso.php 2>/dev/null; then
737                echoAndLog "${FUNCNAME}(): updating web access file"
738                perl -pi -e 's!http://!https://!g' $INSTALL_TARGET/www/controlacceso.php
739                NEWFILES="$NEWFILES $INSTALL_TARGET/www/controlacceso.php"
740        fi
741
[2b793a8]742        # Compatibilidad con dispositivos móviles.
743        COMPATDIR="$INSTALL_TARGET/www/principal"
744        for f in acciones administracion aula aulas hardwares imagenes menus repositorios softwares; do
745                sed 's/clickcontextualnodo/clicksupnodo/g' $COMPATDIR/$f.php > $COMPATDIR/$f.device.php
746        done
[d70a45f]747        cp -a $COMPATDIR/imagenes.device.php $COMPATDIR/imagenes.device4.php
[aafe8f9]748        # Acceso al manual de usuario
749        ln -fs ../doc/userManual $INSTALL_TARGET/www/userManual
[0645906]750        # Fichero de log de la API REST.
751        touch $INSTALL_TARGET/log/{ogagent,rest,remotepc}.log
[2b793a8]752
[0304465]753        echoAndLog "${FUNCNAME}(): Web files successfully updated"
[a0867b37]754}
755
[ec045b1]756# Copiar ficheros en la zona de descargas de OpenGnsys Web Console.
757function updateDownloadableFiles()
758{
[4f445e0]759        local VERSIONFILE OGVERSION FILENAME TARGETFILE
760
761        # Obtener versión a descargar.
762        VERSIONFILE="$INSTALL_TARGET/doc/VERSION.json"
763        OGVERSION="$(jq -r ".ogagent // \"$NEWVERSION\"" $VERSIONFILE 2>/dev/null || echo "$NEWVERSION")"
764        FILENAME="ogagentpkgs-$OGVERSION.tar.gz"
765        TARGETFILE=$WORKDIR/$FILENAME
[ec045b1]766
767        # Descargar archivo comprimido, si es necesario.
768        if [ -s $PROGRAMDIR/$FILENAME ]; then
769                echoAndLog "${FUNCNAME}(): Moving $PROGRAMDIR/$FILENAME file to $(dirname $TARGETFILE)"
770                mv $PROGRAMDIR/$FILENAME $TARGETFILE
771        else
772                echoAndLog "${FUNCNAME}(): Downloading $FILENAME"
[884b6ce]773                curl $DOWNLOADURL/$FILENAME -o $TARGETFILE
[ec045b1]774        fi
775        if [ ! -s $TARGETFILE ]; then
776                errorAndLog "${FUNCNAME}(): Cannot download $FILENAME"
777                return 1
778        fi
779
780        # Descomprimir fichero en zona de descargas.
781        tar xvzf $TARGETFILE -C $INSTALL_TARGET/www/descargas
782        if [ $? != 0 ]; then
[0304465]783                errorAndLog "${FUNCNAME}(): Error uncompressing archive $FILENAME"
[884b6ce]784                return 1
[ec045b1]785        fi
786}
787
[72134d5]788# Copiar carpeta de Interface
[64dd765]789function updateInterfaceAdm()
[72134d5]790{
[27dc5ff]791        local errcode=0
[2b793a8]792
[72134d5]793        # Crear carpeta y copiar Interface
794        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
795        mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface
[884b6ce]796        rsync -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client
[27dc5ff]797        errcoce=$?
[72134d5]798        mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm
[27dc5ff]799        if [ $errcode -ne 0 ]; then
[72134d5]800                echoAndLog "${FUNCNAME}(): error while updating admin interface"
801                exit 1
802        fi
[0304465]803        echoAndLog "${FUNCNAME}(): Admin interface successfully updated"
[72134d5]804}
[a0867b37]805
[5d6bf97]806# Crear documentación Doxygen para la consola web.
807function makeDoxygenFiles()
808{
809        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
810        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
811                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
812        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
[0304465]813                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files"
[5d6bf97]814                return 1
815        fi
[45f1fe8]816        rm -fr "$INSTALL_TARGET/www/api"
[15b2a4e]817        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
818        rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf}
[0304465]819        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully"
[5d6bf97]820}
821
822
[a0867b37]823# Crea la estructura base de la instalación de opengnsys
824function createDirs()
825{
[eb9424f]826        # Crear estructura de directorios.
[a0867b37]827        echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}"
[8cb279b]828        local dir MKNETDIR
[7bb72f7]829
[cfad47b]830        mkdir -p ${INSTALL_TARGET}/{bin,doc,etc,lib,sbin,www}
[d7ece95]831        mkdir -p ${INSTALL_TARGET}/{client,images/groups}
[a0867b37]832        mkdir -p ${INSTALL_TARGET}/log/clients
[eb9424f]833        ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys
[7bb72f7]834        # Detectar directorio de instalación de TFTP.
835        if [ ! -L ${INSTALL_TARGET}/tftpboot ]; then
836                for dir in /var/lib/tftpboot /srv/tftp; do
837                        [ -d $dir ] && ln -fs $dir ${INSTALL_TARGET}/tftpboot
838                done
839        fi
[b4d8d51]840        mkdir -p $INSTALL_TARGET/tftpboot/{menu.lst,grub}/examples
[a0867b37]841        if [ $? -ne 0 ]; then
842                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
843                return 1
844        fi
[663cd905]845        ! [ -f $INSTALL_TARGET/tftpboot/menu.lst/templates/00unknown ] && mv $INSTALL_TARGET/tftpboot/menu.lst/templates/* $INSTALL_TARGET/tftpboot/menu.lst/examples
[b4d8d51]846        ! [ -f $INSTALL_TARGET/tftpboot/grub/templates/10 ] && mv $INSTALL_TARGET/tftpboot/grub/templates/* $INSTALL_TARGET/tftpboot/grub/examples
[a0867b37]847
[8cb279b]848        # Preparar arranque en red con Grub.
849        for f in grub-mknetdir grub2-mknetdir; do
850                if which $f &>/dev/null; then MKNETDIR=$f; fi
851        done
[5969a13]852        $MKNETDIR --net-directory=${INSTALL_TARGET}/tftpboot --subdir=grub
[8cb279b]853
[eb9424f]854        # Crear usuario ficticio.
855        if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then
856                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created"
857        else
[5f21d34]858                echoAndLog "${FUNCNAME}(): creating OpenGnsys user"
[eb9424f]859                useradd $OPENGNSYS_CLIENTUSER 2>/dev/null
860                if [ $? -ne 0 ]; then
[5f21d34]861                        errorAndLog "${FUNCNAME}(): error creating OpenGnsys user"
[eb9424f]862                        return 1
863                fi
864        fi
865
[57f7e9c]866        # Mover el fichero de registro al directorio de logs.
867        echoAndLog "${FUNCNAME}(): moving update log file"
868        mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE
[7669bca]869        chmod 600 $LOG_FILE
[57f7e9c]870
[a0867b37]871        echoAndLog "${FUNCNAME}(): directory paths created"
872        return 0
873}
874
[566e84f]875# Actualización incremental de la BD (versión actaul a actaul+1, hasta final-1 a final).
876function updateDatabase()
877{
878        local DBDIR="$WORKDIR/opengnsys/admin/Database"
879        local file FILES=""
880
881        echoAndLog "${FUNCNAME}(): looking for database updates"
882        pushd $DBDIR >/dev/null
883        # Bucle de actualización incremental desde versión actual a la final.
884        for file in $OPENGNSYS_DATABASE-*-*.sql; do
885                case "$file" in
886                        $OPENGNSYS_DATABASE-$OLDVERSION-$NEWVERSION.sql)
887                                # Actualización única de versión inicial y final.
888                                FILES="$FILES $file"
889                                break
890                                ;;
891                        $OPENGNSYS_DATABASE-*-postinst.sql)
892                                # Ignorar fichero específico de post-instalación.
893                                ;;
894                        $OPENGNSYS_DATABASE-$OLDVERSION-*.sql)
895                                # Actualización de versión n a n+1.
896                                FILES="$FILES $file"
[b5db03a]897                                OLDVERSION="$(echo ${file%.*} | cut -f3 -d-)"
[566e84f]898                                ;;
899                        $OPENGNSYS_DATABASE-*-$NEWVERSION.sql)
900                                # Última actualización de versión final-1 a final.
901                                if [ -n "$FILES" ]; then
902                                        FILES="$FILES $file"
903                                        break
904                                fi
905                                ;;
906                esac
907        done
908        # Aplicar posible actualización propia para la versión final.
909        file=$OPENGNSYS_DATABASE-$NEWVERSION.sql
910        if [ -n "$FILES" -o "$OLDVERSION" = "$NEWVERSION" -a -r $file ]; then
911                FILES="$FILES $file"
912        fi
913
914        popd >/dev/null
915        if [ -n "$FILES" ]; then
916                for file in $FILES; do
[0cfe47a]917                        importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $DBDIR/$file
[566e84f]918                done
919                echoAndLog "${FUNCNAME}(): database is update"
920        else
921                echoAndLog "${FUNCNAME}(): database unchanged"
922        fi
923}
924
[a0867b37]925# Copia ficheros de configuración y ejecutables genéricos del servidor.
[64dd765]926function updateServerFiles()
[bb30a50]927{
[c1e00e4]928        # No copiar ficheros del antiguo cliente Initrd
[873cf1e]929        local SOURCES=( repoman/bin \
[c1e00e4]930                        server/bin \
[3e7d77b]931                        server/lib \
[42a0e41]932                        admin/Sources/Services/ogAdmServerAux \
933                        admin/Sources/Services/ogAdmRepoAux \
[873cf1e]934                        server/tftpboot \
[5969a13]935                        /usr/lib/shim/shimx64.efi.signed \
936                        /usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed \
[bb30a50]937                        installer/opengnsys_uninstall.sh \
[6777e3e]938                        installer/opengnsys_export.sh \
939                        installer/opengnsys_import.sh \
[873cf1e]940                        doc )
941        local TARGETS=( bin \
942                        bin \
[3e7d77b]943                        lib \
[cdad332]944                        sbin/ogAdmServerAux \
945                        sbin/ogAdmRepoAux \
[873cf1e]946                        tftpboot \
[5969a13]947                        tftpboot/shimx64.efi.signed \
948                        tftpboot/grubx64.efi \
[9a2c0f9d]949                        lib/opengnsys_uninstall.sh \
[6777e3e]950                        lib/opengnsys_export.sh \
951                        lib/opengnsys_import.sh \
[873cf1e]952                        doc )
[a0867b37]953
954        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
955                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
956                exit 1
957        fi
958
959        echoAndLog "${FUNCNAME}(): updating files in server directories"
960        pushd $WORKDIR/opengnsys >/dev/null
961        local i
962        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
[27dc5ff]963                if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then
[884b6ce]964                        rsync -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}"))
[aa36857]965                else
[56f100f]966                        rsync -irplt "${SOURCES[i]}" $(readlink -m "$INSTALL_TARGET/${TARGETS[i]}")
[aa36857]967                fi
[a0867b37]968        done
969        popd >/dev/null
[df3cd7f]970        NEWFILES=""             # Ficheros de configuración que han cambiado de formato.
[f80f839]971        if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then
[df3cd7f]972                echoAndLog "${FUNCNAME}(): updating DHCP files"
[f80f839]973                perl -pi -e 's/pxelinux.0/grldr/' /etc/dhcp*/dhcpd*.conf
[a37e5fc4]974                service=$DHCPSERV; $STARTSERVICE
[df3cd7f]975                NEWFILES="/etc/dhcp*/dhcpd*.conf"
976        fi
[5969a13]977        if ! grep -q 'shimx64.efi.signed' /etc/dhcp*/dhcpd*.conf; then
978                echoAndLog "${FUNCNAME}(): updating DHCP files for UEFI computers"
979                UEFICFG="    # 0007 == x64 EFI boot\n"\
980"    if option arch = 00:07 {\n"\
981"        filename \"shimx64.efi.signed\";\n"\
982"    } else {\n"\
983"        filename \"grldr\";\n"\
984"    }"
[8f24716]985                sed -i -e 1i"option arch code 93 = unsigned integer 16;" -e s@"^.*grldr\"\;"@"$UEFICFG"@g /etc/dhcp*/dhcpd*.conf
[5969a13]986                service=$DHCPSERV; $STARTSERVICE
987                NEWFILES="/etc/dhcp*/dhcpd*.conf"
988        fi
[d372e6e]989        if ! diff -q $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys 2>/dev/null; then
[df3cd7f]990                echoAndLog "${FUNCNAME}(): updating new init file"
991                backupFile /etc/init.d/opengnsys
992                cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
993                NEWFILES="$NEWFILES /etc/init.d/opengnsys"
994        fi
[3b8ef0d]995        if ! diff -q $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys >/dev/null; then
996                echoAndLog "${FUNCNAME}(): updating new default file"
997                backupFile /etc/default/opengnsys
998                # Buscar si hay nuevos parámetros.
999                local var valor
1000                while IFS="=" read -e var valor; do
1001                        [[ $var =~ ^# ]] || \
1002                                grep -q "^$var=" /etc/default/opengnsys || \
1003                                echo "$var=$valor" >> /etc/default/opengnsys
1004                done < $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default
1005                NEWFILES="$NEWFILES /etc/default/opengnsys"
1006        fi
[1a2fa9d8]1007        if egrep -q "(UrlMsg=.*msgbrowser.php)|(UrlMenu=http://)" $INSTALL_TARGET/client/etc/ogAdmClient.cfg 2>/dev/null; then
[df3cd7f]1008                echoAndLog "${FUNCNAME}(): updating new client config file"
1009                backupFile $INSTALL_TARGET/client/etc/ogAdmClient.cfg
[1a2fa9d8]1010                perl -pi -e 's!UrlMsg=.*msgbrowser\.php!UrlMsg=http://localhost/cgi-bin/httpd-log\.sh!g; s!UrlMenu=http://!UrlMenu=https://!g' $INSTALL_TARGET/client/etc/ogAdmClient.cfg
[df3cd7f]1011                NEWFILES="$NEWFILES $INSTALL_TARGET/client/etc/ogAdmClient.cfg"
[f80f839]1012        fi
[a3855dc]1013
[9ee62ad]1014        echoAndLog "${FUNCNAME}(): updating cron files"
[db9e706]1015        [ ! -f /etc/cron.d/torrentcreator ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
1016        [ ! -f /etc/cron.d/torrenttracker ] && echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
[dc762088]1017        [ ! -f /etc/cron.d/imagedelete ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete
[0645906]1018        [ ! -f /etc/cron.d/ogagentqueue ] && echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/ogagentqueue.cron ] && $INSTALL_TARGET/bin/ogagentqueue.cron" > /etc/cron.d/ogagentqueue
[b4d8d51]1019
[d9b2413]1020        echoAndLog "${FUNCNAME}(): deleting deprecated cron file"
1021        [ -e /etc/cron.d/opengnsys ] && rm -f /etc/cron.d/opengnsys \
1022                                              $INSTALL_TARGET/bin/opengnsys.cron
1023
[b4d8d51]1024        # Se modifican los nombres de las plantilla PXE por compatibilidad con los equipos UEFI.
1025        if [ -f $INSTALL_TARGET/tftpboot/menu.lst/templates/01 ]; then
1026            BIOSPXEDIR="$INSTALL_TARGET/tftpboot/menu.lst/templates"
1027            mv $BIOSPXEDIR/01 $BIOSPXEDIR/10
[74e6712]1028            sed -i "s/\bMBR\b/1hd/" $BIOSPXEDIR/10
[b4d8d51]1029        fi
[8f24716]1030        echoAndLog "${FUNCNAME}(): server files successfully updated"
[a0867b37]1031}
1032
1033####################################################################
1034### Funciones de compilación de código fuente de servicios
1035####################################################################
1036
[dde65c7]1037# Mueve el fichero del nuevo servicio si es distinto al del directorio destino.
1038function moveNewService()
1039{
1040        local service
1041
1042        # Recibe 2 parámetros: fichero origen y directorio destino.
1043        [ $# == 2 ] || return 1
[ddcb0cf]1044        [ -f  $1 -a -d $2 ] || return 1
[dde65c7]1045
1046        # Comparar los ficheros.
[ddcb0cf]1047        if ! diff -q $1 $2/$(basename $1) &>/dev/null; then
[dde65c7]1048                # Parar los servicios si fuese necesario.
1049                [ -z "$NEWSERVICES" ] && service="opengnsys" $STOPSERVICE
1050                # Nuevo servicio.
1051                NEWSERVICES="$NEWSERVICES $(basename $1)"
1052                # Mover el nuevo fichero de servicio
1053                mv $1 $2
1054        fi
1055}
1056
1057
[bb30a50]1058# Recompilar y actualiza los serivicios y clientes.
[64dd765]1059function compileServices()
[a0867b37]1060{
[bb30a50]1061        local hayErrores=0
1062
[5f21d34]1063        # Compilar OpenGnsys Server
1064        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Admin Server"
[bb30a50]1065        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
[dde65c7]1066        make && moveNewService ogAdmServer $INSTALL_TARGET/sbin
[bb30a50]1067        if [ $? -ne 0 ]; then
[5f21d34]1068                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Admin Server"
[bb30a50]1069                hayErrores=1
1070        fi
1071        popd
[dde2db1]1072        # Parar antiguo servicio de repositorio.
[b351d8a]1073        pgrep ogAdmRepo > /dev/null && service="ogAdmRepo" $STOPSERVICE
[5f21d34]1074        # Compilar OpenGnsys Agent
[0304465]1075        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Server Agent"
[bb30a50]1076        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
[dde65c7]1077        make && moveNewService ogAdmAgent $INSTALL_TARGET/sbin
[bb30a50]1078        if [ $? -ne 0 ]; then
[0304465]1079                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Server Agent"
[bb30a50]1080                hayErrores=1
1081        fi
1082        popd
1083
[5f21d34]1084        # Compilar OpenGnsys Client
1085        echoAndLog "${FUNCNAME}(): Recompiling OpenGnsys Client"
[72134d5]1086        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[e473667]1087        make && mv ogAdmClient $INSTALL_TARGET/client/bin
[a0867b37]1088        if [ $? -ne 0 ]; then
[5f21d34]1089                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Client"
[a0867b37]1090                hayErrores=1
1091        fi
1092        popd
[8f24716]1093        # Generar un API token de ogAdmServer si no existe en el fichero de configuración.
1094        grep -q "APITOKEN=" $INSTALL_TARGET/etc/ogAdmServer.cfg || \
[35f1277]1095                $INSTALL_TARGET/bin/settoken -f
[a0867b37]1096
1097        return $hayErrores
1098}
1099
1100
1101####################################################################
[5f21d34]1102### Funciones instalacion cliente OpenGnsys
[a0867b37]1103####################################################################
1104
[5f21d34]1105# Actualizar cliente OpenGnsys
[c1e00e4]1106function updateClient()
1107{
[2225984]1108        local FILENAME="ogLive-focal-5.11.0-22-generic-amd64-r20210413.992ebb9.iso"     # 1.1.1d
[0b85cc93]1109        local SOURCEFILE=$DOWNLOADURL/$FILENAME
[0496417]1110        local TARGETFILE=$(oglivecli config download-dir)/$FILENAME
[0b85cc93]1111        local SOURCELENGTH
1112        local TARGETLENGTH
[0496417]1113        local OGINITRD
[a63345ac]1114        local SAMBAPASS
[0b85cc93]1115
[0496417]1116        # Comprobar si debe convertirse el antiguo cliente al nuevo formato ogLive.
1117        if oglivecli check | grep -q "oglivecli convert"; then
1118                echoAndLog "${FUNCNAME}(): Converting OpenGnsys Client to default ogLive"
1119                oglivecli convert
1120        fi
[0b85cc93]1121        # Comprobar si debe actualizarse el cliente.
[5f0c2dd]1122        SOURCELENGTH=$(curl -sI $SOURCEFILE 2>&1 | awk '/Content-Length:/ {gsub("\r", ""); print $2}')
[0496417]1123        TARGETLENGTH=$(stat -c "%s" $TARGETFILE 2>/dev/null)
[d4e90c1]1124        [ -z $TARGETLENGTH ] && TARGETLENGTH=0
[0b85cc93]1125        if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then
[ec045b1]1126                echoAndLog "${FUNCNAME}(): Downloading $FILENAME"
[0496417]1127                oglivecli download $FILENAME
[0b85cc93]1128                if [ ! -s $TARGETFILE ]; then
[ec045b1]1129                        errorAndLog "${FUNCNAME}(): Error downloading $FILENAME"
[0b85cc93]1130                        return 1
1131                fi
[1893b9d]1132                # Actaulizar la imagen ISO del ogclient.
[0304465]1133                echoAndLog "${FUNCNAME}(): Updatting ogLive client"
[0496417]1134                oglivecli install $FILENAME
[e1c01217]1135               
[2e1b900]1136                INSTALLEDOGLIVE=${FILENAME%.*}
[ee4beb4]1137
[0304465]1138                echoAndLog "${FUNCNAME}(): ogLive successfully updated"
[0b85cc93]1139        else
[65baf16]1140                # Si no existe, crear el fichero de claves de Rsync.
1141                if [ ! -f /etc/rsyncd.secrets ]; then
[ec045b1]1142                        echoAndLog "${FUNCNAME}(): Restoring ogLive access key"
[0496417]1143                        OGINITRD=$(oglivecli config install-dir)/$(jq -r ".oglive[.default].directory")/oginitrd.img
[65baf16]1144                        SAMBAPASS=$(gzip -dc $OGINITRD | \
1145                                    cpio -i --to-stdout scripts/ogfunctions 2>&1 | \
1146                                    grep "^[    ].*OPTIONS=" | \
1147                                    sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')
[0496417]1148                        echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | setsmbpass
[65baf16]1149                else
[ec045b1]1150                        echoAndLog "${FUNCNAME}(): ogLive is already updated"
[65baf16]1151                fi
[04e5d96]1152                # Versión del ogLive instalado.
1153                echo "${FILENAME%.*}" > $INSTALL_TARGET/doc/veroglive.txt
[c1e00e4]1154        fi
1155}
[a0867b37]1156
[5b95ab6]1157# Comprobar permisos y ficheros.
1158function checkFiles()
1159{
[fbc7333]1160        local LOGROTATEDIR=/etc/logrotate.d
1161
[5b95ab6]1162        # Comprobar permisos adecuados.
1163        if [ -x $INSTALL_TARGET/bin/checkperms ]; then
[0304465]1164                echoAndLog "${FUNCNAME}(): Checking permissions"
[5b95ab6]1165                OPENGNSYS_DIR="$INSTALL_TARGET" OPENGNSYS_USER="$OPENGNSYS_CLIENTUSER" APACHE_USER="$APACHE_RUN_USER" APACHE_GROUP="$APACHE_RUN_GROUP" $INSTALL_TARGET/bin/checkperms
1166        fi
1167        # Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes
1168        if [ -f /tmp/dstate ]; then
[0304465]1169                echoAndLog "${FUNCNAME}(): Deleting unused files"
[5b95ab6]1170                rm -f /tmp/dstate
1171        fi
[59d6670]1172        # Crear nuevos ficheros de logrotate y borrar el fichero antiguo.
[fbc7333]1173        if [ -d $LOGROTATEDIR ]; then
[59d6670]1174                rm -f $LOGROTATEDIR/opengnsys
[fbc7333]1175                if [ ! -f $LOGROTATEDIR/opengnsysServer ]; then
1176                        echoAndLog "${FUNCNAME}(): Creating logrotate configuration file for server"
1177                        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
1178                                $WORKDIR/opengnsys/server/etc/logrotate.tmpl > $LOGROTATEDIR/opengnsysServer
1179                fi
1180                if [ ! -f $LOGROTATEDIR/opengnsysRepo ]; then
1181                        echoAndLog "${FUNCNAME}(): Creating logrotate configuration file for repository"
1182                        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
1183                                $WORKDIR/opengnsys/server/etc/logrotate.tmpl > $LOGROTATEDIR/opengnsysRepo
1184                fi
1185        fi
[5b95ab6]1186}
1187
[eb9424f]1188# Resumen de actualización.
1189function updateSummary()
1190{
1191        # Actualizar fichero de versión y revisión.
[884b6ce]1192        local VERSIONFILE REVISION
[3bbaf79]1193        VERSIONFILE="$INSTALL_TARGET/doc/VERSION.json"
[5f0c2dd]1194        # Obtener revisión.
1195        if [ $REMOTE -eq 1 ]; then
1196                # Revisión: rAñoMesDía.Gitcommit (8 caracteres de fecha y 7 primeros de commit).
[73c5e1c]1197                if [ "$BRANCH" = "main" ]; then
[663363a]1198                        REVISION=$(curl -s "$API_URL" | jq '"r" + (.commit.commit.committer.date | split("-") | join("")[:8]) + "." + (.commit.sha[:7])')
1199                else
1200                        REVISION=$(curl -s "$API_URL" | jq '"r" + (.commit.committer.date | split("-") | join("")[:8]) + "." + (.sha[:7])')
1201                fi
[5f0c2dd]1202        else
1203                # Parámetro "release" del fichero JSON.
1204                REVISION=$(jq -r '.release' $PROGRAMDIR/../doc/VERSION.json 2>/dev/null)
1205        fi
[3bbaf79]1206        [ -f $VERSIONFILE ] || echo '{ "project": "OpenGnsys" }' > $VERSIONFILE
1207        jq ".release=$REVISION" $VERSIONFILE | sponge $VERSIONFILE
1208        VERSION="$(jq -r '[.project, .version, .codename, .release] | join(" ")' $VERSIONFILE 2>/dev/null)"
1209        # Borrar antiguo fichero de versión.
1210        rm -f "${VERSIONFILE/json/txt}"
[eb9424f]1211
1212        echo
[5f21d34]1213        echoAndLog "OpenGnsys Update Summary"
[df3cd7f]1214        echo       "========================"
[3bbaf79]1215        echoAndLog "Project version:                  $VERSION"
[57f7e9c]1216        echoAndLog "Update log file:                  $LOG_FILE"
[c3e4ff1]1217        [ "$NEWFILES" ] && echoAndLog "Check new config files:           $(echo $NEWFILES)"
1218        [ "$NEWSERVICES" ] && echoAndLog "New compiled services:            $(echo $NEWSERVICES)"
[8b2da718]1219        echoAndLog "Warnings:"
[0304465]1220        echoAndLog " - You must to clear web browser cache before loading OpenGnsys page"
[dde2db1]1221        echoAndLog " - Run \"settoken\" script to update authentication tokens"
[c3e4ff1]1222        [ "$INSTALLEDOGLIVE" ] && echoAndLog " - Installed new ogLive Client: $INSTALLEDOGLIVE"
[ce63f8d]1223        echoAndLog " - If you want to use BURG as boot manager, run following command as root:"
1224        echoAndLog "      curl $DOWNLOADURL/burg.tgz -o $INSTALL_TARGET/client/lib/burg.tgz"
1225
[eb9424f]1226        echo
1227}
1228
1229
[a0867b37]1230
1231#####################################################################
[5f21d34]1232####### Proceso de actualización de OpenGnsys
[a0867b37]1233#####################################################################
1234
1235
[27dc5ff]1236# Comprobar si hay conexión y detectar parámetros de red por defecto.
1237checkNetworkConnection
1238if [ $? -ne 0 ]; then
1239        errorAndLog "Error connecting to server. Causes:"
[0304465]1240        errorAndLog " - Network is unreachable, check device parameters"
1241        errorAndLog " - You are inside a private network, configure the proxy service"
1242        errorAndLog " - Server is temporally down, try again later"
[27dc5ff]1243        exit 1
1244fi
[739fb00]1245getNetworkSettings
[27dc5ff]1246
[fd45e9a]1247# Elegir versión y comprobar si se intanta actualizar a una versión anterior.
1248chooseVersion
[0304465]1249checkVersion
1250if [ $? -ne 0 ]; then
1251        errorAndLog "Cannot downgrade to an older version ($OLDVERSION to $NEWVERSION)"
1252        errorAndLog "You must to uninstall OpenGnsys and install desired release"
1253        exit 1
1254fi
1255
[663363a]1256echoAndLog "OpenGnsys update begins at $(date)"
1257pushd $WORKDIR
1258
[64dd765]1259# Comprobar auto-actualización del programa.
1260if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then
1261        checkAutoUpdate
1262        if [ $? -ne 0 ]; then
[0304465]1263                echoAndLog "OpenGnsys updater has been overwritten"
[063caa5]1264                echoAndLog "Please, run this script again"
[64dd765]1265                exit
1266        fi
1267fi
1268
[db9e706]1269# Detectar datos de auto-configuración del instalador.
1270autoConfigure
1271
[bb30a50]1272# Instalar dependencias.
[d70a45f]1273installDependencies ${DEPENDENCIES[*]}
[a0867b37]1274if [ $? -ne 0 ]; then
[0304465]1275        errorAndLog "Error: you must to install all needed dependencies"
[a0867b37]1276        exit 1
1277fi
1278
[5f21d34]1279# Arbol de directorios de OpenGnsys.
[a0867b37]1280createDirs ${INSTALL_TARGET}
1281if [ $? -ne 0 ]; then
[0304465]1282        errorAndLog "Error while creating directory paths"
[a0867b37]1283        exit 1
1284fi
1285
1286# Si es necesario, descarga el repositorio de código en directorio temporal
[884b6ce]1287if [ $REMOTE -eq 1 ]; then
1288        downloadCode $CODE_URL
[a0867b37]1289        if [ $? -ne 0 ]; then
[884b6ce]1290                errorAndLog "Error while getting code from repository"
[a0867b37]1291                exit 1
1292        fi
1293else
1294        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
1295fi
1296
[21372e8]1297# Comprobar configuración de MySQL.
1298checkMysqlConfig $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD
1299
[566e84f]1300# Actualizar la BD.
1301updateDatabase
[295b4ab]1302
1303# Actualizar ficheros complementarios del servidor
[a0867b37]1304updateServerFiles
1305if [ $? -ne 0 ]; then
[5f21d34]1306        errorAndLog "Error updating OpenGnsys Server files"
[a0867b37]1307        exit 1
1308fi
1309
[be49575]1310# Configurar Rsync.
1311rsyncConfigure
1312
[5050850]1313# Actualizar ficheros del cliente.
[295b4ab]1314updateClientFiles
[5050850]1315createCerts
[295b4ab]1316updateInterfaceAdm
[45f1fe8]1317
[5050850]1318# Actualizar páqinas web.
[3ce53a7]1319apacheConfiguration
[a0867b37]1320updateWebFiles
1321if [ $? -ne 0 ]; then
[5f21d34]1322        errorAndLog "Error updating OpenGnsys Web Admin files"
[a0867b37]1323        exit 1
1324fi
[ec045b1]1325# Actaulizar ficheros descargables.
1326updateDownloadableFiles
[5d6bf97]1327# Generar páginas Doxygen para instalar en el web
1328makeDoxygenFiles
[a0867b37]1329
[bb30a50]1330# Recompilar y actualizar los servicios del sistema
[c3e4ff1]1331if compileServices; then
1332        # Restart services, if necessary.
1333        if [ "$NEWSERVICES" ]; then
1334                echoAndLog "Restarting OpenGnsys services"
1335                service="opengnsys" $STARTSERVICE
1336        fi
1337else
1338        errorAndLog "Error compiling OpenGnsys services"
1339        exit 1
1340fi
[bb30a50]1341
1342# Actaulizar ficheros auxiliares del cliente
[a0867b37]1343updateClient
1344if [ $? -ne 0 ]; then
[0304465]1345        errorAndLog "Error updating client files"
[a0867b37]1346        exit 1
1347fi
1348
[5b95ab6]1349# Comprobar permisos y ficheros.
1350checkFiles
[3320409]1351
[eb9424f]1352# Mostrar resumen de actualización.
1353updateSummary
1354
[3b8ef0d]1355rm -rf $WORKDIR
[5f21d34]1356echoAndLog "OpenGnsys update finished at $(date)"
[a0867b37]1357
1358popd
1359
Note: See TracBrowser for help on using the repository browser.