source: installer/opengnsys_installer.sh @ 1cd64e6

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 1cd64e6 was 01a9904, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: corregir errata en actualizador a la hora de parchear la IP del servidor principal.

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

  • Property mode set to 100755
File size: 40.6 KB
RevLine 
[a01156a]1#!/bin/bash
2
3#####################################################################
4####### Script instalador OpenGnsys
5####### autor: Luis Guillén <lguillen@unizar.es>
6#####################################################################
7
8
[1e7eaab]9
[8fc9552]10####  AVISO: Editar configuración de acceso por defecto a la Base de Datos.
[4a3cd1f]11MYSQL_ROOT_PASSWORD="passwordroot"      # Clave root de MySQL
12OPENGNSYS_DATABASE="ogAdmBD"            # Nombre de la base datos
13OPENGNSYS_DB_USER="usuog"               # Usuario de acceso
14OPENGNSYS_DB_PASSWD="passusuog"         # Clave del usuario
15
[8fc9552]16####  AVISO: NO EDITAR.
17#### configuración de acceso smb para clientes OG.
18OPENGNSYS_CLIENT_USER="opengnsys"               # Nombre del usuario
19OPENGNSYS_CLIENT_PASSWD="og"            # Clave del usuario opengnsys
20
21
[4a3cd1f]22
[1e7eaab]23# Sólo ejecutable por usuario root
24if [ "$(whoami)" != 'root' ]
25then
26        echo "ERROR: this program must run under root privileges!!"
27        exit 1
28fi
29
30# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1).
[49c6891]31PROGRAMDIR=$(readlink -e $(dirname "$0"))
[07c3a59]32OPENGNSYS_SERVER="www.opengnsys.es"
[1e7eaab]33if [ -d "$PROGRAMDIR/../installer" ]; then
34    USESVN=0
35else
36    USESVN=1
37fi
[eb9424f]38SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/"
[1e7eaab]39
[a01156a]40WORKDIR=/tmp/opengnsys_installer
[1e7eaab]41mkdir -p $WORKDIR
42
43INSTALL_TARGET=/opt/opengnsys
[13a01a7]44LOG_FILE=/tmp/opengnsys_installation.log
[a01156a]45
[4a3cd1f]46# Base de datos
[7510561]47OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogAdmBD.sql
[3aaf91d]48
[a01156a]49
50#####################################################################
[d168a46]51####### Funciones de configuración
52#####################################################################
53
54# Generar variables de configuración del instalador
55# Variables globales:
56# - OSDISTRIB, OSCODENAME - datos de la distribución Linux
57# - DEPENDENCIES - array de dependencias que deben estar instaladas
58# - UPDATEPKGLIST, INSTALLPKGS, CHECKPKGS - comandos para gestión de paquetes
59# - APACHEINIT, APACHECFGDIR, APACHEUSER, APACHEGROUP - arranque y configuración de Apache
[3ce53a7]60# - ENABLEMOD, ENABLESITE - habilitar módulo Apache y sitio web
[d168a46]61# - DHCPINIT, DHCPCFGDIR - arranque y configuración de DHCP
62# - SAMBAINIT, SAMBACFGDIR - arranque y configuración de Samba
63# - TFTPCFGDIR - configuración de TFTP
64function autoConfigure()
65{
66# Detectar sistema operativo del servidor (debe soportar LSB).
67OSDISTRIB=$(lsb_release -is 2>/dev/null)
68OSCODENAME=$(lsb_release -cs 2>/dev/null)
69
70# Configuración según la distribución de Linux.
71case "$OSDISTRIB" in
72        Ubuntu) DEPENDENCIES=( subversion apache2 php5 libapache2-mod-php5 mysql-server php5-mysql dhcp3-server bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential g++-multilib libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent samba unzip netpipes debootstrap schroot squashfs-tools )
73                UPDATEPKGLIST="apt-get update"
74                INSTALLPKG="apt-get -y install --force-yes"
75                CHECKPKG="dpkg -s \$package 2>/dev/null | grep Status | grep -qw install"
76                APACHEINIT=/etc/init.d/apache2
77                APACHECFGDIR=/etc/apache2
78                APACHEUSER="www-data"
79                APACHEGROUP="www-data"
[3ce53a7]80                ENABLEMOD="a2enmod"
81                ENABLESITE="a2ensite"
[d168a46]82                case "$OSCODENAME" in
83                        natty)  DHCPINIT=/etc/init.d/isc-dhcp-server
84                                DHCPCFGDIR=/etc/dhcp
85                                ;;
86                        *)      DHCPINIT=/etc/init.d/dhcp3-server
87                                DHCPCFGDIR=/etc/dhcp3
88                                ;;
89                esac
90                SAMBAINIT=/etc/init.d/smbd
91                SAMBACFGDIR=/etc/samba
92                TFTPCFGDIR=/var/lib/tftpboot
93                ;;
94        Fedora) DEPENDENCIES=( subversion httpd mod_ssl php mysql-server mysql-devel mysql-devel.i686 php-mysql dhcp bittorrent tftp-server syslinux binutils gcc gcc-c++ glibc-devel.i686 make wget doxygen graphviz python-tornado ctorrent samba unzip NetPIPE debootstrap schroot squashfs-tools )          # TODO comprobar paquetes
95                UPDATEPKGLIST=""
96                INSTALLPKG="yum install -y"
97                CHECKPKG="rpm -q \$package"
98                APACHEINIT=/etc/init.d/httpd
99                APACHECFGDIR=/etc/httpd/conf.d
100                APACHEUSER="apache"
101                APACHEGROUP="apache"
102                DHCPINIT=/etc/init.d/dhcpd
103                DHCPCFGDIR=/etc/dhcp
104                SAMBAINIT=/etc/init.d/smb
105                SAMBACFGDIR=/etc/samba
106                TFTPCFGDIR=/var/lib/tftpboot
107                ;;
108        "")     echo "ERROR: Unknown Linux distribution, please install \"lsb_release\" command."
109                exit 1 ;;
110        *)      echo "ERROR: Distribution not supported by OpenGnSys."
111                exit 1 ;;
112esac
113}
114
115
116#####################################################################
[a01156a]117####### Algunas funciones útiles de propósito general:
118#####################################################################
[d168a46]119
[13a01a7]120function getDateTime()
[a01156a]121{
[d168a46]122        date "+%Y%m%d-%H%M%S"
[a01156a]123}
124
125# Escribe a fichero y muestra por pantalla
[13a01a7]126function echoAndLog()
[a01156a]127{
[d168a46]128        echo "$1"
129        local DATETIME=`getDateTime`
130        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
[a01156a]131}
132
[13a01a7]133function errorAndLog()
[a01156a]134{
[d168a46]135        echo "ERROR: $1"
136        local DATETIME=`getDateTime`
137        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
[a01156a]138}
139
140# comprueba si el elemento pasado en $2 esta en el array $1
[13a01a7]141function isInArray()
[a01156a]142{
143        if [ $# -ne 2 ]; then
[13a01a7]144                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]145                exit 1
146        fi
147
[13a01a7]148        echoAndLog "${FUNCNAME}(): checking if $2 is in $1"
[a01156a]149        local deps
[5c33840]150        eval "deps=( \"\${$1[@]}\" )"
[a01156a]151        elemento=$2
152
153        local is_in_array=1
154        # copia local del array del parametro 1
155        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
156        do
157                if [ "${deps[$i]}" = "${elemento}" ]; then
158                        echoAndLog "isInArray(): $elemento found in array"
159                        is_in_array=0
160                fi
161        done
162
163        if [ $is_in_array -ne 0 ]; then
[13a01a7]164                echoAndLog "${FUNCNAME}(): $elemento NOT found in array"
[a01156a]165        fi
166
167        return $is_in_array
168
169}
170
171#####################################################################
172####### Funciones de manejo de paquetes Debian
173#####################################################################
174
[13a01a7]175function checkPackage()
[a01156a]176{
177        package=$1
178        if [ -z $package ]; then
[73cfa0a]179                errorAndLog "${FUNCNAME}(): parameter required"
[a01156a]180                exit 1
181        fi
[73cfa0a]182        echoAndLog "${FUNCNAME}(): checking if package $package exists"
[d168a46]183        eval $CHECKPKG
[a01156a]184        if [ $? -eq 0 ]; then
[73cfa0a]185                echoAndLog "${FUNCNAME}(): package $package exists"
[a01156a]186                return 0
187        else
[73cfa0a]188                echoAndLog "${FUNCNAME}(): package $package doesn't exists"
[a01156a]189                return 1
190        fi
191}
192
193# recibe array con dependencias
194# por referencia deja un array con las dependencias no resueltas
195# devuelve 1 si hay alguna dependencia no resuelta
[13a01a7]196function checkDependencies()
[a01156a]197{
198        if [ $# -ne 2 ]; then
[73cfa0a]199                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]200                exit 1
201        fi
202
[73cfa0a]203        echoAndLog "${FUNCNAME}(): checking dependences"
[a01156a]204        uncompletedeps=0
205
206        # copia local del array del parametro 1
207        local deps
[5c33840]208        eval "deps=( \"\${$1[@]}\" )"
[a01156a]209
210        declare -a local_notinstalled
[5c33840]211
[a01156a]212        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
213        do
214                checkPackage ${deps[$i]}
215                if [ $? -ne 0 ]; then
216                        local_notinstalled[$uncompletedeps]=$package
217                        let uncompletedeps=uncompletedeps+1
218                fi
219        done
220
221        # relleno el array especificado en $2 por referencia
222        for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ ))
223        do
224                eval "${2}[$i]=${local_notinstalled[$i]}"
225        done
226
227        # retorna el numero de paquetes no resueltos
[73cfa0a]228        echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps"
[a01156a]229        return $uncompletedeps
230}
231
232# Recibe un array con las dependencias y lo instala
[13a01a7]233function installDependencies()
[a01156a]234{
235        if [ $# -ne 1 ]; then
[813f617]236                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]237                exit 1
238        fi
[813f617]239        echoAndLog "${FUNCNAME}(): installing uncompleted dependencies"
[a01156a]240
241        # copia local del array del parametro 1
242        local deps
[5c33840]243        eval "deps=( \"\${$1[@]}\" )"
[a01156a]244
245        local string_deps=""
246        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
247        do
248                string_deps="$string_deps ${deps[$i]}"
249        done
250
251        if [ -z "${string_deps}" ]; then
[813f617]252                errorAndLog "${FUNCNAME}(): array of dependeces is empty"
[a01156a]253                exit 1
254        fi
255
256        OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND
257        export DEBIAN_FRONTEND=noninteractive
258
[d168a46]259        echoAndLog "${FUNCNAME}(): now $string_deps will be installed"
260        eval $INSTALLPKG $string_deps
[a01156a]261        if [ $? -ne 0 ]; then
[813f617]262                errorAndLog "${FUNCNAME}(): error installing dependencies"
[a01156a]263                return 1
264        fi
265
266        DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND
[813f617]267        echoAndLog "${FUNCNAME}(): dependencies installed"
[a01156a]268}
269
[13a01a7]270# Hace un backup del fichero pasado por parámetro
271# deja un -last y uno para el día
272function backupFile()
273{
274        if [ $# -ne 1 ]; then
275                errorAndLog "${FUNCNAME}(): invalid number of parameters"
276                exit 1
277        fi
278
[d168a46]279        local file="$1"
280        local dateymd=`date +%Y%m%d`
[13a01a7]281
[d168a46]282        if [ ! -f "$file" ]; then
283                errorAndLog "${FUNCNAME}(): file $file doesn't exists"
[13a01a7]284                return 1
285        fi
286
[d168a46]287        echoAndLog "${FUNCNAME}(): making $file backup"
[13a01a7]288
289        # realiza una copia de la última configuración como last
[d168a46]290        cp -a "$file" "${file}-LAST"
[13a01a7]291
292        # si para el día no hay backup lo hace, sino no
[d168a46]293        if [ ! -f "${file}-${dateymd}" ]; then
294                cp -a "$file" "${file}-${dateymd}"
[13a01a7]295        fi
296
[d168a46]297        echoAndLog "${FUNCNAME}(): $file backup success"
[13a01a7]298}
299
[a01156a]300#####################################################################
301####### Funciones para el manejo de bases de datos
302#####################################################################
303
304# This function set password to root
[13a01a7]305function mysqlSetRootPassword()
[a01156a]306{
307        if [ $# -ne 1 ]; then
[813f617]308                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]309                exit 1
310        fi
311
[e0edc14]312        local root_mysql="$1"
[813f617]313        echoAndLog "${FUNCNAME}(): setting root password in MySQL server"
[e0edc14]314        mysqladmin -u root password "$root_mysql"
[a01156a]315        if [ $? -ne 0 ]; then
[813f617]316                errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server"
[a01156a]317                return 1
318        fi
[813f617]319        echoAndLog "${FUNCNAME}(): root password saved!"
[a01156a]320        return 0
321}
322
[892606b9]323# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
[e0edc14]324function mysqlGetRootPassword()
325{
[892606b9]326        local pass_mysql
327        local pass_mysql2
[7c54b49]328        # Comprobar si MySQL está instalado con la clave de root por defecto.
329        if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then
330                echoAndLog "${FUNCNAME}(): Using default mysql root password."
331        else
332                stty -echo
[e0edc14]333                echo "There is a MySQL service already installed."
334                read -p "Enter MySQL root password: " pass_mysql
[7c54b49]335                echo ""
[e0edc14]336                read -p "Confrim password:" pass_mysql2
[7c54b49]337                echo ""
338                stty echo
339                if [ "$pass_mysql" == "$pass_mysql2" ] ;then
[e0edc14]340                        MYSQL_ROOT_PASSWORD="$pass_mysql"
[7c54b49]341                        return 0
342                else
[e0edc14]343                        echo "The keys don't match. Do not configure the server's key,"
344                        echo "transactions in the database will give error."
[7c54b49]345                        return 1
346                fi
[892606b9]347        fi
348}
349
[a01156a]350# comprueba si puede conectar con mysql con el usuario root
351function mysqlTestConnection()
352{
353        if [ $# -ne 1 ]; then
[e0edc14]354                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]355                exit 1
356        fi
357
358        local root_password="${1}"
[e0edc14]359        echoAndLog "${FUNCNAME}(): checking connection to mysql..."
[a01156a]360        echo "" | mysql -uroot -p"${root_password}"
361        if [ $? -ne 0 ]; then
[e0edc14]362                errorAndLog "${FUNCNAME}(): connection to mysql failed, check root password and if daemon is running!"
[a01156a]363                return 1
364        else
[e0edc14]365                echoAndLog "${FUNCNAME}(): connection success"
[a01156a]366                return 0
367        fi
368}
369
370# comprueba si la base de datos existe
371function mysqlDbExists()
372{
373        if [ $# -ne 2 ]; then
[e0edc14]374                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]375                exit 1
376        fi
377
378        local root_password="${1}"
379        local database=$2
[e0edc14]380        echoAndLog "${FUNCNAME}(): checking if $database exists..."
[a01156a]381        echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$"
382        if [ $? -ne 0 ]; then
[e0edc14]383                echoAndLog "${FUNCNAME}():database $database doesn't exists"
[a01156a]384                return 1
385        else
[e0edc14]386                echoAndLog "${FUNCNAME}():database $database exists"
[a01156a]387                return 0
388        fi
389}
390
391function mysqlCheckDbIsEmpty()
392{
393        if [ $# -ne 2 ]; then
[e0edc14]394                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]395                exit 1
396        fi
397
398        local root_password="${1}"
399        local database=$2
[e0edc14]400        echoAndLog "${FUNCNAME}(): checking if $database is empty..."
[a01156a]401        num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l`
402        if [ $? -ne 0 ]; then
[e0edc14]403                errorAndLog "${FUNCNAME}(): error executing query, check database and root password"
[a01156a]404                exit 1
405        fi
406
407        if [ $num_tablas -eq 0 ]; then
[e0edc14]408                echoAndLog "${FUNCNAME}():database $database is empty"
[a01156a]409                return 0
410        else
[e0edc14]411                echoAndLog "${FUNCNAME}():database $database has tables"
[a01156a]412                return 1
413        fi
414
415}
416
417
418function mysqlImportSqlFileToDb()
419{
420        if [ $# -ne 3 ]; then
[c5ce04c]421                errorAndLog "${FNCNAME}(): invalid number of parameters"
[a01156a]422                exit 1
423        fi
424
[c4321ae]425        local root_password="$1"
426        local database="$2"
427        local sqlfile="$3"
428        local tmpfile=$(mktemp)
[d168a46]429        local i=0
430        local dev=""
[c4321ae]431        local status
[a01156a]432
433        if [ ! -f $sqlfile ]; then
[c5ce04c]434                errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!"
[a01156a]435                return 1
436        fi
437
[d168a46]438        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
[c4321ae]439        chmod 600 $tmpfile
[d168a46]440        for dev in ${DEVICE[*]}; do
[01a9904]441                if [ "${DEVICE[i]} == $DEFAULTDEV" ]; then
[d168a46]442                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
443                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
444                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
445                                $sqlfile > $tmpfile
446                fi
447                let i++
448        done
[c4321ae]449        mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $tmpfile
450        status=$?
451        rm -f $tmpfile
452        if [ $status -ne 0 ]; then
[c5ce04c]453                errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database"
[a01156a]454                return 1
455        fi
[c5ce04c]456        echoAndLog "${FUNCNAME}(): file imported to database $database"
[a01156a]457        return 0
458}
459
460# Crea la base de datos
461function mysqlCreateDb()
462{
463        if [ $# -ne 2 ]; then
[a555f49]464                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]465                exit 1
466        fi
467
468        local root_password="${1}"
469        local database=$2
470
[a555f49]471        echoAndLog "${FUNCNAME}(): creating database..."
[a01156a]472        mysqladmin -u root --password="${root_password}" create $database
473        if [ $? -ne 0 ]; then
[a555f49]474                errorAndLog "${FUNCNAME}(): error while creating database $database"
[a01156a]475                return 1
476        fi
[a555f49]477        echoAndLog "${FUNCNAME}(): database $database created"
[a01156a]478        return 0
479}
480
481
482function mysqlCheckUserExists()
483{
484        if [ $# -ne 2 ]; then
[e0edc14]485                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]486                exit 1
487        fi
488
489        local root_password="${1}"
490        local userdb=$2
491
[e0edc14]492        echoAndLog "${FUNCNAME}(): checking if $userdb exists..."
[a01156a]493        echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user
494        if [ $? -ne 0 ]; then
[e0edc14]495                echoAndLog "${FUNCNAME}(): user doesn't exists"
[a01156a]496                return 1
497        else
[e0edc14]498                echoAndLog "${FUNCNAME}(): user already exists"
[a01156a]499                return 0
500        fi
501
502}
503
504# Crea un usuario administrativo para la base de datos
505function mysqlCreateAdminUserToDb()
506{
507        if [ $# -ne 4 ]; then
[e0edc14]508                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]509                exit 1
510        fi
511
512        local root_password=$1
513        local database=$2
514        local userdb=$3
515        local passdb=$4
516
[e0edc14]517        echoAndLog "${FUNCNAME}(): creating admin user ${userdb} to database ${database}"
[a01156a]518
519        cat > $WORKDIR/create_${database}.sql <<EOF
520GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
521GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
522FLUSH PRIVILEGES ;
523EOF
524        mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql
525        if [ $? -ne 0 ]; then
[e0edc14]526                errorAndLog "${FUNCNAME}(): error while creating user in mysql"
[a01156a]527                rm -f $WORKDIR/create_${database}.sql
528                return 1
529        else
[e0edc14]530                echoAndLog "${FUNCNAME}(): user created ok"
[a01156a]531                rm -f $WORKDIR/create_${database}.sql
532                return 0
533        fi
534}
535
536
537#####################################################################
538####### Funciones para el manejo de Subversion
539#####################################################################
540
[13a01a7]541function svnExportCode()
542{
543        if [ $# -ne 1 ]; then
544                errorAndLog "${FUNCNAME}(): invalid number of parameters"
545                exit 1
546        fi
547
[6090a2d]548        local url="$1"
[13a01a7]549
550        echoAndLog "${FUNCNAME}(): downloading subversion code..."
551
[6090a2d]552        svn export --force "$url" opengnsys
[13a01a7]553        if [ $? -ne 0 ]; then
[6090a2d]554                errorAndLog "${FUNCNAME}(): error getting OpenGnSys code from $url"
[13a01a7]555                return 1
556        fi
557        echoAndLog "${FUNCNAME}(): subversion code downloaded"
558        return 0
559}
560
561
[892606b9]562############################################################
[7586ca3]563###  Detectar red
564############################################################
565
[07c3a59]566# Comprobar si existe conexión.
567function checkNetworkConnection()
568{
569        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"}
570        wget --spider -q $OPENGNSYS_SERVER
571}
572
573# Obtener los parámetros de red de la interfaz por defecto.
[7586ca3]574function getNetworkSettings()
575{
[d168a46]576        # Arrays globales definidas:
577        # - DEVICE:     nombres de dispositivos de red activos.
578        # - SERVERIP:   IPs locales del servidor.
579        # - NETIP:      IPs de redes.
580        # - NETMASK:    máscaras de red.
581        # - NETBROAD:   IPs de difusión de redes.
582        # - ROUTERIP:   IPs de routers.
583        # Otras variables globales:
584        # - DEFAULTDEV: dispositivo de red por defecto.
585        # - DNSIP:      IP del servidor DNS principal.
586
587        local i=0
588        local dev=""
589
590        echoAndLog "${FUNCNAME}(): Detecting network parameters."
591        DEVICE=( $(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}') )
592        if [ -z "$DEVICE" ]; then
593                errorAndLog "${FUNCNAME}(): Network devices not detected."
[62e3bcf]594                exit 1
595        fi
[d168a46]596        for dev in ${DEVICE[*]}; do
597                SERVERIP[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
598                if [ -n "${SERVERIP[i]}" ]; then
599                        NETMASK[i]=$(LANG=C ifconfig $dev | awk '/Mask/ {sub(/.*:/,"",$4); print $4}')
600                        NETBROAD[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {print ($6)}')
601                        NETIP[i]=$(netstat -nr | awk -v d="$dev" '$1!~/0\.0\.0\.0/&&$8==d {if (n=="") n=$1} END {print n}')
602                        ROUTERIP[i]=$(netstat -nr | awk -v d="$dev" '$1~/0\.0\.0\.0/&&$8==d {print $2}')
603                        DEFAULTDEV=${DEFAULTDEV:-"$dev"}
604                        let i++
605                fi
606        done
[a555f49]607        DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1)
[d168a46]608        if [ -z "${NETIP}[*]" -o -z "${NETMASK[*]}" ]; then
[62e3bcf]609                errorAndLog "${FUNCNAME}(): Network not detected."
[7586ca3]610                exit 1
611        fi
[cc7eab7]612
613        # Variables de ejecución de Apache
614        # - APACHE_RUN_USER
615        # - APACHE_RUN_GROUP
[d168a46]616        if [ -f $APACHECFGDIR/envvars ]; then
617                source $APACHECFGDIR/envvars
[cc7eab7]618        fi
[d168a46]619        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
620        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
[7586ca3]621}
622
623
624############################################################
[892606b9]625### Esqueleto para el Servicio pxe y contenedor tftpboot ###
626############################################################
627
[e0edc14]628function tftpConfigure()
629{
[cfad47b]630        echoAndLog "${FUNCNAME}(): Configuring TFTP service."
[892606b9]631        # reiniciamos demonio internet ????? porque ????
632        /etc/init.d/openbsd-inetd start
633
634        # preparacion contenedor tftpboot
[d168a46]635        cp -ar /usr/lib/syslinux/ $TFTPCFGDIR/syslinux
636        cp -a /usr/lib/syslinux/pxelinux.0 $TFTPCFGDIR
[892606b9]637        # prepamos el directorio de la configuracion de pxe
[d168a46]638        mkdir -p $TFTPCFGDIR/pxelinux.cfg
639        cat > $TFTPCFGDIR/pxelinux.cfg/default <<EOF
[8fc9552]640DEFAULT syslinux/vesamenu.c32
641MENU TITLE Aplicacion GNSYS
642 
643LABEL 1
644MENU LABEL 1
645KERNEL syslinux/chain.c32
646APPEND hd0
647 
648PROMPT 0
649TIMEOUT 10
[892606b9]650EOF
651        # comprobamos el servicio tftp
652        sleep 1
653        testPxe
654}
655
[e0edc14]656function testPxe ()
657{
658        echoAndLog "${FUNCNAME}(): Checking TFTP service... please wait."
[892606b9]659        cd /tmp
[e0edc14]660        tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echoAndLog "TFTP service is OK." || errorAndLog "TFTP service is down."
[892606b9]661        cd /
662}
663
[8fc9552]664
[892606b9]665########################################################################
[813f617]666## Configuracion servicio Samba
[8fc9552]667########################################################################
668function smbConfigure()
669{
[e0edc14]670        echoAndLog "${FUNCNAME}(): Configuring Samba service."
[8fc9552]671
[d168a46]672        backupFile $SAMBACFGDIR/smb.conf
[8fc9552]673       
[813f617]674        # Copiar plantailla de recursos para OpenGnSys
[c1e00e4]675        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
[d168a46]676                $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf
[813f617]677        # Configurar y recargar Samba"
[d168a46]678        perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnSys Samba Server/; s/^\; *include \=.*$/   include \= \/etc\/samba\/smb-og.conf/" $SAMBACFGDIR/smb.conf
679        $SAMBAINIT restart
[8fc9552]680        if [ $? -ne 0 ]; then
[813f617]681                errorAndLog "${FUNCNAME}(): error while configure Samba"
[8fc9552]682                return 1
683        fi
[eb9424f]684        # Crear clave para usuario de acceso a los recursos.
[813f617]685        echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | smbpasswd -a -s $OPENGNSYS_CLIENT_USER
[8fc9552]686
[813f617]687        echoAndLog "${FUNCNAME}(): Added Samba configuration."
[8fc9552]688        return 0
689}
690
691
[b6906f7]692########################################################################
693## Configuracion servicio DHCP
694########################################################################
695
[7586ca3]696function dhcpConfigure()
697{
[836a7597]698        echoAndLog "${FUNCNAME}(): Sample DHCP configuration."
[a555f49]699
[d168a46]700        local errcode=0
701        local i=0
702        local dev=""
703
704        backupFile $DHCPCFGDIR/dhcpd.conf
705        for dev in ${DEVICE[*]}; do
[01a9904]706                if [ -n "${SERVERIP[i]}" ]; then
[d168a46]707                        backupFile $DHCPCFGDIR/dhcpd-$dev.conf
708                        sed -e "s/SERVERIP/${SERVERIP[$i]}/g" \
709                            -e "s/NETIP/${NETIP[$i]}/g" \
710                            -e "s/NETMASK/${NETMASK[$i]}/g" \
711                            -e "s/NETBROAD/${NETBROAD[$i]}/g" \
712                            -e "s/ROUTERIP/${ROUTERIP[$i]}/g" \
713                            -e "s/DNSIP/$DNSIP/g" \
714                            $WORKDIR/opengnsys/server/etc/dhcpd.conf.tmpl > $DHCPCFGDIR/dhcpd-$dev.conf || errcode=1
715                fi
716                let i++
717        done
718        if [ $errcode -ne 0 ]; then
[b25fc47]719                errorAndLog "${FUNCNAME}(): error while configuring DHCP server"
[a555f49]720                return 1
721        fi
[d168a46]722        ln -f $DHCPCFGDIR/dhcpd-$DEFAULTDEV.conf $DHCPCFGDIR/dhcpd.conf
723        $DHCPINIT restart
724        echoAndLog "${FUNCNAME}(): Sample DHCP configured in \"$DHCPCFGDIR\"."
[a555f49]725        return 0
[892606b9]726}
727
728
[a01156a]729#####################################################################
730####### Funciones específicas de la instalación de Opengnsys
731#####################################################################
732
[49c6891]733# Copiar ficheros del OpenGnSys Web Console.
[7586ca3]734function installWebFiles()
735{
[dce072b]736        echoAndLog "${FUNCNAME}(): Installing web files..."
[7586ca3]737        cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www   #*/ comentario para doxigen
738        if [ $? != 0 ]; then
[dce072b]739                errorAndLog "${FUNCNAME}(): Error copying web files."
[7586ca3]740                exit 1
741        fi
742        find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null
[813f617]743        # Descomprimir XAJAX.
[edac247]744        unzip $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
[7586ca3]745        # Cambiar permisos para ficheros especiales.
[3aaf91d]746        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/iconos
[dce072b]747        echoAndLog "${FUNCNAME}(): Web files installed successfully."
[7586ca3]748}
749
750# Configuración específica de Apache.
[892606b9]751function openGnsysInstallWebConsoleApacheConf()
[a01156a]752{
753        if [ $# -ne 2 ]; then
[dce072b]754                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]755                exit 1
756        fi
757
758        local path_opengnsys_base=$1
759        local path_apache2_confd=$2
[892606b9]760        local path_web_console=${path_opengnsys_base}/www
[a01156a]761
[892606b9]762        if [ ! -d $path_apache2_confd ]; then
[dce072b]763                errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation"
[892606b9]764                return 1
765        fi
766
[7586ca3]767        mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
[892606b9]768
[dce072b]769        echoAndLog "${FUNCNAME}(): creating apache2 config file.."
[a01156a]770
[3ce53a7]771        # Activar HTTPS.
772        $ENABLESITE default-ssl
773        $ENABLEMOD ssl
774        make-ssl-cert generate-default-snakeoil --force-overwrite
[d725a41]775
[3ce53a7]776        # Genera configuración de consola web.
[892606b9]777        cat > $path_opengnsys_base/etc/apache.conf <<EOF
[49c6891]778# OpenGnSys Web Console configuration for Apache
[a01156a]779
[892606b9]780Alias /opengnsys ${path_web_console}
[a01156a]781
[892606b9]782<Directory ${path_web_console}>
[a01156a]783        Options -Indexes FollowSymLinks
784        DirectoryIndex acceso.php
785</Directory>
786EOF
787
[3ce53a7]788        ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys
789        $ENABLESITE opengnsys
[a01156a]790        if [ $? -ne 0 ]; then
[dce072b]791                errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation"
[a01156a]792                return 1
793        else
[dce072b]794                echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon"
[d168a46]795                $APACHEINIT restart
[a01156a]796                return 0
797        fi
798}
799
[8fc9552]800
[5d6bf97]801# Crear documentación Doxygen para la consola web.
802function makeDoxygenFiles()
803{
804        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
805        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
806                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
807        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
808                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
[ead38fb]809                return 1
[5d6bf97]810        fi
811        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
812        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
813        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
814}
815
816
[a01156a]817# Crea la estructura base de la instalación de opengnsys
[eb9424f]818function createDirs()
[a01156a]819{
820        if [ $# -ne 1 ]; then
[dce072b]821                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[a01156a]822                exit 1
823        fi
824
[eb9424f]825        local path_opengnsys_base="$1"
[a01156a]826
[eb9424f]827        # Crear estructura de directorios.
[dce072b]828        echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base"
[a01156a]829        mkdir -p $path_opengnsys_base
830        mkdir -p $path_opengnsys_base/bin
[5c33840]831        mkdir -p $path_opengnsys_base/client
[49c6891]832        mkdir -p $path_opengnsys_base/doc
[5c33840]833        mkdir -p $path_opengnsys_base/etc
[a01156a]834        mkdir -p $path_opengnsys_base/lib
[1cc5697]835        mkdir -p $path_opengnsys_base/log/clients
[eb9424f]836        ln -fs $path_opengnsys_base/log /var/log/opengnsys
[7586ca3]837        mkdir -p $path_opengnsys_base/sbin
[a01156a]838        mkdir -p $path_opengnsys_base/www
[5c33840]839        mkdir -p $path_opengnsys_base/images
[b6906f7]840        ln -fs /var/lib/tftpboot $path_opengnsys_base
[eb9424f]841        mkdir -p $path_opengnsys_base/tftpboot/pxelinux.cfg
[cfad47b]842        mkdir -p $path_opengnsys_base/tftpboot/menu.lst
[a01156a]843        if [ $? -ne 0 ]; then
[dce072b]844                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
[a01156a]845                return 1
846        fi
847
[eb9424f]848        # Crear usuario ficticio.
849        if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then
850                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created"
851        else
852                echoAndLog "${FUNCNAME}(): creating OpenGnSys user"
853                useradd $OPENGNSYS_CLIENT_USER 2>/dev/null
854                if [ $? -ne 0 ]; then
855                        errorAndLog "${FUNCNAME}(): error creating OpenGnSys user"
856                        return 1
857                fi
858        fi
859
860        # Establecer los permisos básicos.
861        echoAndLog "${FUNCNAME}(): setting directory permissions"
[5eb61a6]862        chmod -R 775 $path_opengnsys_base/{log/clients,images}
863        chown -R :$OPENGNSYS_CLIENT_USER $path_opengnsys_base/{log/clients,images}
[eb9424f]864        if [ $? -ne 0 ]; then
865                errorAndLog "${FUNCNAME}(): error while setting permissions"
866                return 1
867        fi
868
[dce072b]869        echoAndLog "${FUNCNAME}(): directory paths created"
[a01156a]870        return 0
871}
872
[463a1d49]873# Copia ficheros de configuración y ejecutables genéricos del servidor.
[e0edc14]874function openGnsysCopyServerFiles ()
875{
[463a1d49]876        if [ $# -ne 1 ]; then
[879689f]877                errorAndLog "${FUNCNAME}(): invalid number of parameters"
[463a1d49]878                exit 1
879        fi
880
[7caf5a7c]881        local path_opengnsys_base="$1"
[463a1d49]882
[cfad47b]883        local SOURCES=( server/tftpboot \
[7caf5a7c]884                        server/bin \
885                        repoman/bin \
886                        installer/opengnsys_uninstall.sh \
887                        installer/opengnsys_update.sh \
888                        doc )
[cfad47b]889        local TARGETS=( tftpboot \
[7caf5a7c]890                        bin \
891                        bin \
892                        lib \
893                        lib \
894                        doc )
[463a1d49]895
896        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
[879689f]897                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
[463a1d49]898                exit 1
899        fi
900
[879689f]901        echoAndLog "${FUNCNAME}(): copying files to server directories"
[f2bb433]902
[8457092]903        pushd $WORKDIR/opengnsys
[463a1d49]904        local i
905        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
906                if [ -f "${SOURCES[$i]}" ]; then
[879689f]907                        echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
[b5aae72]908                        cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
[8457092]909                elif [ -d "${SOURCES[$i]}" ]; then
[879689f]910                        echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
[8457092]911                        cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}"
912        else
913                        echoAndLog "Warning: Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
[463a1d49]914                fi
915        done
[7586ca3]916        popd
[892606b9]917}
918
[7586ca3]919####################################################################
[5eb61a6]920### Funciones de compilación de código fuente de servicios
[7586ca3]921####################################################################
922
[5eb61a6]923# Compilar los servicios de OpenGnSys
[7586ca3]924function servicesCompilation ()
925{
[13a01a7]926        local hayErrores=0
[0795938]927
[49c6891]928        # Compilar OpenGnSys Server
929        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server"
[7b61735]930        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
[d168a46]931        make && mv ogAdmServer $INSTALL_TARGET/sbin
[13a01a7]932        if [ $? -ne 0 ]; then
[49c6891]933                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
[13a01a7]934                hayErrores=1
935        fi
[7586ca3]936        popd
[49c6891]937        # Compilar OpenGnSys Repository Manager
938        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager"
[7b61735]939        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
[d168a46]940        make && mv ogAdmRepo $INSTALL_TARGET/sbin
[13a01a7]941        if [ $? -ne 0 ]; then
[49c6891]942                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
[13a01a7]943                hayErrores=1
944        fi
[8125e7c]945        popd
[4984660]946        # Compilar OpenGnSys Agent
947        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent"
[7b61735]948        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
[d168a46]949        make && mv ogAdmAgent $INSTALL_TARGET/sbin
[4984660]950        if [ $? -ne 0 ]; then
951                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent"
952                hayErrores=1
953        fi
954        popd   
[49c6891]955        # Compilar OpenGnSys Client
956        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client"
[7b61735]957        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
[2338c95f]958        make && mv ogAdmClient ../../../../client/shared/bin
[13a01a7]959        if [ $? -ne 0 ]; then
[49c6891]960                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client"
[13a01a7]961                hayErrores=1
962        fi
[318efac]963        popd
[13a01a7]964
965        return $hayErrores
[b6906f7]966}
967
[7b61735]968####################################################################
969### Funciones de copia de la Interface de administración
970####################################################################
971
972# Copiar carpeta de Interface
[c1e00e4]973function copyInterfaceAdm ()
[7b61735]974{
975        local hayErrores=0
976       
[fbd9bcc]977        # Crear carpeta y copiar Interface
[7b61735]978        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
[fbd9bcc]979        cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm
[7b61735]980        if [ $? -ne 0 ]; then
981                echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder"
982                hayErrores=1
983        fi
[b6f1726]984        chown $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[f6c1d2b]985        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
[7b61735]986
987        return $hayErrores
988}
[b6906f7]989
[892606b9]990####################################################################
991### Funciones instalacion cliente opengnsys
992####################################################################
993
[7cc6687]994function openGnsysCopyClientFiles()
[7586ca3]995{
[d168a46]996        local errstatus=0
[a555f49]997
[49c6891]998        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
[d47d38d]999        cp -ar $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
1000        if [ $? -ne 0 ]; then
[9ef8920]1001                errorAndLog "${FUNCNAME}(): error while copying client estructure"
[d168a46]1002                errstatus=1
[9ef8920]1003        fi
[d47d38d]1004        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
[9ef8920]1005       
[49c6891]1006        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
[d47d38d]1007        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
[51b179a]1008        cp -ar $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
[a555f49]1009        if [ $? -ne 0 ]; then
1010                errorAndLog "${FUNCNAME}(): error while copying engine files"
[d168a46]1011                errstatus=1
[a555f49]1012        fi
[9ef8920]1013       
[d168a46]1014        if [ $errstatus -eq 0 ]; then
[9ef8920]1015                echoAndLog "${FUNCNAME}(): client copy files success."
1016        else
1017                errorAndLog "${FUNCNAME}(): client copy files with errors"
1018        fi
1019
[d168a46]1020        return $errstatus
[463a1d49]1021}
1022
1023
[d168a46]1024# Crear cliente OpenGnSys 1.0.2
[5ad5dcc]1025function clientCreate()
[813f617]1026{
[5ad5dcc]1027        local DOWNLOADURL="http://www.opengnsys.es/downloads"
[35b6d4a]1028        local FILENAME=ogclient-1.0.2-natty-32bit-beta01-rev2111.iso
[0b85cc93]1029        local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
1030        local TMPDIR=/tmp/${FILENAME%.iso}
[d168a46]1031 
[813f617]1032        echoAndLog "${FUNCNAME}(): Loading Client"
[5ad5dcc]1033        # Descargar, montar imagen, copiar cliente ogclient y desmontar.
[0b85cc93]1034        wget $DOWNLOADURL/$FILENAME -O $TARGETFILE
1035        if [ ! -s $TARGETFILE ]; then
[6ef9f23]1036                errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client"
[813f617]1037                return 1
1038        fi
[5ad5dcc]1039        echoAndLog "${FUNCNAME}(): Copying Client files"
[d168a46]1040        mkdir -p $TMPDIR
[0b85cc93]1041        mount -o loop,ro $TARGETFILE $TMPDIR
[5eb61a6]1042        cp -vr $TMPDIR/ogclient $INSTALL_TARGET/tftpboot
[5ad5dcc]1043        umount $TMPDIR
1044        rmdir $TMPDIR
[0b85cc93]1045
[813f617]1046        # Establecer los permisos.
[19fdf38]1047        find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \;
1048        find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \;
[813f617]1049        chown -R :$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/tftpboot/ogclient
[5eb61a6]1050        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg}
[813f617]1051        echoAndLog "${FUNCNAME}(): Client generation success"
1052}
1053
1054
[49c6891]1055# Configuración básica de servicios de OpenGnSys
[cc7eab7]1056function openGnsysConfigure()
1057{
[d168a46]1058        local i=0
1059        local dev=""
1060
[9ee62ad]1061        echoAndLog "${FUNCNAME}(): Copying init files."
[7b61735]1062        cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
1063        cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys
[8fc9552]1064        cp -p $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepoAux /opt/opengnsys/sbin/
[cc7eab7]1065        update-rc.d opengnsys defaults
[9ee62ad]1066        echoAndLog "${FUNCNAME}(): Creating cron files."
1067        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
[8fc9552]1068        echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
[d168a46]1069
[700299b]1070        echoAndLog "${FUNCNAME}(): Creating logrotate configuration file."
1071        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
1072                $WORKDIR/opengnsys/server/etc/logrotate.tmpl > /etc/logrotate.d/opengnsys
1073
[d168a46]1074        echoAndLog "${FUNCNAME}(): Creating OpenGnSys config files."
1075        for dev in ${DEVICE[*]}; do
1076                if [ -n "${SERVERIP[i]}" ]; then
1077                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1078                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1079                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1080                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1081                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer/ogAdmServer.cfg > $INSTALL_TARGET/etc/ogAdmServer-$dev.cfg
1082                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1083                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo/ogAdmRepo.cfg > $INSTALL_TARGET/etc/ogAdmRepo-$dev.cfg
1084                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1085                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1086                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1087                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1088                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent/ogAdmAgent.cfg > $INSTALL_TARGET/etc/ogAdmAgent-$dev.cfg
1089                        OPENGNSYS_CONSOLEURL="http://${SERVERIP[i]}/opengnsys"
1090                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1091                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1092                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1093                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1094                            -e "s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" \
1095                                $INSTALL_TARGET/www/controlacceso.php > $INSTALL_TARGET/www/controlacceso-$dev.php
1096                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1097                            -e "s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" \
1098                                $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient-$dev.cfg
1099                fi
1100                let i++
1101        done
1102        ln -f $INSTALL_TARGET/etc/ogAdmServer-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmServer.cfg
1103        ln -f $INSTALL_TARGET/etc/ogAdmRepo-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmRepo.cfg
1104        ln -f $INSTALL_TARGET/etc/ogAdmAgent-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmAgent.cfg
1105        ln -f $INSTALL_TARGET/client/etc/ogAdmClient-$DEFAULTDEV.cfg $INSTALL_TARGET/client/etc/ogAdmClient.cfg
1106        ln -f $INSTALL_TARGET/www/controlacceso-$DEFAULTDEV.php $INSTALL_TARGET/www/controlacceso.php
1107        chown root:root $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg
1108        chmod 600 $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg
1109        chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso*.php
1110        chmod 600 $INSTALL_TARGET/www/controlacceso*.php
[9ee62ad]1111        echoAndLog "${FUNCNAME}(): Starting OpenGnSys services."
[cc7eab7]1112        /etc/init.d/opengnsys start
1113}
1114
[b6906f7]1115
[a01156a]1116#####################################################################
[180a07dd]1117#######  Función de resumen informativo de la instalación
1118#####################################################################
1119
[813f617]1120function installationSummary()
1121{
[eb9424f]1122        # Crear fichero de versión y revisión, si no existe.
1123        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
[0b85cc93]1124        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}')
[eb9424f]1125        [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE
1126        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
1127
1128        # Mostrar información.
[180a07dd]1129        echo
[49c6891]1130        echoAndLog "OpenGnSys Installation Summary"
[180a07dd]1131        echo       "=============================="
[eb9424f]1132        echoAndLog "Project version:                  $(cat $VERSIONFILE 2>/dev/null)"
[49c6891]1133        echoAndLog "Installation directory:           $INSTALL_TARGET"
1134        echoAndLog "Repository directory:             $INSTALL_TARGET/images"
[d168a46]1135        echoAndLog "DHCP configuration directory:     $DHCPCFGDIR"
[d47d38d]1136        echoAndLog "TFTP configuration directory:     /var/lib/tftpboot"
1137        echoAndLog "Samba configuration directory:    /etc/samba"
[49c6891]1138        echoAndLog "Web Console URL:                  $OPENGNSYS_CONSOLEURL"
[180a07dd]1139        echoAndLog "Web Console admin user:           $OPENGNSYS_DB_USER"
1140        echoAndLog "Web Console admin password:       $OPENGNSYS_DB_PASSWD"
1141        echo
1142        echoAndLog "Post-Installation Instructions:"
1143        echo       "==============================="
1144        echoAndLog "Review or edit all configuration files."
[c5ce04c]1145        echoAndLog "Insert DHCP configuration data and restart service."
[180a07dd]1146        echoAndLog "Log-in as Web Console admin user."
[85fa51e]1147        echoAndLog " - Review default Organization data and assign default user."
[180a07dd]1148        echoAndLog "Log-in as Web Console organization user."
[85fa51e]1149        echoAndLog " - Insert OpenGnSys data (rooms, computers, menus, etc)."
[180a07dd]1150echo
1151}
1152
1153
1154
1155#####################################################################
[49c6891]1156####### Proceso de instalación de OpenGnSys
[a01156a]1157#####################################################################
1158
[49c6891]1159echoAndLog "OpenGnSys installation begins at $(date)"
[6090a2d]1160pushd $WORKDIR
[cc7eab7]1161
[d168a46]1162# Detectar datos de auto-configuración del instalador.
1163autoConfigure
1164
1165# Detectar parámetros de red y comprobar si hay conexión.
1166getNetworkSettings
1167if [ $? -ne 0 ]; then
1168        errorAndLog "Error reading default network settings."
1169        exit 1
1170fi
[07c3a59]1171checkNetworkConnection
1172if [ $? -ne 0 ]; then
1173        errorAndLog "Error connecting to server. Causes:"
1174        errorAndLog " - Network is unreachable, review devices parameters."
1175        errorAndLog " - You are inside a private network, configure the proxy service."
1176        errorAndLog " - Server is temporally down, try agian later."
1177        exit 1
1178fi
[7586ca3]1179
[e0edc14]1180# Detener servicios de OpenGnSys, si están activos previamente.
1181[ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop
1182
[318efac]1183# Actualizar repositorios
[d168a46]1184eval $UPDATEPKGLIST
[318efac]1185
[b6906f7]1186# Instalación de dependencias (paquetes de sistema operativo).
[a01156a]1187declare -a notinstalled
1188checkDependencies DEPENDENCIES notinstalled
1189if [ $? -ne 0 ]; then
1190        installDependencies notinstalled
1191        if [ $? -ne 0 ]; then
1192                echoAndLog "Error while installing some dependeces, please verify your server installation before continue"
1193                exit 1
1194        fi
1195fi
1196
[49c6891]1197# Arbol de directorios de OpenGnSys.
[eb9424f]1198createDirs ${INSTALL_TARGET}
[a01156a]1199if [ $? -ne 0 ]; then
1200        errorAndLog "Error while creating directory paths!"
1201        exit 1
1202fi
[b6906f7]1203
[1e7eaab]1204# Si es necesario, descarga el repositorio de código en directorio temporal
[49c6891]1205if [ $USESVN -eq 1 ]; then
[1e7eaab]1206        svnExportCode $SVN_URL
1207        if [ $? -ne 0 ]; then
1208                errorAndLog "Error while getting code from svn"
1209                exit 1
1210        fi
1211else
1212        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
[a01156a]1213fi
1214
[49c6891]1215# Compilar código fuente de los servicios de OpenGnSys.
[b6906f7]1216servicesCompilation
[13a01a7]1217if [ $? -ne 0 ]; then
1218        errorAndLog "Error while compiling OpenGnsys services"
1219        exit 1
1220fi
[b6906f7]1221
[7b61735]1222# Copiar carpeta Interface entre administración y motor de clonación.
[c1e00e4]1223copyInterfaceAdm
[7b61735]1224if [ $? -ne 0 ]; then
[c1e00e4]1225        errorAndLog "Error while copying Administration Interface"
[7b61735]1226        exit 1
1227fi
1228
[b6906f7]1229# Configurando tftp
[318efac]1230tftpConfigure
[b6906f7]1231
[c1e00e4]1232# Configuración Samba
[8fc9552]1233smbConfigure
1234if [ $? -ne 0 ]; then
[c1e00e4]1235        errorAndLog "Error while configuring Samba server!"
[8fc9552]1236        exit 1
1237fi
1238
[b6906f7]1239# Configuración ejemplo DHCP
1240dhcpConfigure
[a555f49]1241if [ $? -ne 0 ]; then
1242        errorAndLog "Error while copying your dhcp server files!"
1243        exit 1
1244fi
[b6906f7]1245
[49c6891]1246# Copiar ficheros de servicios OpenGnSys Server.
[463a1d49]1247openGnsysCopyServerFiles ${INSTALL_TARGET}
1248if [ $? -ne 0 ]; then
1249        errorAndLog "Error while copying the server files!"
1250        exit 1
1251fi
1252
[49c6891]1253# Instalar Base de datos de OpenGnSys Admin.
[b6906f7]1254isInArray notinstalled "mysql-server"
1255if [ $? -eq 0 ]; then
1256        mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD}
1257else
1258        mysqlGetRootPassword
1259fi
[463a1d49]1260
[a01156a]1261mysqlTestConnection ${MYSQL_ROOT_PASSWORD}
1262if [ $? -ne 0 ]; then
1263        errorAndLog "Error while connection to mysql"
1264        exit 1
1265fi
[892606b9]1266mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
[a01156a]1267if [ $? -ne 0 ]; then
[cc7eab7]1268        echoAndLog "Creating Web Console database"
[892606b9]1269        mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
[a01156a]1270        if [ $? -ne 0 ]; then
[cc7eab7]1271                errorAndLog "Error while creating Web Console database"
[a01156a]1272                exit 1
1273        fi
1274else
[cc7eab7]1275        echoAndLog "Web Console database exists, ommiting creation"
[a01156a]1276fi
1277
[892606b9]1278mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER}
[a01156a]1279if [ $? -ne 0 ]; then
1280        echoAndLog "Creating user in database"
[892606b9]1281        mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
[a01156a]1282        if [ $? -ne 0 ]; then
[cc7eab7]1283                errorAndLog "Error while creating database user"
[a01156a]1284                exit 1
1285        fi
1286
1287fi
1288
[892606b9]1289mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
[a01156a]1290if [ $? -eq 0 ]; then
1291        echoAndLog "Creating tables..."
[892606b9]1292        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
1293                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
[a01156a]1294        else
[892606b9]1295                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
[a01156a]1296                exit 1
1297        fi
[bc7dfe7]1298else
1299        # Si existe fichero ogBDAdmin-VersLocal-VersRepo.sql; aplicar cambios.
1300        INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
1301        REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
[295b4ab]1302        OPENGNSYS_DB_UPDATE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
1303        if [ -f $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE ]; then
[bc7dfe7]1304                echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION"
[295b4ab]1305                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE
[bc7dfe7]1306        else
1307                echoAndLog "Database unchanged."
1308        fi
[a01156a]1309fi
1310
1311# copiando paqinas web
[7586ca3]1312installWebFiles
[5d6bf97]1313# Generar páqinas web de documentación de la API
1314makeDoxygenFiles
[a01156a]1315
1316# creando configuracion de apache2
[892606b9]1317openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2
[a01156a]1318if [ $? -ne 0 ]; then
[49c6891]1319        errorAndLog "Error configuring Apache for OpenGnSYS Admin"
[a01156a]1320        exit 1
1321fi
1322
1323popd
[892606b9]1324
[9ef8920]1325
1326# Crear la estructura de los accesos al servidor desde el cliente (shared)
[7cc6687]1327openGnsysCopyClientFiles
[9ef8920]1328if [ $? -ne 0 ]; then
1329        errorAndLog "Error creating client structure"
1330fi
1331
[d168a46]1332# Crear la estructura del cliente de OpenGnSys
[5ad5dcc]1333clientCreate
[a555f49]1334if [ $? -ne 0 ]; then
[813f617]1335        errorAndLog "Error creating client"
[a555f49]1336        exit 1
1337fi
[892606b9]1338
[65245d1]1339# Configuración de servicios de OpenGnSys
1340openGnsysConfigure
1341
[180a07dd]1342# Mostrar sumario de la instalación e instrucciones de post-instalación.
1343installationSummary
1344
[077dd7c5]1345#rm -rf $WORKDIR
[49c6891]1346echoAndLog "OpenGnSys installation finished at $(date)"
[2308fc7]1347
Note: See TracBrowser for help on using the repository browser.