source: installer/opengnsys_installer.sh @ ea01a0db

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 ea01a0db was 9e64d82, checked in by Ramón M. Gómez <ramongomez@…>, 7 years ago

#869: Adaptación de paquetes en Ubuntu 18.04 y evitar redundancias al detectar parámetros de red.

  • Property mode set to 100755
File size: 58.7 KB
RevLine 
[a01156a]1#!/bin/bash
2
3#####################################################################
[5f21d34]4####### Script instalador OpenGnsys
5####### Autor: Luis Guillén <lguillen@unizar.es>
[a01156a]6#####################################################################
7
8
[9672640]9####  AVISO: Puede editar configuración de acceso por defecto.
10####  WARNING: Edit default access configuration if you wish.
11DEFAULT_MYSQL_ROOT_PASSWORD="passwordroot"      # Clave por defecto root de MySQL
[5f21d34]12DEFAULT_OPENGNSYS_DB_USER="usuog"               # Usuario por defecto de acceso a la base de datos
[9672640]13DEFAULT_OPENGNSYS_DB_PASSWD="passusuog"         # Clave por defecto de acceso a la base de datos
14DEFAULT_OPENGNSYS_CLIENT_PASSWD="og"            # Clave por defecto de acceso del cliente       
[4a3cd1f]15
[1e7eaab]16# Sólo ejecutable por usuario root
[6ef01d9]17if [ "$(whoami)" != 'root' ]; then
[1e7eaab]18        echo "ERROR: this program must run under root privileges!!"
19        exit 1
20fi
[9672640]21
[5f21d34]22echo -e "\\nOpenGnsys Installation"
[9672640]23echo "=============================="
24
25# Clave root de MySQL
26while : ; do
27        echo -n -e "\\nEnter root password for MySQL (${DEFAULT_MYSQL_ROOT_PASSWORD}): ";
[6019b12]28        read -r MYSQL_ROOT_PASSWORD
[9672640]29        if [ -n "${MYSQL_ROOT_PASSWORD//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico
30                echo -e "\\aERROR: Must be alphanumeric, try again..."
31        else
[6019b12]32                # Si esta vacio ponemos el valor por defecto
33                MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-$DEFAULT_MYSQL_ROOT_PASSWORD}"
[9672640]34                break
35        fi
36done
37
38# Usuario de acceso a la base de datos
39while : ; do
[5f21d34]40        echo -n -e "\\nEnter username for OpenGnsys console (${DEFAULT_OPENGNSYS_DB_USER}): "
[6019b12]41        read -r OPENGNSYS_DB_USER
[9672640]42        if [ -n "${OPENGNSYS_DB_USER//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico
43                echo -e "\\aERROR: Must be alphanumeric, try again..."
44        else
[6019b12]45                # Si esta vacio ponemos el valor por defecto
46                OPENGNSYS_DB_USER="${OPENGNSYS_DB_USER:-$DEFAULT_OPENGNSYS_DB_USER}"
[9672640]47                break
48        fi
49done
50
51# Clave de acceso a la base de datos
52while : ; do
[5f21d34]53        echo -n -e "\\nEnter password for OpenGnsys console (${DEFAULT_OPENGNSYS_DB_PASSWD}): "
[6019b12]54        read -r OPENGNSYS_DB_PASSWD
[9672640]55        if [ -n "${OPENGNSYS_DB_PASSWD//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico
56                echo -e "\\aERROR: Must be alphanumeric, try again..."
57        else
[6019b12]58                # Si esta vacio ponemos el valor por defecto
59                OPENGNSYS_DB_PASSWD="${OPENGNSYS_DB_PASSWD:-$DEFAULT_OPENGNSYS_DB_PASSWD}"
[9672640]60                break
61        fi
62done
63
64# Clave de acceso del cliente
65while : ; do
[5f21d34]66        echo -n -e "\\nEnter root password for OpenGnsys client (${DEFAULT_OPENGNSYS_CLIENT_PASSWD}): "
[6019b12]67        read -r OPENGNSYS_CLIENT_PASSWD
[9672640]68        if [ -n "${OPENGNSYS_CLIENT_PASSWD//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico
69                echo -e "\\aERROR: Must be alphanumeric, try again..."
70        else
[6019b12]71                # Si esta vacio ponemos el valor por defecto
72                OPENGNSYS_CLIENT_PASSWD="${OPENGNSYS_CLIENT_PASSWD:-$DEFAULT_OPENGNSYS_CLIENT_PASSWD}"
[9672640]73                break
74        fi
75done
76
[6019b12]77# Selección de clientes ogLive para descargar.
78while : ; do
79        echo -e "\\nChoose ogLive client to install."
[e4546f2]80        echo -e "1) Kernel 4.13, 64-bit, EFI-compatible"
[6019b12]81        echo -e "2) Kernel 3.2, 32-bit"
82        echo -e "3) Both"
83        echo -n -e "Please, type a valid number (1): "
84        read -r OPT
85        case "$OPT" in
[e4546f2]86                1|"")   OGLIVE="ogLive-xenial-4.13.0-17-generic-amd64-r5520.iso"
[6019b12]87                        break ;;
88                2)      OGLIVE="ogLive-precise-3.2.0-23-generic-r5159.iso"
89                        break ;;
[e4546f2]90                3)      OGLIVE="ogLive-xenial-4.13.0-17-generic-amd64-r5520.iso ogLive-precise-3.2.0-23-generic-r5159.iso";
[6019b12]91                        break ;;
92                *)      echo -e "\\aERROR: unknown option, try again."
93        esac
94done
95
[9672640]96echo -e "\\n=============================="
[1e7eaab]97
[884b6ce]98# Comprobar si se ha descargado el paquete comprimido (REMOTE=0) o sólo el instalador (REMOTE=1).
[6019b12]99PROGRAMDIR=$(readlink -e "$(dirname "$0")")
[35b0ef1]100PROGRAMNAME=$(basename "$0")
[a0081b7]101OPENGNSYS_SERVER="opengnsys.es"
102DOWNLOADURL="https://$OPENGNSYS_SERVER/trac/downloads"
[1e7eaab]103if [ -d "$PROGRAMDIR/../installer" ]; then
[884b6ce]104        REMOTE=0
[1e7eaab]105else
[884b6ce]106        REMOTE=1
[1e7eaab]107fi
[884b6ce]108BRANCH="devel"
109CODE_URL="https://codeload.github.com/opengnsys/OpenGnsys/zip/$BRANCH"
110API_URL="https://api.github.com/repos/opengnsys/OpenGnsys/branches/$BRANCH"
[1e7eaab]111
[a01156a]112WORKDIR=/tmp/opengnsys_installer
[1e7eaab]113mkdir -p $WORKDIR
114
[5f21d34]115# Directorio destino de OpenGnsys.
[1e7eaab]116INSTALL_TARGET=/opt/opengnsys
[6019b12]117PATH=$PATH:$INSTALL_TARGET/bin
[42a0e41]118
119# Registro de incidencias.
120OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log
[acfb07d]121LOG_FILE=/tmp/$(basename $OGLOGFILE)
[a01156a]122
[fd021b0]123# Usuario del cliente para acceso remoto.
124OPENGNSYS_CLIENT_USER="opengnsys"
125
126# Nombre de la base datos y fichero SQL para su creación.
127OPENGNSYS_DATABASE="ogAdmBD"
128OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/${OPENGNSYS_DATABASE}.sql
[3aaf91d]129
[a01156a]130
131#####################################################################
[d168a46]132####### Funciones de configuración
133#####################################################################
134
135# Generar variables de configuración del instalador
136# Variables globales:
[5cc52295]137# - OSDISTRIB, OSVERSION - tipo y versión de la distribución GNU/Linux
[d168a46]138# - DEPENDENCIES - array de dependencias que deben estar instaladas
139# - UPDATEPKGLIST, INSTALLPKGS, CHECKPKGS - comandos para gestión de paquetes
[109e8b2]140# - INSTALLEXTRADEPS - instalar dependencias no incluidas en la distribución
[53fba30]141# - STARTSERVICE, ENABLESERVICE - iniciar y habilitar un servicio
[109e8b2]142# - STOPSERVICE, DISABLESERVICE - parar y deshabilitar un servicio
[53fba30]143# - APACHESERV, APACHECFGDIR, APACHESITESDIR, APACHEUSER, APACHEGROUP - servicio y configuración de Apache
[7825e9e]144# - APACHESSLMOD, APACHEENABLESSL, APACHEMAKECERT - habilitar módulo Apache y certificado SSL
[5f21d34]145# - APACHEENABLEOG, APACHEOGSITE, - habilitar sitio web de OpenGnsys
[53fba30]146# - INETDSERV - servicio Inetd
[09ac3b8]147# - FIREWALLSERV - servicio de cortabuegos IPTables/FirewallD
[53fba30]148# - DHCPSERV, DHCPCFGDIR - servicio y configuración de DHCP
[0f8100d]149# - MYSQLSERV, TMPMYCNF - servicio MySQL y fichero temporal con credenciales de acceso
150# - MARIADBSERV - servicio MariaDB (sustituto de MySQL en algunas distribuciones)
[e70925a]151# - RSYNCSERV, RSYNCCFGDIR - servicio y configuración de Rsync
[53fba30]152# - SAMBASERV, SAMBACFGDIR - servicio y configuración de Samba
[a16ce1b]153# - TFTPSERV, TFTPCFGDIR - servicio y configuración de TFTP/PXE
[d168a46]154function autoConfigure()
155{
[44f6582]156# Detectar sistema operativo del servidor (compatible con fichero os-release y con LSB).
157if [ -f /etc/os-release ]; then
158        source /etc/os-release
[eb7b39d]159        OSDISTRIB="$ID"
[5cc52295]160        OSVERSION="$VERSION_ID"
[44f6582]161else
162        OSDISTRIB=$(lsb_release -is 2>/dev/null)
[5cc52295]163        OSVERSION=$(lsb_release -rs 2>/dev/null)
[44f6582]164fi
[5cc52295]165# Convertir distribución a minúsculas y obtener solo el 1er número de versión.
[eb7b39d]166OSDISTRIB="${OSDISTRIB,,}"
[5cc52295]167OSVERSION="${OSVERSION%%.*}"
[d168a46]168
[eb7b39d]169# Configuración según la distribución GNU/Linux (usar minúsculas).
[d168a46]170case "$OSDISTRIB" in
[eb7b39d]171        ubuntu|debian|linuxmint)
[228dd16]172                DEPENDENCIES=( subversion apache2 php php-ldap libapache2-mod-php mysql-server php-mysql isc-dhcp-server bittorrent tftp-hpa tftpd-hpa xinetd build-essential g++-multilib libmysqlclient-dev wget curl doxygen graphviz bittornado ctorrent samba rsync unzip netpipes debootstrap schroot squashfs-tools btrfs-tools procps arp-scan realpath php-curl gettext moreutils jq wakeonlan udpcast shim-signed grub-efi-amd64-signed )
[d168a46]173                UPDATEPKGLIST="apt-get update"
174                INSTALLPKG="apt-get -y install --force-yes"
175                CHECKPKG="dpkg -s \$package 2>/dev/null | grep Status | grep -qw install"
[53fba30]176                if which service &>/dev/null; then
[7ba85a4]177                        STARTSERVICE="eval service \$service restart"
[109e8b2]178                        STOPSERVICE="eval service \$service stop"
[53fba30]179                else
[7ba85a4]180                        STARTSERVICE="eval /etc/init.d/\$service restart"
[109e8b2]181                        STOPSERVICE="eval /etc/init.d/\$service stop"
[53fba30]182                fi
[7ba85a4]183                ENABLESERVICE="eval update-rc.d \$service defaults"
[109e8b2]184                DISABLESERVICE="eval update-rc.d \$service disable"
[53fba30]185                APACHESERV=apache2
[d168a46]186                APACHECFGDIR=/etc/apache2
[643ca8c]187                APACHESITESDIR=sites-available
[53fba30]188                APACHEOGSITE=opengnsys
[d168a46]189                APACHEUSER="www-data"
190                APACHEGROUP="www-data"
[7ba85a4]191                APACHESSLMOD="a2enmod ssl"
[7829e4e]192                APACHEREWRITEMOD="a2enmod rewrite"
[7ba85a4]193                APACHEENABLESSL="a2ensite default-ssl"
[53fba30]194                APACHEENABLEOG="a2ensite $APACHEOGSITE"
[643ca8c]195                APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite"
[53fba30]196                DHCPSERV=isc-dhcp-server
[83518d5]197                DHCPCFGDIR=/etc/dhcp
[f243a47]198                INETDSERV=xinetd
199                INETDCFGDIR=/etc/xinetd.d
[53fba30]200                MYSQLSERV=mysql
[0f8100d]201                MARIADBSERV=mariadb
[e70925a]202                RSYNCSERV=rsync
203                RSYNCCFGDIR=/etc
[53fba30]204                SAMBASERV=smbd
[d168a46]205                SAMBACFGDIR=/etc/samba
206                TFTPCFGDIR=/var/lib/tftpboot
207                ;;
[eb7b39d]208        fedora|centos)
[228dd16]209                DEPENDENCIES=( subversion httpd mod_ssl php php-ldap mysql-server mysql-devel mysql-devel.i686 php-mysql dhcp tftp-server tftp xinetd binutils gcc gcc-c++ glibc-devel glibc-devel.i686 glibc-static glibc-static.i686 libstdc++-devel.i686 make wget curl doxygen graphviz ctorrent samba samba-client rsync unzip debootstrap schroot squashfs-tools python-crypto arp-scan procps-ng gettext moreutils jq net-tools http://ftp.altlinux.org/pub/distributions/ALTLinux/5.1/branch/$(arch)/RPMS.classic/netpipes-4.2-alt1.$(arch).rpm )
[325aac9]210                INSTALLEXTRADEPS=( 'pushd /tmp; wget -t3 http://download.bittornado.com/download/BitTornado-0.3.18.tar.gz && tar xvzf BitTornado-0.3.18.tar.gz && cd BitTornado-CVS && python setup.py install && ln -fs btlaunchmany.py /usr/bin/btlaunchmany && ln -fs bttrack.py /usr/bin/bttrack; popd' )
211                INSTALLPKG="yum install -y libstdc++ libstdc++.i686"
[c79a2b3]212                CHECKPKG="rpm -q --quiet \$package"
[03cfd6e]213                SYSTEMD=$(which systemctl 2>/dev/null)
214                if [ -n "$SYSTEMD" ]; then
215                        STARTSERVICE="eval systemctl start \$service.service"
216                        STOPSERVICE="eval systemctl stop \$service.service"
217                        ENABLESERVICE="eval systemctl enable \$service.service"
218                        DISABLESERVICE="eval systemctl disable \$service.service"
219                else
220                        STARTSERVICE="eval service \$service start"
221                        STOPSERVICE="eval service \$service stop"
222                        ENABLESERVICE="eval chkconfig \$service on"
223                        DISABLESERVICE="eval chkconfig \$service off"
224                fi
[53fba30]225                APACHESERV=httpd
[d168a46]226                APACHECFGDIR=/etc/httpd/conf.d
[53fba30]227                APACHEOGSITE=opengnsys.conf
[d168a46]228                APACHEUSER="apache"
229                APACHEGROUP="apache"
[5f21d34]230                APACHEREWRITEMOD="sed -i '/rewrite/s/^#//' $APACHECFGDIR/../*.conf"
[53fba30]231                DHCPSERV=dhcpd
[d168a46]232                DHCPCFGDIR=/etc/dhcp
[09ac3b8]233                if firewall-cmd --state &>/dev/null; then
234                        FIREWALLSERV=firewalld
235                else
236                        FIREWALLSERV=iptables
237                fi
[53fba30]238                INETDSERV=xinetd
[f243a47]239                INETDCFGDIR=/etc/xinetd.d
[53fba30]240                MYSQLSERV=mysqld
[0f8100d]241                MARIADBSERV=mariadb
[e70925a]242                RSYNCSERV=rsync
243                RSYNCCFGDIR=/etc
[53fba30]244                SAMBASERV=smb
[d168a46]245                SAMBACFGDIR=/etc/samba
[53fba30]246                TFTPSERV=tftp
[d168a46]247                TFTPCFGDIR=/var/lib/tftpboot
248                ;;
249        "")     echo "ERROR: Unknown Linux distribution, please install \"lsb_release\" command."
250                exit 1 ;;
[5f21d34]251        *)      echo "ERROR: Distribution not supported by OpenGnsys."
[d168a46]252                exit 1 ;;
253esac
[09bf701]254
255# Fichero de credenciales de acceso a MySQL.
256TMPMYCNF=/tmp/.my.cnf.$$
[d168a46]257}
258
[09ac3b8]259
[ff6c349]260# Modificar variables de configuración tras instalar paquetes del sistema.
261function autoConfigurePost()
262{
[09ac3b8]263local f
264
[44f6582]265# Configuraciones específicas para Samba y TFTP en Debian 6.
266[ -z "$SYSTEMD" -a ! -e /etc/init.d/$SAMBASERV ] && SAMBASERV=samba
267[ ! -e $TFTPCFGDIR ] && TFTPCFGDIR=/srv/tftp
268
[09ac3b8]269# Configuraciones específicas para SELinux permisivo en distintas versiones.
[44f6582]270[ -f /selinux/enforce ] && echo 0 > /selinux/enforce
[e5f9c147]271for f in /etc/sysconfig/selinux /etc/selinux/config; do
[4fdf2b1]272        [ -f $f ] && perl -pi -e 's/SELINUX=enforcing/SELINUX=permissive/g' $f
[09ac3b8]273done
274selinuxenabled 2>/dev/null && setenforce 0 2>/dev/null
[ff6c349]275}
276
277
[83518d5]278# Cargar lista de paquetes del sistema y actualizar algunas variables de configuración
279# dependiendo de la versión instalada.
280function updatePackageList()
281{
[a37e5fc4]282local DHCPVERSION PHP7VERSION
[83518d5]283
284# Si es necesario, actualizar la lista de paquetes disponibles.
285[ -n "$UPDATEPKGLIST" ] && eval $UPDATEPKGLIST
286
287# Configuración personallizada de algunos paquetes.
288case "$OSDISTRIB" in
[eb7b39d]289        ubuntu|linuxmint)       # Postconfiguación personalizada para Ubuntu.
[83518d5]290                # Configuración para DHCP v3.
[e4b1572]291                DHCPVERSION=$(apt-cache show $(apt-cache pkgnames|egrep "dhcp.?-server$") | \
[83518d5]292                              awk '/Version/ {print substr($2,1,1);}' | \
293                              sort -n | tail -1)
294                if [ $DHCPVERSION = 3 ]; then
[e4b1572]295                        DEPENDENCIES=( ${DEPENDENCIES[@]/isc-dhcp-server/dhcp3-server} )
[53fba30]296                        DHCPSERV=dhcp3-server
[83518d5]297                        DHCPCFGDIR=/etc/dhcp3
298                fi
[a37e5fc4]299                # Configuración para PHP 7 en Ubuntu.
300                if [ -z "$(apt-cache pkgnames php7)" ]; then
[668f7dc]301                        eval $INSTALLPKG software-properties-common
[21f78d1]302                        add-apt-repository -y ppa:ondrej/php
[668f7dc]303                        eval $UPDATEPKGLIST
[5e4fb7e]304                        PHP7VERSION=$(apt-cache pkgnames php7 | sort | head -1)
305                        DEPENDENCIES=( ${DEPENDENCIES[@]//php/$PHP7VERSION} )
[ad69c61]306                fi
[5e4fb7e]307                # Adaptar dependencias para libmysqlclient.
308                [ -z "$(apt-cache pkgnames libmysqlclient-dev)" ] && [ -n "$(apt-cache pkgnames libmysqlclient15)" ] && DEPENDENCIES=( ${DEPENDENCIES[@]//libmysqlclient-dev/libmysqlclient15} )
[9e64d82]309                # Paquete correcto para realpath.
310                [ -z "$(apt-cache pkgnames realpath)" ] && DEPENDENCIES=( ${DEPENDENCIES[@]//realpath/coreutils} )
[83518d5]311                ;;
[eb7b39d]312        centos) # Postconfiguación personalizada para CentOS.
[a37e5fc4]313                # Configuración para PHP 7.
314                if ! yum list php7 &>/dev/null; then
315                        if [ $OSVERSION -lt 7 ]; then
[325aac9]316                                yum install -y https://mirror.webtatic.com/yum/el$OSVERSION/latest.rpm
[a37e5fc4]317                                PHP7VERSION=$(yum list -q php7\*w | awk -F. '/^php/ {p=$1} END {print p}')
318                                DEPENDENCIES=( ${DEPENDENCIES[@]//php/$PHP5VERSION} )
[325aac9]319                        fi
320                fi
[2c8b9ed]321                # Cambios a aplicar a partir de CentOS 7.
322                if [ $OSVERSION -ge 7 ]; then
323                        # Sustituir MySQL por MariaDB.
324                        DEPENDENCIES=( ${DEPENDENCIES[*]/mysql-/mariadb-} )
[325aac9]325                        # Instalar ctorrent de EPEL para CentOS 6 (no disponible en CentOS 7).
326                        DEPENDENCIES=( ${DEPENDENCIES[*]/ctorrent/http://dl.fedoraproject.org/pub/epel/6/$(arch)/Packages/c/ctorrent-1.3.4-14.dnh3.3.2.el6.$(arch).rpm} )
[2c8b9ed]327                fi
[c525453]328                ;;
[eb7b39d]329        fedora) # Postconfiguación personalizada para Fedora.
[c525453]330                # Incluir paquetes específicos.
[325aac9]331                DEPENDENCIES=( ${DEPENDENCIES[@]} btrfs-progs )
[5cc52295]332                # Sustituir MySQL por MariaDB a partir de Fedora 20.
333                [ $OSVERSION -ge 20 ] && DEPENDENCIES=( ${DEPENDENCIES[*]/mysql-/mariadb-} )
[c79a2b3]334                ;;
[83518d5]335esac
336}
337
[d168a46]338
339#####################################################################
[a01156a]340####### Algunas funciones útiles de propósito general:
341#####################################################################
[d168a46]342
[13a01a7]343function getDateTime()
[a01156a]344{
[d168a46]345        date "+%Y%m%d-%H%M%S"
[a01156a]346}
347
348# Escribe a fichero y muestra por pantalla
[13a01a7]349function echoAndLog()
[a01156a]350{
[d168a46]351        local DATETIME=`getDateTime`
[87c7b02]352        echo "$1"
[d168a46]353        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
[a01156a]354}
355
[87c7b02]356# Escribe a fichero y muestra mensaje de error
[13a01a7]357function errorAndLog()
[a01156a]358{
[d168a46]359        local DATETIME=`getDateTime`
[87c7b02]360        echo "ERROR: $1"
[d168a46]361        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
[a01156a]362}
363
[346eaee]364# Escribe a fichero y muestra mensaje de aviso
365function warningAndLog()
366{
367        local DATETIME=`getDateTime`
[cd86637]368        echo "Warning: $1"
[346eaee]369        echo "$DATETIME;$SSH_CLIENT;Warning: $1" >> $LOG_FILE
370}
371
[87c7b02]372# Comprueba si el elemento pasado en $2 está en el array $1
[13a01a7]373function isInArray()
[a01156a]374{
375        if [ $# -ne 2 ]; then
[13a01a7]376                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]377                exit 1
378        fi
379
380        local deps
[87c7b02]381        local is_in_array=1
382        local element="$2"
383
384        echoAndLog "${FUNCNAME}(): checking if $2 is in $1"
[5c33840]385        eval "deps=( \"\${$1[@]}\" )"
[a01156a]386
[87c7b02]387        # Copia local del array del parámetro 1.
388        for (( i = 0 ; i < ${#deps[@]} ; i++ )); do
389                if [ "${deps[$i]}" = "${element}" ]; then
390                        echoAndLog "isInArray(): $element found in array"
[a01156a]391                        is_in_array=0
392                fi
393        done
394
395        if [ $is_in_array -ne 0 ]; then
[87c7b02]396                echoAndLog "${FUNCNAME}(): $element NOT found in array"
[a01156a]397        fi
398
399        return $is_in_array
400}
401
[87c7b02]402
[a01156a]403#####################################################################
404####### Funciones de manejo de paquetes Debian
405#####################################################################
406
[13a01a7]407function checkPackage()
[a01156a]408{
409        package=$1
410        if [ -z $package ]; then
[73cfa0a]411                errorAndLog "${FUNCNAME}(): parameter required"
[a01156a]412                exit 1
413        fi
[73cfa0a]414        echoAndLog "${FUNCNAME}(): checking if package $package exists"
[d168a46]415        eval $CHECKPKG
[a01156a]416        if [ $? -eq 0 ]; then
[73cfa0a]417                echoAndLog "${FUNCNAME}(): package $package exists"
[a01156a]418                return 0
419        else
[73cfa0a]420                echoAndLog "${FUNCNAME}(): package $package doesn't exists"
[a01156a]421                return 1
422        fi
423}
424
[87c7b02]425# Recibe array con dependencias
[a01156a]426# por referencia deja un array con las dependencias no resueltas
427# devuelve 1 si hay alguna dependencia no resuelta
[13a01a7]428function checkDependencies()
[a01156a]429{
430        if [ $# -ne 2 ]; then
[73cfa0a]431                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]432                exit 1
433        fi
434
[73cfa0a]435        echoAndLog "${FUNCNAME}(): checking dependences"
[a01156a]436        uncompletedeps=0
437
438        # copia local del array del parametro 1
439        local deps
[5c33840]440        eval "deps=( \"\${$1[@]}\" )"
[a01156a]441
442        declare -a local_notinstalled
[5c33840]443
[a01156a]444        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
445        do
446                checkPackage ${deps[$i]}
447                if [ $? -ne 0 ]; then
448                        local_notinstalled[$uncompletedeps]=$package
449                        let uncompletedeps=uncompletedeps+1
450                fi
451        done
452
453        # relleno el array especificado en $2 por referencia
454        for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ ))
455        do
456                eval "${2}[$i]=${local_notinstalled[$i]}"
457        done
458
459        # retorna el numero de paquetes no resueltos
[73cfa0a]460        echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps"
[a01156a]461        return $uncompletedeps
462}
463
464# Recibe un array con las dependencias y lo instala
[13a01a7]465function installDependencies()
[a01156a]466{
467        if [ $# -ne 1 ]; then
[813f617]468                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]469                exit 1
470        fi
[813f617]471        echoAndLog "${FUNCNAME}(): installing uncompleted dependencies"
[a01156a]472
473        # copia local del array del parametro 1
474        local deps
[5c33840]475        eval "deps=( \"\${$1[@]}\" )"
[a01156a]476
477        local string_deps=""
478        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
479        do
480                string_deps="$string_deps ${deps[$i]}"
481        done
482
483        if [ -z "${string_deps}" ]; then
[813f617]484                errorAndLog "${FUNCNAME}(): array of dependeces is empty"
[a01156a]485                exit 1
486        fi
487
[c79a2b3]488        OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND            # Debian/Ubuntu
[a01156a]489        export DEBIAN_FRONTEND=noninteractive
490
[d168a46]491        echoAndLog "${FUNCNAME}(): now $string_deps will be installed"
492        eval $INSTALLPKG $string_deps
[a01156a]493        if [ $? -ne 0 ]; then
[813f617]494                errorAndLog "${FUNCNAME}(): error installing dependencies"
[a01156a]495                return 1
496        fi
497
[c79a2b3]498        DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND            # Debian/Ubuntu
[6019b12]499        test grep -q "EPEL temporal" /etc/yum.repos.d/epel.repo 2>/dev/null || mv -f /etc/yum.repos.d/epel.repo.rpmnew /etc/yum.repos.d/epel.repo 2>/dev/null   # CentOS/RedHat EPEL
[c79a2b3]500
[813f617]501        echoAndLog "${FUNCNAME}(): dependencies installed"
[a01156a]502}
503
[13a01a7]504# Hace un backup del fichero pasado por parámetro
505# deja un -last y uno para el día
506function backupFile()
507{
508        if [ $# -ne 1 ]; then
509                errorAndLog "${FUNCNAME}(): invalid number of parameters"
510                exit 1
511        fi
512
[d168a46]513        local file="$1"
514        local dateymd=`date +%Y%m%d`
[13a01a7]515
[d168a46]516        if [ ! -f "$file" ]; then
[346eaee]517                warningAndLog "${FUNCNAME}(): file $file doesn't exists"
[13a01a7]518                return 1
519        fi
520
[d168a46]521        echoAndLog "${FUNCNAME}(): making $file backup"
[13a01a7]522
523        # realiza una copia de la última configuración como last
[d168a46]524        cp -a "$file" "${file}-LAST"
[13a01a7]525
526        # si para el día no hay backup lo hace, sino no
[d168a46]527        if [ ! -f "${file}-${dateymd}" ]; then
528                cp -a "$file" "${file}-${dateymd}"
[13a01a7]529        fi
530
[d168a46]531        echoAndLog "${FUNCNAME}(): $file backup success"
[13a01a7]532}
533
[a01156a]534#####################################################################
535####### Funciones para el manejo de bases de datos
536#####################################################################
537
538# This function set password to root
[13a01a7]539function mysqlSetRootPassword()
[a01156a]540{
541        if [ $# -ne 1 ]; then
[813f617]542                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]543                exit 1
544        fi
545
[e0edc14]546        local root_mysql="$1"
[813f617]547        echoAndLog "${FUNCNAME}(): setting root password in MySQL server"
[e0edc14]548        mysqladmin -u root password "$root_mysql"
[a01156a]549        if [ $? -ne 0 ]; then
[813f617]550                errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server"
[a01156a]551                return 1
552        fi
[813f617]553        echoAndLog "${FUNCNAME}(): root password saved!"
[a01156a]554        return 0
555}
556
[892606b9]557# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
[e0edc14]558function mysqlGetRootPassword()
559{
[892606b9]560        local pass_mysql
561        local pass_mysql2
[7c54b49]562        # Comprobar si MySQL está instalado con la clave de root por defecto.
563        if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then
564                echoAndLog "${FUNCNAME}(): Using default mysql root password."
565        else
566                stty -echo
[e0edc14]567                echo "There is a MySQL service already installed."
568                read -p "Enter MySQL root password: " pass_mysql
[7c54b49]569                echo ""
[e0edc14]570                read -p "Confrim password:" pass_mysql2
[7c54b49]571                echo ""
572                stty echo
573                if [ "$pass_mysql" == "$pass_mysql2" ] ;then
[e0edc14]574                        MYSQL_ROOT_PASSWORD="$pass_mysql"
[7c54b49]575                        return 0
576                else
[e0edc14]577                        echo "The keys don't match. Do not configure the server's key,"
578                        echo "transactions in the database will give error."
[7c54b49]579                        return 1
580                fi
[892606b9]581        fi
582}
583
[a01156a]584# comprueba si puede conectar con mysql con el usuario root
585function mysqlTestConnection()
586{
587        if [ $# -ne 1 ]; then
[e0edc14]588                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]589                exit 1
590        fi
591
[09bf701]592        local root_password="$1"
[e0edc14]593        echoAndLog "${FUNCNAME}(): checking connection to mysql..."
[09bf701]594        # Componer fichero con credenciales de conexión a MySQL.
595        touch $TMPMYCNF
596        chmod 600 $TMPMYCNF
597        cat << EOT > $TMPMYCNF
[c073224]598[client]
[09bf701]599user=root
600password=$root_password
601EOT
602        # Borrar el fichero temporal si termina el proceso de instalación.
603        trap "rm -f $TMPMYCNF" 0 1 2 3 6 9 15
604        # Comprobar conexión a MySQL.
605        echo "" | mysql --defaults-extra-file=$TMPMYCNF
[a01156a]606        if [ $? -ne 0 ]; then
[e0edc14]607                errorAndLog "${FUNCNAME}(): connection to mysql failed, check root password and if daemon is running!"
[a01156a]608                return 1
609        else
[e0edc14]610                echoAndLog "${FUNCNAME}(): connection success"
[a01156a]611                return 0
612        fi
613}
614
615# comprueba si la base de datos existe
616function mysqlDbExists()
617{
[09bf701]618        if [ $# -ne 1 ]; then
[e0edc14]619                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]620                exit 1
621        fi
622
[09bf701]623        local database="$1"
[e0edc14]624        echoAndLog "${FUNCNAME}(): checking if $database exists..."
[09bf701]625        echo "show databases" | mysql --defaults-extra-file=$TMPMYCNF | grep "^${database}$"
[a01156a]626        if [ $? -ne 0 ]; then
[e0edc14]627                echoAndLog "${FUNCNAME}():database $database doesn't exists"
[a01156a]628                return 1
629        else
[e0edc14]630                echoAndLog "${FUNCNAME}():database $database exists"
[a01156a]631                return 0
632        fi
633}
634
[0a735488]635# Comprueba si la base de datos está vacía.
[a01156a]636function mysqlCheckDbIsEmpty()
637{
[09bf701]638        if [ $# -ne 1 ]; then
[e0edc14]639                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]640                exit 1
641        fi
642
[09bf701]643        local database="$1"
[e0edc14]644        echoAndLog "${FUNCNAME}(): checking if $database is empty..."
[09bf701]645        num_tablas=`echo "show tables" | mysql --defaults-extra-file=$TMPMYCNF "${database}" | wc -l`
[a01156a]646        if [ $? -ne 0 ]; then
[e0edc14]647                errorAndLog "${FUNCNAME}(): error executing query, check database and root password"
[a01156a]648                exit 1
649        fi
650
651        if [ $num_tablas -eq 0 ]; then
[e0edc14]652                echoAndLog "${FUNCNAME}():database $database is empty"
[a01156a]653                return 0
654        else
[e0edc14]655                echoAndLog "${FUNCNAME}():database $database has tables"
[a01156a]656                return 1
657        fi
658
659}
660
[0a735488]661# Importa un fichero SQL en la base de datos.
662# Parámetros:
663# - 1: nombre de la BD.
664# - 2: fichero a importar.
665# Nota: el fichero SQL puede contener las siguientes palabras reservadas:
666# - SERVERIP: se sustituye por la dirección IP del servidor.
667# - DBUSER: se sustituye por usuario de conexión a la BD definido en este script.
668# - DBPASSWD: se sustituye por la clave de conexión a la BD definida en este script.
[a01156a]669function mysqlImportSqlFileToDb()
670{
[09bf701]671        if [ $# -ne 2 ]; then
[c5ce04c]672                errorAndLog "${FNCNAME}(): invalid number of parameters"
[a01156a]673                exit 1
674        fi
675
[09bf701]676        local database="$1"
677        local sqlfile="$2"
[c4321ae]678        local tmpfile=$(mktemp)
[d168a46]679        local i=0
680        local dev=""
[c4321ae]681        local status
[8e0f770]682        # Claves aleatorias para acceso a las APIs REST.
[7829e4e]683        local OPENGNSYS_APIKEY=$(php -r 'echo md5(uniqid(rand(), true));')
[f9b5714]684        OPENGNSYS_REPOKEY=$(php -r 'echo md5(uniqid(rand(), true));')
[a01156a]685
686        if [ ! -f $sqlfile ]; then
[c5ce04c]687                errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!"
[a01156a]688                return 1
689        fi
690
[d168a46]691        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
[c4321ae]692        chmod 600 $tmpfile
[d168a46]693        for dev in ${DEVICE[*]}; do
[73a1bd6]694                if [ "${DEVICE[i]}" == "$DEFAULTDEV" ]; then
[d168a46]695                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
696                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
697                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
[7829e4e]698                            -e "s/APIKEY/$OPENGNSYS_APIKEY/g" \
[8e0f770]699                            -e "s/REPOKEY/$OPENGNSYS_REPOKEY/g" \
[d168a46]700                                $sqlfile > $tmpfile
701                fi
702                let i++
703        done
[09bf701]704        mysql --defaults-extra-file=$TMPMYCNF --default-character-set=utf8 "${database}" < $tmpfile
[c4321ae]705        status=$?
706        rm -f $tmpfile
707        if [ $status -ne 0 ]; then
[c5ce04c]708                errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database"
[a01156a]709                return 1
710        fi
[c5ce04c]711        echoAndLog "${FUNCNAME}(): file imported to database $database"
[a01156a]712        return 0
713}
714
715# Crea la base de datos
716function mysqlCreateDb()
717{
[09bf701]718        if [ $# -ne 1 ]; then
[a555f49]719                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]720                exit 1
721        fi
722
[09bf701]723        local database="$1"
[a01156a]724
[a555f49]725        echoAndLog "${FUNCNAME}(): creating database..."
[09bf701]726        mysqladmin --defaults-extra-file=$TMPMYCNF create $database
[a01156a]727        if [ $? -ne 0 ]; then
[a555f49]728                errorAndLog "${FUNCNAME}(): error while creating database $database"
[a01156a]729                return 1
730        fi
[e47e131]731        # Quitar modo ONLY_FULL_GROUP_BY de MySQL (ticket #730).
732        mysql --defaults-extra-file=$TMPMYCNF -e "SET GLOBAL sql_mode=(SELECT TRIM(BOTH ',' FROM REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')));"
733
[a555f49]734        echoAndLog "${FUNCNAME}(): database $database created"
[a01156a]735        return 0
736}
737
[0a735488]738# Comprueba si ya está definido el usuario de acceso a la BD.
[a01156a]739function mysqlCheckUserExists()
740{
[09bf701]741        if [ $# -ne 1 ]; then
[e0edc14]742                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]743                exit 1
744        fi
745
[09bf701]746        local userdb="$1"
[a01156a]747
[e0edc14]748        echoAndLog "${FUNCNAME}(): checking if $userdb exists..."
[09bf701]749        echo "select user from user where user='${userdb}'\\G" |mysql --defaults-extra-file=$TMPMYCNF mysql | grep user
[a01156a]750        if [ $? -ne 0 ]; then
[e0edc14]751                echoAndLog "${FUNCNAME}(): user doesn't exists"
[a01156a]752                return 1
753        else
[e0edc14]754                echoAndLog "${FUNCNAME}(): user already exists"
[a01156a]755                return 0
756        fi
757
758}
759
760# Crea un usuario administrativo para la base de datos
761function mysqlCreateAdminUserToDb()
762{
[09bf701]763        if [ $# -ne 3 ]; then
[e0edc14]764                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]765                exit 1
766        fi
767
[09bf701]768        local database="$1"
769        local userdb="$2"
770        local passdb="$3"
[a01156a]771
[e0edc14]772        echoAndLog "${FUNCNAME}(): creating admin user ${userdb} to database ${database}"
[a01156a]773
774        cat > $WORKDIR/create_${database}.sql <<EOF
775GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
776GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
777FLUSH PRIVILEGES ;
778EOF
[09bf701]779        mysql --defaults-extra-file=$TMPMYCNF < $WORKDIR/create_${database}.sql
[a01156a]780        if [ $? -ne 0 ]; then
[e0edc14]781                errorAndLog "${FUNCNAME}(): error while creating user in mysql"
[a01156a]782                rm -f $WORKDIR/create_${database}.sql
783                return 1
784        else
[e0edc14]785                echoAndLog "${FUNCNAME}(): user created ok"
[a01156a]786                rm -f $WORKDIR/create_${database}.sql
787                return 0
788        fi
789}
790
791
792#####################################################################
[884b6ce]793####### Funciones para la descarga de código
[a01156a]794#####################################################################
795
[884b6ce]796# Obtiene el código fuente del proyecto desde el repositorio de GitHub.
797function downloadCode()
[13a01a7]798{
799        if [ $# -ne 1 ]; then
800                errorAndLog "${FUNCNAME}(): invalid number of parameters"
801                exit 1
802        fi
803
[6090a2d]804        local url="$1"
[13a01a7]805
[884b6ce]806        echoAndLog "${FUNCNAME}(): downloading code..."
[13a01a7]807
[884b6ce]808        curl "${url}" -o opengnsys.zip && unzip opengnsys.zip && mv "OpenGnsys-$BRANCH" opengnsys
[13a01a7]809        if [ $? -ne 0 ]; then
[5f21d34]810                errorAndLog "${FUNCNAME}(): error getting OpenGnsys code from $url"
[13a01a7]811                return 1
812        fi
[884b6ce]813        rm -f opengnsys.zip
814        echoAndLog "${FUNCNAME}(): code was downloaded"
[13a01a7]815        return 0
816}
817
818
[892606b9]819############################################################
[7586ca3]820###  Detectar red
821############################################################
822
[07c3a59]823# Comprobar si existe conexión.
824function checkNetworkConnection()
825{
[09ac3b8]826        echoAndLog "${FUNCNAME}(): Disabling Firewall: $FIREWALLSERV."
827        if [ -n "$FIREWALLSERV" ]; then
828                service=$FIREWALLSERV
[b83843c]829                $STOPSERVICE; $DISABLESERVICE
830        fi
[109e8b2]831
[5f21d34]832        echoAndLog "${FUNCNAME}(): Checking OpenGnsys server conectivity."
[a0081b7]833        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"opengnsys.es"}
[225e859]834        if which wget &>/dev/null; then
835                wget --spider -q $OPENGNSYS_SERVER
836        elif which curl &>/dev/null; then
837                curl --connect-timeout 10 -s $OPENGNSYS_SERVER -o /dev/null
838        else
839                echoAndLog "${FUNCNAME}(): Cannot execute \"wget\" nor \"curl\"."
840                return 1
841        fi
[07c3a59]842}
843
[140fbd5]844# Convierte nº de bits (notación CIDR) en máscara de red (gracias a FriedZombie en openwrt.org).
845cidr2mask ()
846{
847        # Number of args to shift, 255..255, first non-255 byte, zeroes
848        set -- $[ 5 - ($1 / 8) ] 255 255 255 255 $[ (255 << (8 - ($1 % 8))) & 255 ] 0 0 0
849        [ $1 -gt 1 ] && shift $1 || shift
850        echo ${1-0}.${2-0}.${3-0}.${4-0}
851}
852
[07c3a59]853# Obtener los parámetros de red de la interfaz por defecto.
[7586ca3]854function getNetworkSettings()
855{
[d168a46]856        # Arrays globales definidas:
857        # - DEVICE:     nombres de dispositivos de red activos.
858        # - SERVERIP:   IPs locales del servidor.
859        # - NETIP:      IPs de redes.
860        # - NETMASK:    máscaras de red.
861        # - NETBROAD:   IPs de difusión de redes.
862        # - ROUTERIP:   IPs de routers.
863        # Otras variables globales:
864        # - DEFAULTDEV: dispositivo de red por defecto.
865        # - DNSIP:      IP del servidor DNS principal.
866
867        local i=0
868        local dev=""
869
[109e8b2]870        echoAndLog "${FUNCNAME}(): Detecting network parameters."
[d168a46]871        DEVICE=( $(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}') )
872        if [ -z "$DEVICE" ]; then
873                errorAndLog "${FUNCNAME}(): Network devices not detected."
[62e3bcf]874                exit 1
875        fi
[d168a46]876        for dev in ${DEVICE[*]}; do
[140fbd5]877                SERVERIP[i]=$(ip -o addr show dev "$dev" | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
[d168a46]878                if [ -n "${SERVERIP[i]}" ]; then
[140fbd5]879                        NETMASK[i]=$( cidr2mask $(ip -o addr show dev "$dev" | awk '$3~/inet$/ {sub (/.*\//, "", $4); print ($4)}') )
880                        NETBROAD[i]=$(ip -o addr show dev "$dev" | awk '$3~/inet$/ {print ($6)}')
[9e64d82]881                        NETIP[i]=$(ip route list proto kernel | awk -v d="$dev" '$3==d && /src/ {sub (/\/.*/,""); print $1}')
882                        ROUTERIP[i]=$(ip route list default | awk -v d="$dev" '$5==d {print $3}')
[d168a46]883                        DEFAULTDEV=${DEFAULTDEV:-"$dev"}
884                fi
[ce85ae8]885                let i++
[d168a46]886        done
[a555f49]887        DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1)
[03cfd6e]888        if [ -z "${NETIP[*]}" -o -z "${NETMASK[*]}" ]; then
[62e3bcf]889                errorAndLog "${FUNCNAME}(): Network not detected."
[7586ca3]890                exit 1
891        fi
[cc7eab7]892
893        # Variables de ejecución de Apache
894        # - APACHE_RUN_USER
895        # - APACHE_RUN_GROUP
[d168a46]896        if [ -f $APACHECFGDIR/envvars ]; then
897                source $APACHECFGDIR/envvars
[cc7eab7]898        fi
[d168a46]899        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
900        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
[73a1bd6]901
902        echoAndLog "${FUNCNAME}(): Default network device: $DEFAULTDEV."
[7586ca3]903}
904
905
906############################################################
[892606b9]907### Esqueleto para el Servicio pxe y contenedor tftpboot ###
908############################################################
909
[e0edc14]910function tftpConfigure()
911{
[109e8b2]912        echoAndLog "${FUNCNAME}(): Configuring TFTP service."
913        # Habilitar TFTP y reiniciar Inetd.
[8244351]914        if [ -n "$TFTPSERV" ]; then
[584b103]915                if [ -f $INETDCFGDIR/$TFTPSERV ]; then
916                        perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/$TFTPSERV
917                else
918                        service=$TFTPSERV
[b8969db]919                        $ENABLESERVICE; $STARTSERVICE
[584b103]920                fi
[8244351]921        fi
[53fba30]922        service=$INETDSERV
923        $ENABLESERVICE; $STARTSERVICE
[892606b9]924
[297df16]925        # comprobamos el servicio tftp
926        sleep 1
927        testPxe
[892606b9]928}
929
[0a735488]930# Comprueba que haya conexión al servicio TFTP/PXE.
[e0edc14]931function testPxe ()
932{
[297df16]933        echoAndLog "${FUNCNAME}(): Checking TFTP service... please wait."
[beaebf8]934        echo "test" >$TFTPCFGDIR/testpxe
935        tftp -v 127.0.0.1 -c get testpxe /tmp/testpxe && echoAndLog "TFTP service is OK." || errorAndLog "TFTP service is down."
936        rm -f $TFTPCFGDIR/testpxe /tmp/testpxe
[e4b1572]937}
938
939
940########################################################################
[5f21d34]941## Configuración servicio Samba
[8fc9552]942########################################################################
[e4b1572]943
944# Configurar servicios Samba.
[8fc9552]945function smbConfigure()
946{
[e0edc14]947        echoAndLog "${FUNCNAME}(): Configuring Samba service."
[8fc9552]948
[d168a46]949        backupFile $SAMBACFGDIR/smb.conf
[8fc9552]950       
[5f21d34]951        # Copiar plantailla de recursos para OpenGnsys
[c1e00e4]952        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
[d168a46]953                $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf
[813f617]954        # Configurar y recargar Samba"
[5f21d34]955        perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnsys Samba Server/" $SAMBACFGDIR/smb.conf
[03cfd6e]956        if ! grep -q "smb-og" $SAMBACFGDIR/smb.conf; then
957                echo "include = $SAMBACFGDIR/smb-og.conf" >> $SAMBACFGDIR/smb.conf
958        fi
[53fba30]959        service=$SAMBASERV
960        $ENABLESERVICE; $STARTSERVICE
[8fc9552]961        if [ $? -ne 0 ]; then
[813f617]962                errorAndLog "${FUNCNAME}(): error while configure Samba"
[8fc9552]963                return 1
964        fi
[eb9424f]965        # Crear clave para usuario de acceso a los recursos.
[813f617]966        echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | smbpasswd -a -s $OPENGNSYS_CLIENT_USER
[8fc9552]967
[813f617]968        echoAndLog "${FUNCNAME}(): Added Samba configuration."
[8fc9552]969        return 0
970}
971
972
[b6906f7]973########################################################################
[5f21d34]974## Configuración servicio Rsync
[e70925a]975########################################################################
976
977# Configurar servicio Rsync.
978function rsyncConfigure()
979{
980        echoAndLog "${FUNCNAME}(): Configuring Rsync service."
981
982        backupFile $RSYNCCFGDIR/rsyncd.conf
983
984        # Configurar acceso a Rsync.
985        sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENT_USER/g" \
986                $WORKDIR/opengnsys/repoman/etc/rsyncd.conf.tmpl > $RSYNCCFGDIR/rsyncd.conf
987        sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENT_USER/g" \
988            -e "s/CLIENTPASSWORD/$OPENGNSYS_CLIENT_PASSWD/g" \
989                $WORKDIR/opengnsys/repoman/etc/rsyncd.secrets.tmpl > $RSYNCCFGDIR/rsyncd.secrets
990        chown root.root $RSYNCCFGDIR/rsyncd.secrets
991        chmod 600 $RSYNCCFGDIR/rsyncd.secrets
992
993        # Habilitar Rsync y reiniciar Inetd.
994        if [ -n "$RSYNCSERV" ]; then
[4666588]995                if [ -f /etc/default/rsync ]; then
996                        perl -pi -e 's/RSYNC_ENABLE=.*/RSYNC_ENABLE=inetd/' /etc/default/rsync
997                fi
[f243a47]998                if [ -f $INETDCFGDIR/rsync ]; then
999                        perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/rsync
1000                else
1001                        cat << EOT > $INETDCFGDIR/rsync
1002service rsync
1003{
1004        disable = no
1005        socket_type = stream
1006        wait = no
1007        user = root
1008        server = $(which rsync)
1009        server_args = --daemon
1010        log_on_failure += USERID
1011        flags = IPv6
1012}
1013EOT
1014                fi
[e70925a]1015                service=$RSYNCSERV $ENABLESERVICE
1016                service=$INETDSERV $STARTSERVICE
1017        fi
1018
1019        echoAndLog "${FUNCNAME}(): Added Rsync configuration."
1020        return 0
1021}
1022
1023       
1024########################################################################
[5f21d34]1025## Configuración servicio DHCP
[b6906f7]1026########################################################################
1027
[e4b1572]1028# Configurar servicios DHCP.
[7586ca3]1029function dhcpConfigure()
1030{
[836a7597]1031        echoAndLog "${FUNCNAME}(): Sample DHCP configuration."
[a555f49]1032
[d168a46]1033        local errcode=0
1034        local i=0
1035        local dev=""
1036
1037        backupFile $DHCPCFGDIR/dhcpd.conf
1038        for dev in ${DEVICE[*]}; do
[01a9904]1039                if [ -n "${SERVERIP[i]}" ]; then
[d168a46]1040                        backupFile $DHCPCFGDIR/dhcpd-$dev.conf
[e4b1572]1041                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1042                            -e "s/NETIP/${NETIP[i]}/g" \
1043                            -e "s/NETMASK/${NETMASK[i]}/g" \
1044                            -e "s/NETBROAD/${NETBROAD[i]}/g" \
1045                            -e "s/ROUTERIP/${ROUTERIP[i]}/g" \
[d168a46]1046                            -e "s/DNSIP/$DNSIP/g" \
1047                            $WORKDIR/opengnsys/server/etc/dhcpd.conf.tmpl > $DHCPCFGDIR/dhcpd-$dev.conf || errcode=1
1048                fi
1049                let i++
1050        done
1051        if [ $errcode -ne 0 ]; then
[b25fc47]1052                errorAndLog "${FUNCNAME}(): error while configuring DHCP server"
[a555f49]1053                return 1
1054        fi
[d168a46]1055        ln -f $DHCPCFGDIR/dhcpd-$DEFAULTDEV.conf $DHCPCFGDIR/dhcpd.conf
[53fba30]1056        service=$DHCPSERV
1057        $ENABLESERVICE; $STARTSERVICE
[d168a46]1058        echoAndLog "${FUNCNAME}(): Sample DHCP configured in \"$DHCPCFGDIR\"."
[a555f49]1059        return 0
[892606b9]1060}
1061
1062
[a01156a]1063#####################################################################
1064####### Funciones específicas de la instalación de Opengnsys
1065#####################################################################
1066
[5f21d34]1067# Copiar ficheros del OpenGnsys Web Console.
[7586ca3]1068function installWebFiles()
1069{
[2b793a8]1070        local COMPATDIR f
[7829e4e]1071        local SLIMFILE="slim-2.6.1.zip"
[8b8e948]1072        local SWAGGERFILE="swagger-ui-2.2.5.zip"
[2b793a8]1073
[dce072b]1074        echoAndLog "${FUNCNAME}(): Installing web files..."
[2b793a8]1075        # Copiar ficheros.
1076        cp -a $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www   #*/ comentario para Doxygen.
[7586ca3]1077        if [ $? != 0 ]; then
[dce072b]1078                errorAndLog "${FUNCNAME}(): Error copying web files."
[7586ca3]1079                exit 1
1080        fi
[7829e4e]1081
[1635f45]1082        # Descomprimir librerías: Slim y Swagger-UI.
[7829e4e]1083        unzip -o $WORKDIR/opengnsys/admin/$SLIMFILE -d $INSTALL_TARGET/www/rest
[8b8e948]1084        unzip -o $WORKDIR/opengnsys/admin/$SWAGGERFILE -d $INSTALL_TARGET/www/rest
[7829e4e]1085
[2b793a8]1086        # Compatibilidad con dispositivos móviles.
1087        COMPATDIR="$INSTALL_TARGET/www/principal"
1088        for f in acciones administracion aula aulas hardwares imagenes menus repositorios softwares; do
1089                sed 's/clickcontextualnodo/clicksupnodo/g' $COMPATDIR/$f.php > $COMPATDIR/$f.device.php
1090        done
1091        cp -a $COMPATDIR/imagenes.device.php $COMPATDIR/imagenes.device4.php
[7586ca3]1092        # Cambiar permisos para ficheros especiales.
[e6d22c6]1093        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/{fotos,iconos}
[b7bd0df]1094        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/tmp/
[0645906]1095        # Ficheros de log de la API REST.
1096        touch $INSTALL_TARGET/log/{ogagent,remotepc,rest}.log
1097        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/log/{ogagent,remotepc,rest}.log
[2b793a8]1098
[dce072b]1099        echoAndLog "${FUNCNAME}(): Web files installed successfully."
[7586ca3]1100}
1101
[ec045b1]1102# Copiar ficheros en la zona de descargas de OpenGnsys Web Console.
1103function installDownloadableFiles()
1104{
[5e4fb7e]1105        INSTVERSION=1.1.0       ###  Temporal.
[ec045b1]1106        local FILENAME=ogagentpkgs-$INSTVERSION.tar.gz
1107        local TARGETFILE=$WORKDIR/$FILENAME
1108 
1109        # Descargar archivo comprimido, si es necesario.
1110        if [ -s $PROGRAMDIR/$FILENAME ]; then
1111                echoAndLog "${FUNCNAME}(): Moving $PROGRAMDIR/$FILENAME file to $(dirname $TARGETFILE)"
1112                mv $PROGRAMDIR/$FILENAME $TARGETFILE
1113        else
1114                echoAndLog "${FUNCNAME}(): Downloading $FILENAME"
[d5cbfa8]1115                curl $DOWNLOADURL/$FILENAME -o $TARGETFILE
[ec045b1]1116        fi
1117        if [ ! -s $TARGETFILE ]; then
1118                errorAndLog "${FUNCNAME}(): Cannot download $FILENAME"
1119                return 1
1120        fi
1121       
1122        # Descomprimir fichero en zona de descargas.
1123        tar xvzf $TARGETFILE -C $INSTALL_TARGET/www/descargas
1124        if [ $? != 0 ]; then
1125                errorAndLog "${FUNCNAME}(): Error uncompressing archive."
1126                exit 1
1127        fi
1128}
1129
[7586ca3]1130# Configuración específica de Apache.
[73a1bd6]1131function installWebConsoleApacheConf()
[a01156a]1132{
1133        if [ $# -ne 2 ]; then
[dce072b]1134                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]1135                exit 1
1136        fi
1137
[f9e3393]1138        local path_opengnsys_base="$1"
1139        local path_apache2_confd="$2"
[30837bb]1140        local CONSOLEDIR=${path_opengnsys_base}/www
[a01156a]1141
[892606b9]1142        if [ ! -d $path_apache2_confd ]; then
[dce072b]1143                errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation"
[892606b9]1144                return 1
1145        fi
1146
[7586ca3]1147        mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
[892606b9]1148
[dce072b]1149        echoAndLog "${FUNCNAME}(): creating apache2 config file.."
[a01156a]1150
[3ce53a7]1151        # Activar HTTPS.
[7825e9e]1152        $APACHESSLMOD
[643ca8c]1153        $APACHEENABLESSL
1154        $APACHEMAKECERT
[7829e4e]1155        # Activar módulo Rewrite.
1156        $APACHEREWRITEMOD
[30837bb]1157        # Genera configuración de consola web a partir del fichero plantilla.
[f9e3393]1158        if [ -n "$(apachectl -v | grep "2\.[0-2]")" ]; then
1159                # Configuración para versiones anteriores de Apache.
[6f4d39b]1160                sed -e "s,CONSOLEDIR,$CONSOLEDIR,g" \
[f3dde7e]1161                        $WORKDIR/opengnsys/server/etc/apache-prev2.4.conf.tmpl > $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}
[f9e3393]1162        else
1163                # Configuración específica a partir de Apache 2.4
[6f4d39b]1164                sed -e "s,CONSOLEDIR,$CONSOLEDIR,g" \
[f3dde7e]1165                        $WORKDIR/opengnsys/server/etc/apache.conf.tmpl > $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf
[f9e3393]1166        fi
[643ca8c]1167        $APACHEENABLEOG
[a01156a]1168        if [ $? -ne 0 ]; then
[dce072b]1169                errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation"
[a01156a]1170                return 1
1171        fi
[103bc82]1172        echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon"
1173        service=$APACHESERV
1174        $ENABLESERVICE; $STARTSERVICE
1175        return 0
[a01156a]1176}
1177
[8fc9552]1178
[5d6bf97]1179# Crear documentación Doxygen para la consola web.
1180function makeDoxygenFiles()
1181{
1182        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
1183        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
1184                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
1185        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
1186                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
[ead38fb]1187                return 1
[5d6bf97]1188        fi
1189        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
1190        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
1191        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
1192}
1193
1194
[a01156a]1195# Crea la estructura base de la instalación de opengnsys
[eb9424f]1196function createDirs()
[a01156a]1197{
1198        if [ $# -ne 1 ]; then
[dce072b]1199                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]1200                exit 1
1201        fi
1202
[eb9424f]1203        local path_opengnsys_base="$1"
[a01156a]1204
[eb9424f]1205        # Crear estructura de directorios.
[dce072b]1206        echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base"
[a01156a]1207        mkdir -p $path_opengnsys_base
1208        mkdir -p $path_opengnsys_base/bin
[d47ec6c]1209        mkdir -p $path_opengnsys_base/client/{cache,images,log}
[49c6891]1210        mkdir -p $path_opengnsys_base/doc
[5c33840]1211        mkdir -p $path_opengnsys_base/etc
[a01156a]1212        mkdir -p $path_opengnsys_base/lib
[1cc5697]1213        mkdir -p $path_opengnsys_base/log/clients
[eb9424f]1214        ln -fs $path_opengnsys_base/log /var/log/opengnsys
[7586ca3]1215        mkdir -p $path_opengnsys_base/sbin
[a01156a]1216        mkdir -p $path_opengnsys_base/www
[d7ece95]1217        mkdir -p $path_opengnsys_base/images/groups
[87c7b02]1218        mkdir -p $TFTPCFGDIR
[63fd1ba]1219        ln -fs $TFTPCFGDIR $path_opengnsys_base/tftpboot
[c30c33e]1220        mkdir -p $path_opengnsys_base/tftpboot/{menu.lst,grub}
[a01156a]1221        if [ $? -ne 0 ]; then
[dce072b]1222                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
[a01156a]1223                return 1
1224        fi
1225
[eb9424f]1226        # Crear usuario ficticio.
1227        if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then
1228                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created"
1229        else
[5f21d34]1230                echoAndLog "${FUNCNAME}(): creating OpenGnsys user"
[eb9424f]1231                useradd $OPENGNSYS_CLIENT_USER 2>/dev/null
1232                if [ $? -ne 0 ]; then
[5f21d34]1233                        errorAndLog "${FUNCNAME}(): error creating OpenGnsys user"
[eb9424f]1234                        return 1
1235                fi
1236        fi
1237
1238        # Establecer los permisos básicos.
1239        echoAndLog "${FUNCNAME}(): setting directory permissions"
[5eb61a6]1240        chmod -R 775 $path_opengnsys_base/{log/clients,images}
1241        chown -R :$OPENGNSYS_CLIENT_USER $path_opengnsys_base/{log/clients,images}
[eb9424f]1242        if [ $? -ne 0 ]; then
1243                errorAndLog "${FUNCNAME}(): error while setting permissions"
1244                return 1
1245        fi
1246
[7669bca]1247        # Mover el fichero de registro de instalación al directorio de logs.
[acfb07d]1248        echoAndLog "${FUNCNAME}(): moving installation log file"
1249        mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE
[7669bca]1250        chmod 600 $LOG_FILE
[acfb07d]1251
[dce072b]1252        echoAndLog "${FUNCNAME}(): directory paths created"
[a01156a]1253        return 0
1254}
1255
[463a1d49]1256# Copia ficheros de configuración y ejecutables genéricos del servidor.
[73a1bd6]1257function copyServerFiles ()
[e0edc14]1258{
[463a1d49]1259        if [ $# -ne 1 ]; then
[879689f]1260                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[463a1d49]1261                exit 1
1262        fi
1263
[7caf5a7c]1264        local path_opengnsys_base="$1"
[463a1d49]1265
[a43e90d]1266        # Lista de ficheros y directorios origen y de directorios destino.
[cfad47b]1267        local SOURCES=( server/tftpboot \
[98dedfc]1268                        /usr/lib/shim/shimx64.efi.signed \
[c30c33e]1269                        /usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed \
[7caf5a7c]1270                        server/bin \
1271                        repoman/bin \
[3e7d77b]1272                        server/lib \
[42a0e41]1273                        admin/Sources/Services/ogAdmServerAux
1274                        admin/Sources/Services/ogAdmRepoAux
[7caf5a7c]1275                        installer/opengnsys_uninstall.sh \
1276                        installer/opengnsys_update.sh \
[6777e3e]1277                        installer/opengnsys_export.sh \
1278                        installer/opengnsys_import.sh \
[7caf5a7c]1279                        doc )
[cfad47b]1280        local TARGETS=( tftpboot \
[c30c33e]1281                        tftpboot \
[98dedfc]1282                        tftpboot/grubx64.efi \
[7caf5a7c]1283                        bin \
1284                        bin \
[3e7d77b]1285                        lib \
[42a0e41]1286                        sbin \
1287                        sbin \
[7caf5a7c]1288                        lib \
1289                        lib \
[6777e3e]1290                        lib \
1291                        lib \
[7caf5a7c]1292                        doc )
[463a1d49]1293
1294        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
[879689f]1295                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
[463a1d49]1296                exit 1
1297        fi
1298
[a43e90d]1299        # Copiar ficheros.
[879689f]1300        echoAndLog "${FUNCNAME}(): copying files to server directories"
[f2bb433]1301
[8457092]1302        pushd $WORKDIR/opengnsys
[463a1d49]1303        local i
1304        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
1305                if [ -f "${SOURCES[$i]}" ]; then
[879689f]1306                        echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
[b5aae72]1307                        cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
[8457092]1308                elif [ -d "${SOURCES[$i]}" ]; then
[879689f]1309                        echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
[8457092]1310                        cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}"
[98dedfc]1311                else
[346eaee]1312                        warningAndLog "Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
[463a1d49]1313                fi
1314        done
[a43e90d]1315
[7586ca3]1316        popd
[892606b9]1317}
1318
[7586ca3]1319####################################################################
[5eb61a6]1320### Funciones de compilación de código fuente de servicios
[7586ca3]1321####################################################################
1322
[5f21d34]1323# Compilar los servicios de OpenGnsys
[7586ca3]1324function servicesCompilation ()
1325{
[13a01a7]1326        local hayErrores=0
[0795938]1327
[5f21d34]1328        # Compilar OpenGnsys Server
1329        echoAndLog "${FUNCNAME}(): Compiling OpenGnsys Admin Server"
[7b61735]1330        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
[d168a46]1331        make && mv ogAdmServer $INSTALL_TARGET/sbin
[13a01a7]1332        if [ $? -ne 0 ]; then
[5f21d34]1333                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Admin Server"
[13a01a7]1334                hayErrores=1
1335        fi
[7586ca3]1336        popd
[5f21d34]1337        # Compilar OpenGnsys Repository Manager
1338        echoAndLog "${FUNCNAME}(): Compiling OpenGnsys Repository Manager"
[7b61735]1339        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
[d168a46]1340        make && mv ogAdmRepo $INSTALL_TARGET/sbin
[13a01a7]1341        if [ $? -ne 0 ]; then
[5f21d34]1342                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Repository Manager"
[13a01a7]1343                hayErrores=1
1344        fi
[8125e7c]1345        popd
[5f21d34]1346        # Compilar OpenGnsys Agent
1347        echoAndLog "${FUNCNAME}(): Compiling OpenGnsys Agent"
[7b61735]1348        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
[d168a46]1349        make && mv ogAdmAgent $INSTALL_TARGET/sbin
[4984660]1350        if [ $? -ne 0 ]; then
[5f21d34]1351                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Agent"
[4984660]1352                hayErrores=1
1353        fi
1354        popd   
[5f21d34]1355        # Compilar OpenGnsys Client
1356        echoAndLog "${FUNCNAME}(): Compiling OpenGnsys Admin Client"
[7b61735]1357        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[2338c95f]1358        make && mv ogAdmClient ../../../../client/shared/bin
[13a01a7]1359        if [ $? -ne 0 ]; then
[5f21d34]1360                echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Admin Client"
[13a01a7]1361                hayErrores=1
1362        fi
[318efac]1363        popd
[13a01a7]1364
1365        return $hayErrores
[b6906f7]1366}
1367
[7b61735]1368####################################################################
1369### Funciones de copia de la Interface de administración
1370####################################################################
1371
1372# Copiar carpeta de Interface
[c1e00e4]1373function copyInterfaceAdm ()
[7b61735]1374{
1375        local hayErrores=0
1376       
[fbd9bcc]1377        # Crear carpeta y copiar Interface
[7b61735]1378        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
[fbd9bcc]1379        cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm
[7b61735]1380        if [ $? -ne 0 ]; then
1381                echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder"
1382                hayErrores=1
1383        fi
[b6f1726]1384        chown $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[f6c1d2b]1385        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[7b61735]1386
1387        return $hayErrores
1388}
[b6906f7]1389
[892606b9]1390####################################################################
1391### Funciones instalacion cliente opengnsys
1392####################################################################
1393
[73a1bd6]1394function copyClientFiles()
[7586ca3]1395{
[d168a46]1396        local errstatus=0
[a555f49]1397
[5f21d34]1398        echoAndLog "${FUNCNAME}(): Copying OpenGnsys Client files."
[73a1bd6]1399        cp -a $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
[d47d38d]1400        if [ $? -ne 0 ]; then
[9ef8920]1401                errorAndLog "${FUNCNAME}(): error while copying client estructure"
[d168a46]1402                errstatus=1
[9ef8920]1403        fi
1404       
[5f21d34]1405        echoAndLog "${FUNCNAME}(): Copying OpenGnsys Cloning Engine files."
[d47d38d]1406        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
[73a1bd6]1407        cp -a $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
[a555f49]1408        if [ $? -ne 0 ]; then
1409                errorAndLog "${FUNCNAME}(): error while copying engine files"
[d168a46]1410                errstatus=1
[a555f49]1411        fi
[9ef8920]1412       
[d168a46]1413        if [ $errstatus -eq 0 ]; then
[9ef8920]1414                echoAndLog "${FUNCNAME}(): client copy files success."
1415        else
1416                errorAndLog "${FUNCNAME}(): client copy files with errors"
1417        fi
1418
[d168a46]1419        return $errstatus
[463a1d49]1420}
1421
1422
[5f21d34]1423# Crear cliente OpenGnsys.
[5ad5dcc]1424function clientCreate()
[813f617]1425{
[6019b12]1426        if [ $# -ne 1 ]; then
1427                errorAndLog "${FUNCNAME}(): invalid number of parameters"
1428                exit 1
1429        fi
1430
1431        local FILENAME="$1"
[0b85cc93]1432        local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
[d168a46]1433 
[79c26a8]1434        # Descargar cliente, si es necesario.
1435        if [ -s $PROGRAMDIR/$FILENAME ]; then
1436                echoAndLog "${FUNCNAME}(): Moving $PROGRAMDIR/$FILENAME file to $(dirname $TARGETFILE)"
1437                mv $PROGRAMDIR/$FILENAME $TARGETFILE
1438        else
[ec045b1]1439                echoAndLog "${FUNCNAME}(): Downloading $FILENAME"
[6019b12]1440                oglivecli download $FILENAME
[79c26a8]1441        fi
[0b85cc93]1442        if [ ! -s $TARGETFILE ]; then
[ec045b1]1443                errorAndLog "${FUNCNAME}(): Error loading $FILENAME"
[813f617]1444                return 1
1445        fi
[1893b9d]1446
[79c26a8]1447        # Montar imagen, copiar cliente ogclient y desmontar.
[0496417]1448        echoAndLog "${FUNCNAME}(): Installing ogLive Client"
[6ef01d9]1449        echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | \
[6019b12]1450                        oglivecli install $FILENAME
[1893b9d]1451        # Adaptar permisos.
[beaebf8]1452        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/menu.lst
[6ef01d9]1453
[813f617]1454        echoAndLog "${FUNCNAME}(): Client generation success"
1455}
1456
1457
[5f21d34]1458# Configuración básica de servicios de OpenGnsys
[cc7eab7]1459function openGnsysConfigure()
1460{
[d168a46]1461        local i=0
1462        local dev=""
[7d4ce64]1463        local CONSOLEURL
[d168a46]1464
[9ee62ad]1465        echoAndLog "${FUNCNAME}(): Copying init files."
[42a0e41]1466        cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
1467        cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys
[b8969db]1468        # Deshabilitar servicios de BitTorrent si no están instalados.
1469        if [ ! -e /usr/bin/bttrack ]; then
[fdab5d0]1470                sed -i 's/RUN_BTTRACKER="yes"/RUN_BTTRACKER="no"/; s/RUN_BTSEEDER="yes"/RUN_BTSEEDER="no"/' \
[b8969db]1471                        /etc/default/opengnsys
1472        fi
[9ee62ad]1473        echoAndLog "${FUNCNAME}(): Creating cron files."
[57cf15b]1474        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys
[9ee62ad]1475        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
[8fc9552]1476        echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
[dc762088]1477        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete
[0645906]1478        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/ogagentqueue.cron ] && $INSTALL_TARGET/bin/ogagentqueue.cron" > /etc/cron.d/ogagentqueue
[d168a46]1479
[700299b]1480        echoAndLog "${FUNCNAME}(): Creating logrotate configuration file."
1481        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
1482                $WORKDIR/opengnsys/server/etc/logrotate.tmpl > /etc/logrotate.d/opengnsys
1483
[5f21d34]1484        echoAndLog "${FUNCNAME}(): Creating OpenGnsys config files."
[d168a46]1485        for dev in ${DEVICE[*]}; do
1486                if [ -n "${SERVERIP[i]}" ]; then
1487                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1488                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1489                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1490                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1491                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer/ogAdmServer.cfg > $INSTALL_TARGET/etc/ogAdmServer-$dev.cfg
1492                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
[f9b5714]1493                            -e "s/REPOKEY/$OPENGNSYS_REPOKEY/g" \
[d168a46]1494                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo/ogAdmRepo.cfg > $INSTALL_TARGET/etc/ogAdmRepo-$dev.cfg
1495                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1496                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1497                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1498                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1499                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent/ogAdmAgent.cfg > $INSTALL_TARGET/etc/ogAdmAgent-$dev.cfg
[1a2fa9d8]1500                        CONSOLEURL="https://${SERVERIP[i]}/opengnsys"
[d168a46]1501                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1502                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1503                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1504                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
[b22305e]1505                            -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \
[d168a46]1506                                $INSTALL_TARGET/www/controlacceso.php > $INSTALL_TARGET/www/controlacceso-$dev.php
1507                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
[d7f8305]1508                            -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \
[d168a46]1509                                $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient-$dev.cfg
[7d4ce64]1510                        if [ "$dev" == "$DEFAULTDEV" ]; then
[1a2fa9d8]1511                                OPENGNSYS_CONSOLEURL="$CONSOLEURL"
[7d4ce64]1512                        fi
[d168a46]1513                fi
1514                let i++
1515        done
1516        ln -f $INSTALL_TARGET/etc/ogAdmServer-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmServer.cfg
1517        ln -f $INSTALL_TARGET/etc/ogAdmRepo-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmRepo.cfg
1518        ln -f $INSTALL_TARGET/etc/ogAdmAgent-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmAgent.cfg
1519        ln -f $INSTALL_TARGET/client/etc/ogAdmClient-$DEFAULTDEV.cfg $INSTALL_TARGET/client/etc/ogAdmClient.cfg
1520        ln -f $INSTALL_TARGET/www/controlacceso-$DEFAULTDEV.php $INSTALL_TARGET/www/controlacceso.php
1521        chown root:root $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg
1522        chmod 600 $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg
1523        chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso*.php
1524        chmod 600 $INSTALL_TARGET/www/controlacceso*.php
[1f7b2d0]1525
[a3855dc]1526        # Configuración del motor de clonación.
1527        # - Zona horaria del servidor.
1528        TZ=$(timedatectl status|awk -F"[:()]" '/Time.*zone/ {print $2}')
1529        cat << EOT >> $INSTALL_TARGET/client/etc/engine.cfg
1530# OpenGnsys Server timezone.
1531TZ="${TZ// /}"
1532EOT
1533
[1f7b2d0]1534        # Revisar permisos generales.
1535        if [ -x $INSTALL_TARGET/bin/checkperms ]; then
1536                echoAndLog "${FUNCNAME}(): Checking permissions."
[6019b12]1537                OPENGNSYS_DIR="$INSTALL_TARGET" OPENGNSYS_USER="$OPENGNSYS_CLIENT_USER" APACHE_USER="$APACHE_RUN_USER" APACHE_GROUP="$APACHE_RUN_GROUP" checkperms
[1f7b2d0]1538        fi
1539
[4e19f13]1540        # Evitar inicio de duplicado en Ubuntu 14.04 (Upstart y SysV Init).
[c7ade22]1541        if [ -f /etc/init/${MYSQLSERV}.conf -a -n "$(which initctl 2>/dev/null)" ]; then
[4e19f13]1542                service=$MYSQLSERV
1543                $DISABLESERVICE
1544        fi
1545
[5f21d34]1546        echoAndLog "${FUNCNAME}(): Starting OpenGnsys services."
[53fba30]1547        service="opengnsys"
1548        $ENABLESERVICE; $STARTSERVICE
[cc7eab7]1549}
1550
[b6906f7]1551
[a01156a]1552#####################################################################
[180a07dd]1553#######  Función de resumen informativo de la instalación
1554#####################################################################
1555
[813f617]1556function installationSummary()
1557{
[832e27b]1558        local VERSIONFILE REVISION
1559
[eb9424f]1560        # Crear fichero de versión y revisión, si no existe.
[3bbaf79]1561        VERSIONFILE="$INSTALL_TARGET/doc/VERSION.json"
1562        [ -f $VERSIONFILE ] || echo '{ "project": "OpenGnsys" }' >$VERSIONFILE
1563        # Incluir datos de revisión, si se está instalando desde el repositorio
[130bdbf]1564        # de código o si no está incluida en el fichero de versión.
[3bbaf79]1565        if [ $REMOTE -eq 1 ] || [ -z "$(jq -r '.release' $VERSIONFILE)" ]; then
[832e27b]1566                # Revisión: rAñoMesDía.Gitcommit (8 caracteres de fecha y 7 primeros de commit).
[3bbaf79]1567                REVISION=$(curl -s "$API_URL" | jq '"r" + (.commit.commit.committer.date | gsub("-"; "")[:8]) + "." + (.commit.sha[:7])')
1568                jq ".release=$REVISION" $VERSIONFILE | sponge $VERSIONFILE
[130bdbf]1569        fi
[3bbaf79]1570        VERSION="$(jq -r '[.project, .version, .codename, .release] | join(" ")' $VERSIONFILE 2>/dev/null)"
[eb9424f]1571
1572        # Mostrar información.
[180a07dd]1573        echo
[5f21d34]1574        echoAndLog "OpenGnsys Installation Summary"
[180a07dd]1575        echo       "=============================="
[3bbaf79]1576        echoAndLog "Project version:                  $VERSION"
[49c6891]1577        echoAndLog "Installation directory:           $INSTALL_TARGET"
[acfb07d]1578        echoAndLog "Installation log file:            $LOG_FILE"
[49c6891]1579        echoAndLog "Repository directory:             $INSTALL_TARGET/images"
[d168a46]1580        echoAndLog "DHCP configuration directory:     $DHCPCFGDIR"
[87c7b02]1581        echoAndLog "TFTP configuration directory:     $TFTPCFGDIR"
[6019b12]1582        echoAndLog "Installed ogLive client(s):       $(oglivecli list | awk '{print $2}')"
[87c7b02]1583        echoAndLog "Samba configuration directory:    $SAMBACFGDIR"
[49c6891]1584        echoAndLog "Web Console URL:                  $OPENGNSYS_CONSOLEURL"
[35b0ef1]1585        echoAndLog "Web Console access data:          specified in installer script"
[b8969db]1586        if grep -q "^RUN_BTTRACK.*no" /etc/default/opengnsys; then
1587                echoAndLog "BitTorrent service is disabled."
1588        fi
[180a07dd]1589        echo
1590        echoAndLog "Post-Installation Instructions:"
1591        echo       "==============================="
[663c6625]1592        echoAndLog "Firewall service has been disabled and SELinux mode set to"
[5f21d34]1593        echoAndLog "   permissive during OpenGnsys installation. Please check"
[64f4ada]1594        echoAndLog "   ${FIREWALLSERV:-firewall} and SELinux configuration, if needed."
[4faafcd]1595        echoAndLog "It's strongly recommended to synchronize this server with an NTP server."
[180a07dd]1596        echoAndLog "Review or edit all configuration files."
[c5ce04c]1597        echoAndLog "Insert DHCP configuration data and restart service."
[af5efd6]1598        echoAndLog "Optional: Log-in as Web Console admin user."
1599        echoAndLog " - Review default Organization data and assign access to users."
[180a07dd]1600        echoAndLog "Log-in as Web Console organization user."
[5f21d34]1601        echoAndLog " - Insert OpenGnsys data (labs, computers, menus, etc)."
[180a07dd]1602echo
1603}
1604
1605
1606
1607#####################################################################
[5f21d34]1608####### Proceso de instalación de OpenGnsys
[a01156a]1609#####################################################################
1610
[5f21d34]1611echoAndLog "OpenGnsys installation begins at $(date)"
[6090a2d]1612pushd $WORKDIR
[cc7eab7]1613
[af5efd6]1614# Detectar datos iniciales de auto-configuración del instalador.
[d168a46]1615autoConfigure
1616
1617# Detectar parámetros de red y comprobar si hay conexión.
1618getNetworkSettings
1619if [ $? -ne 0 ]; then
1620        errorAndLog "Error reading default network settings."
1621        exit 1
1622fi
[07c3a59]1623checkNetworkConnection
1624if [ $? -ne 0 ]; then
1625        errorAndLog "Error connecting to server. Causes:"
1626        errorAndLog " - Network is unreachable, review devices parameters."
1627        errorAndLog " - You are inside a private network, configure the proxy service."
1628        errorAndLog " - Server is temporally down, try agian later."
1629        exit 1
1630fi
[7586ca3]1631
[5f21d34]1632# Detener servicios de OpenGnsys, si están activos previamente.
[e0edc14]1633[ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop
1634
[318efac]1635# Actualizar repositorios
[83518d5]1636updatePackageList
[318efac]1637
[b6906f7]1638# Instalación de dependencias (paquetes de sistema operativo).
[a01156a]1639declare -a notinstalled
1640checkDependencies DEPENDENCIES notinstalled
1641if [ $? -ne 0 ]; then
1642        installDependencies notinstalled
1643        if [ $? -ne 0 ]; then
1644                echoAndLog "Error while installing some dependeces, please verify your server installation before continue"
1645                exit 1
1646        fi
1647fi
[109e8b2]1648if [ -n "$INSTALLEXTRADEPS" ]; then
1649        echoAndLog "Installing extra dependencies"
1650        for (( i=0; i<${#INSTALLEXTRADEPS[*]}; i++ )); do
1651                eval ${INSTALLEXTRADEPS[i]}
1652        done
1653fi     
[a01156a]1654
[ff6c349]1655# Detectar datos de auto-configuración después de instalar paquetes.
1656autoConfigurePost
1657
[5f21d34]1658# Arbol de directorios de OpenGnsys.
[eb9424f]1659createDirs ${INSTALL_TARGET}
[a01156a]1660if [ $? -ne 0 ]; then
1661        errorAndLog "Error while creating directory paths!"
1662        exit 1
1663fi
[b6906f7]1664
[1e7eaab]1665# Si es necesario, descarga el repositorio de código en directorio temporal
[884b6ce]1666if [ $REMOTE -eq 1 ]; then
1667        downloadCode $CODE_URL
[1e7eaab]1668        if [ $? -ne 0 ]; then
[884b6ce]1669                errorAndLog "Error while getting code from the repository"
[1e7eaab]1670                exit 1
1671        fi
1672else
1673        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
[a01156a]1674fi
1675
[5f21d34]1676# Compilar código fuente de los servicios de OpenGnsys.
[b6906f7]1677servicesCompilation
[13a01a7]1678if [ $? -ne 0 ]; then
1679        errorAndLog "Error while compiling OpenGnsys services"
1680        exit 1
1681fi
[b6906f7]1682
[7b61735]1683# Copiar carpeta Interface entre administración y motor de clonación.
[c1e00e4]1684copyInterfaceAdm
[7b61735]1685if [ $? -ne 0 ]; then
[c1e00e4]1686        errorAndLog "Error while copying Administration Interface"
[7b61735]1687        exit 1
1688fi
1689
[e70925a]1690# Configuración de TFTP.
[318efac]1691tftpConfigure
[b6906f7]1692
[e70925a]1693# Configuración de Samba.
[8fc9552]1694smbConfigure
1695if [ $? -ne 0 ]; then
[c1e00e4]1696        errorAndLog "Error while configuring Samba server!"
[8fc9552]1697        exit 1
1698fi
1699
[e70925a]1700# Configuración de Rsync.
1701rsyncConfigure
1702
1703# Configuración ejemplo DHCP.
[b6906f7]1704dhcpConfigure
[a555f49]1705if [ $? -ne 0 ]; then
1706        errorAndLog "Error while copying your dhcp server files!"
1707        exit 1
1708fi
[b6906f7]1709
[5f21d34]1710# Copiar ficheros de servicios OpenGnsys Server.
[73a1bd6]1711copyServerFiles ${INSTALL_TARGET}
[463a1d49]1712if [ $? -ne 0 ]; then
1713        errorAndLog "Error while copying the server files!"
1714        exit 1
1715fi
[9815cac]1716INSTVERSION=$(jq -r '.version' $INSTALL_TARGET/doc/VERSION.json)
[463a1d49]1717
[5f21d34]1718# Instalar base de datos de OpenGnsys Admin.
[5cc52295]1719isInArray notinstalled "mysql-server" || isInArray notinstalled "mariadb-server"
[b6906f7]1720if [ $? -eq 0 ]; then
[094ac0d]1721        # Habilitar gestor de base de datos (MySQL, si falla, MariaDB).
1722        service=$MYSQLSERV
1723        $ENABLESERVICE
1724        if [ $? != 0 ]; then
1725                service=$MARIADBSERV
1726                $ENABLESERVICE
1727        fi
1728        # Activar gestor de base de datos.
[0f8100d]1729        $STARTSERVICE
[094ac0d]1730        # Asignar clave del usuario "root".
[09bf701]1731        mysqlSetRootPassword "${MYSQL_ROOT_PASSWORD}"
[b6906f7]1732else
[094ac0d]1733        # Si ya está instalado el gestor de bases de datos, obtener clave de "root",
[b6906f7]1734        mysqlGetRootPassword
1735fi
[463a1d49]1736
[09bf701]1737mysqlTestConnection "${MYSQL_ROOT_PASSWORD}"
[a01156a]1738if [ $? -ne 0 ]; then
1739        errorAndLog "Error while connection to mysql"
1740        exit 1
1741fi
[09bf701]1742mysqlDbExists ${OPENGNSYS_DATABASE}
[a01156a]1743if [ $? -ne 0 ]; then
[cc7eab7]1744        echoAndLog "Creating Web Console database"
[09bf701]1745        mysqlCreateDb ${OPENGNSYS_DATABASE}
[a01156a]1746        if [ $? -ne 0 ]; then
[cc7eab7]1747                errorAndLog "Error while creating Web Console database"
[a01156a]1748                exit 1
1749        fi
1750else
[cc7eab7]1751        echoAndLog "Web Console database exists, ommiting creation"
[a01156a]1752fi
1753
[09bf701]1754mysqlCheckUserExists ${OPENGNSYS_DB_USER}
[a01156a]1755if [ $? -ne 0 ]; then
1756        echoAndLog "Creating user in database"
[09bf701]1757        mysqlCreateAdminUserToDb ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
[a01156a]1758        if [ $? -ne 0 ]; then
[cc7eab7]1759                errorAndLog "Error while creating database user"
[a01156a]1760                exit 1
1761        fi
1762
1763fi
1764
[09bf701]1765mysqlCheckDbIsEmpty ${OPENGNSYS_DATABASE}
[a01156a]1766if [ $? -eq 0 ]; then
1767        echoAndLog "Creating tables..."
[892606b9]1768        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
[09bf701]1769                mysqlImportSqlFileToDb ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
[a01156a]1770        else
[892606b9]1771                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
[a01156a]1772                exit 1
1773        fi
[bc7dfe7]1774else
1775        # Si existe fichero ogBDAdmin-VersLocal-VersRepo.sql; aplicar cambios.
[9815cac]1776        REPOVERSION=$(jq -r '.version' $WORKDIR/opengnsys/doc/VERSION.json)
[295b4ab]1777        OPENGNSYS_DB_UPDATE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
1778        if [ -f $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE ]; then
[bc7dfe7]1779                echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION"
[09bf701]1780                mysqlImportSqlFileToDb ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE
[bc7dfe7]1781        else
1782                echoAndLog "Database unchanged."
1783        fi
[a01156a]1784fi
[09bf701]1785# Eliminar fichero temporal con credenciales de acceso a MySQL.
1786rm -f $TMPMYCNF
[a01156a]1787
[5f21d34]1788# Copiando páqinas web.
[7586ca3]1789installWebFiles
[ec045b1]1790# Descargar/descomprimir archivos descargables.
1791installDownloadableFiles
[5d6bf97]1792# Generar páqinas web de documentación de la API
1793makeDoxygenFiles
[a01156a]1794
[5f21d34]1795# Creando configuración de Apache.
[5fcf180]1796installWebConsoleApacheConf $INSTALL_TARGET $APACHECFGDIR
[a01156a]1797if [ $? -ne 0 ]; then
[5f21d34]1798        errorAndLog "Error configuring Apache for OpenGnsys Admin"
[a01156a]1799        exit 1
1800fi
1801
1802popd
[892606b9]1803
[9ef8920]1804# Crear la estructura de los accesos al servidor desde el cliente (shared)
[73a1bd6]1805copyClientFiles
[9ef8920]1806if [ $? -ne 0 ]; then
1807        errorAndLog "Error creating client structure"
1808fi
1809
[5f21d34]1810# Crear la estructura del cliente de OpenGnsys.
[6019b12]1811for i in $OGLIVE; do
1812        if ! clientCreate "$i"; then
1813                errorAndLog "Error creating client $i"
1814                exit 1
1815        fi
1816done
[892606b9]1817
[5f21d34]1818# Configuración de servicios de OpenGnsys
[65245d1]1819openGnsysConfigure
1820
[180a07dd]1821# Mostrar sumario de la instalación e instrucciones de post-instalación.
1822installationSummary
1823
[077dd7c5]1824#rm -rf $WORKDIR
[5f21d34]1825echoAndLog "OpenGnsys installation finished at $(date)"
[05d2e03]1826exit 0
[2308fc7]1827
Note: See TracBrowser for help on using the repository browser.