source: installer/opengnsys_installer.sh @ 8068b82

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-instalacion
Last change on this file since 8068b82 was 506c670, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#914: Installer and updater check HTTP and HTTPS connections to avoid proxy configuration errors.

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