source: installer/opengnsys_installer.sh @ 8182ab14

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 8182ab14 was 140fbd5, checked in by ramon <ramongomez@…>, 8 years ago

#730: Reducir dependencias del instalador.

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

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