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
Line 
1#!/bin/bash
2
3#####################################################################
4####### Script instalador OpenGnsys
5####### autor: Luis Guillén <lguillen@unizar.es>
6#####################################################################
7
8
9
10####  AVISO: Editar configuración de acceso por defecto a la Base de Datos.
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
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
22
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).
31PROGRAMDIR=$(readlink -e $(dirname "$0"))
32OPENGNSYS_SERVER="www.opengnsys.es"
33if [ -d "$PROGRAMDIR/../installer" ]; then
34    USESVN=0
35else
36    USESVN=1
37fi
38SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/"
39
40WORKDIR=/tmp/opengnsys_installer
41mkdir -p $WORKDIR
42
43INSTALL_TARGET=/opt/opengnsys
44LOG_FILE=/tmp/opengnsys_installation.log
45
46# Base de datos
47OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogAdmBD.sql
48
49
50#####################################################################
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
60# - ENABLEMOD, ENABLESITE - habilitar módulo Apache y sitio web
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"
80                ENABLEMOD="a2enmod"
81                ENABLESITE="a2ensite"
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#####################################################################
117####### Algunas funciones útiles de propósito general:
118#####################################################################
119
120function getDateTime()
121{
122        date "+%Y%m%d-%H%M%S"
123}
124
125# Escribe a fichero y muestra por pantalla
126function echoAndLog()
127{
128        echo "$1"
129        local DATETIME=`getDateTime`
130        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
131}
132
133function errorAndLog()
134{
135        echo "ERROR: $1"
136        local DATETIME=`getDateTime`
137        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
138}
139
140# comprueba si el elemento pasado en $2 esta en el array $1
141function isInArray()
142{
143        if [ $# -ne 2 ]; then
144                errorAndLog "${FUNCNAME}(): invalid number of parameters"
145                exit 1
146        fi
147
148        echoAndLog "${FUNCNAME}(): checking if $2 is in $1"
149        local deps
150        eval "deps=( \"\${$1[@]}\" )"
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
164                echoAndLog "${FUNCNAME}(): $elemento NOT found in array"
165        fi
166
167        return $is_in_array
168
169}
170
171#####################################################################
172####### Funciones de manejo de paquetes Debian
173#####################################################################
174
175function checkPackage()
176{
177        package=$1
178        if [ -z $package ]; then
179                errorAndLog "${FUNCNAME}(): parameter required"
180                exit 1
181        fi
182        echoAndLog "${FUNCNAME}(): checking if package $package exists"
183        eval $CHECKPKG
184        if [ $? -eq 0 ]; then
185                echoAndLog "${FUNCNAME}(): package $package exists"
186                return 0
187        else
188                echoAndLog "${FUNCNAME}(): package $package doesn't exists"
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
196function checkDependencies()
197{
198        if [ $# -ne 2 ]; then
199                errorAndLog "${FUNCNAME}(): invalid number of parameters"
200                exit 1
201        fi
202
203        echoAndLog "${FUNCNAME}(): checking dependences"
204        uncompletedeps=0
205
206        # copia local del array del parametro 1
207        local deps
208        eval "deps=( \"\${$1[@]}\" )"
209
210        declare -a local_notinstalled
211
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
228        echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps"
229        return $uncompletedeps
230}
231
232# Recibe un array con las dependencias y lo instala
233function installDependencies()
234{
235        if [ $# -ne 1 ]; then
236                errorAndLog "${FUNCNAME}(): invalid number of parameters"
237                exit 1
238        fi
239        echoAndLog "${FUNCNAME}(): installing uncompleted dependencies"
240
241        # copia local del array del parametro 1
242        local deps
243        eval "deps=( \"\${$1[@]}\" )"
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
252                errorAndLog "${FUNCNAME}(): array of dependeces is empty"
253                exit 1
254        fi
255
256        OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND
257        export DEBIAN_FRONTEND=noninteractive
258
259        echoAndLog "${FUNCNAME}(): now $string_deps will be installed"
260        eval $INSTALLPKG $string_deps
261        if [ $? -ne 0 ]; then
262                errorAndLog "${FUNCNAME}(): error installing dependencies"
263                return 1
264        fi
265
266        DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND
267        echoAndLog "${FUNCNAME}(): dependencies installed"
268}
269
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
279        local file="$1"
280        local dateymd=`date +%Y%m%d`
281
282        if [ ! -f "$file" ]; then
283                errorAndLog "${FUNCNAME}(): file $file doesn't exists"
284                return 1
285        fi
286
287        echoAndLog "${FUNCNAME}(): making $file backup"
288
289        # realiza una copia de la última configuración como last
290        cp -a "$file" "${file}-LAST"
291
292        # si para el día no hay backup lo hace, sino no
293        if [ ! -f "${file}-${dateymd}" ]; then
294                cp -a "$file" "${file}-${dateymd}"
295        fi
296
297        echoAndLog "${FUNCNAME}(): $file backup success"
298}
299
300#####################################################################
301####### Funciones para el manejo de bases de datos
302#####################################################################
303
304# This function set password to root
305function mysqlSetRootPassword()
306{
307        if [ $# -ne 1 ]; then
308                errorAndLog "${FUNCNAME}(): invalid number of parameters"
309                exit 1
310        fi
311
312        local root_mysql="$1"
313        echoAndLog "${FUNCNAME}(): setting root password in MySQL server"
314        mysqladmin -u root password "$root_mysql"
315        if [ $? -ne 0 ]; then
316                errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server"
317                return 1
318        fi
319        echoAndLog "${FUNCNAME}(): root password saved!"
320        return 0
321}
322
323# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
324function mysqlGetRootPassword()
325{
326        local pass_mysql
327        local pass_mysql2
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
333                echo "There is a MySQL service already installed."
334                read -p "Enter MySQL root password: " pass_mysql
335                echo ""
336                read -p "Confrim password:" pass_mysql2
337                echo ""
338                stty echo
339                if [ "$pass_mysql" == "$pass_mysql2" ] ;then
340                        MYSQL_ROOT_PASSWORD="$pass_mysql"
341                        return 0
342                else
343                        echo "The keys don't match. Do not configure the server's key,"
344                        echo "transactions in the database will give error."
345                        return 1
346                fi
347        fi
348}
349
350# comprueba si puede conectar con mysql con el usuario root
351function mysqlTestConnection()
352{
353        if [ $# -ne 1 ]; then
354                errorAndLog "${FUNCNAME}(): invalid number of parameters"
355                exit 1
356        fi
357
358        local root_password="${1}"
359        echoAndLog "${FUNCNAME}(): checking connection to mysql..."
360        echo "" | mysql -uroot -p"${root_password}"
361        if [ $? -ne 0 ]; then
362                errorAndLog "${FUNCNAME}(): connection to mysql failed, check root password and if daemon is running!"
363                return 1
364        else
365                echoAndLog "${FUNCNAME}(): connection success"
366                return 0
367        fi
368}
369
370# comprueba si la base de datos existe
371function mysqlDbExists()
372{
373        if [ $# -ne 2 ]; then
374                errorAndLog "${FUNCNAME}(): invalid number of parameters"
375                exit 1
376        fi
377
378        local root_password="${1}"
379        local database=$2
380        echoAndLog "${FUNCNAME}(): checking if $database exists..."
381        echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$"
382        if [ $? -ne 0 ]; then
383                echoAndLog "${FUNCNAME}():database $database doesn't exists"
384                return 1
385        else
386                echoAndLog "${FUNCNAME}():database $database exists"
387                return 0
388        fi
389}
390
391function mysqlCheckDbIsEmpty()
392{
393        if [ $# -ne 2 ]; then
394                errorAndLog "${FUNCNAME}(): invalid number of parameters"
395                exit 1
396        fi
397
398        local root_password="${1}"
399        local database=$2
400        echoAndLog "${FUNCNAME}(): checking if $database is empty..."
401        num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l`
402        if [ $? -ne 0 ]; then
403                errorAndLog "${FUNCNAME}(): error executing query, check database and root password"
404                exit 1
405        fi
406
407        if [ $num_tablas -eq 0 ]; then
408                echoAndLog "${FUNCNAME}():database $database is empty"
409                return 0
410        else
411                echoAndLog "${FUNCNAME}():database $database has tables"
412                return 1
413        fi
414
415}
416
417
418function mysqlImportSqlFileToDb()
419{
420        if [ $# -ne 3 ]; then
421                errorAndLog "${FNCNAME}(): invalid number of parameters"
422                exit 1
423        fi
424
425        local root_password="$1"
426        local database="$2"
427        local sqlfile="$3"
428        local tmpfile=$(mktemp)
429        local i=0
430        local dev=""
431        local status
432
433        if [ ! -f $sqlfile ]; then
434                errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!"
435                return 1
436        fi
437
438        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
439        chmod 600 $tmpfile
440        for dev in ${DEVICE[*]}; do
441                if [ "${DEVICE[i]} == $DEFAULTDEV" ]; then
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
449        mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $tmpfile
450        status=$?
451        rm -f $tmpfile
452        if [ $status -ne 0 ]; then
453                errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database"
454                return 1
455        fi
456        echoAndLog "${FUNCNAME}(): file imported to database $database"
457        return 0
458}
459
460# Crea la base de datos
461function mysqlCreateDb()
462{
463        if [ $# -ne 2 ]; then
464                errorAndLog "${FUNCNAME}(): invalid number of parameters"
465                exit 1
466        fi
467
468        local root_password="${1}"
469        local database=$2
470
471        echoAndLog "${FUNCNAME}(): creating database..."
472        mysqladmin -u root --password="${root_password}" create $database
473        if [ $? -ne 0 ]; then
474                errorAndLog "${FUNCNAME}(): error while creating database $database"
475                return 1
476        fi
477        echoAndLog "${FUNCNAME}(): database $database created"
478        return 0
479}
480
481
482function mysqlCheckUserExists()
483{
484        if [ $# -ne 2 ]; then
485                errorAndLog "${FUNCNAME}(): invalid number of parameters"
486                exit 1
487        fi
488
489        local root_password="${1}"
490        local userdb=$2
491
492        echoAndLog "${FUNCNAME}(): checking if $userdb exists..."
493        echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user
494        if [ $? -ne 0 ]; then
495                echoAndLog "${FUNCNAME}(): user doesn't exists"
496                return 1
497        else
498                echoAndLog "${FUNCNAME}(): user already exists"
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
508                errorAndLog "${FUNCNAME}(): invalid number of parameters"
509                exit 1
510        fi
511
512        local root_password=$1
513        local database=$2
514        local userdb=$3
515        local passdb=$4
516
517        echoAndLog "${FUNCNAME}(): creating admin user ${userdb} to database ${database}"
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
526                errorAndLog "${FUNCNAME}(): error while creating user in mysql"
527                rm -f $WORKDIR/create_${database}.sql
528                return 1
529        else
530                echoAndLog "${FUNCNAME}(): user created ok"
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
541function svnExportCode()
542{
543        if [ $# -ne 1 ]; then
544                errorAndLog "${FUNCNAME}(): invalid number of parameters"
545                exit 1
546        fi
547
548        local url="$1"
549
550        echoAndLog "${FUNCNAME}(): downloading subversion code..."
551
552        svn export --force "$url" opengnsys
553        if [ $? -ne 0 ]; then
554                errorAndLog "${FUNCNAME}(): error getting OpenGnSys code from $url"
555                return 1
556        fi
557        echoAndLog "${FUNCNAME}(): subversion code downloaded"
558        return 0
559}
560
561
562############################################################
563###  Detectar red
564############################################################
565
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.
574function getNetworkSettings()
575{
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."
594                exit 1
595        fi
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
607        DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1)
608        if [ -z "${NETIP}[*]" -o -z "${NETMASK[*]}" ]; then
609                errorAndLog "${FUNCNAME}(): Network not detected."
610                exit 1
611        fi
612
613        # Variables de ejecución de Apache
614        # - APACHE_RUN_USER
615        # - APACHE_RUN_GROUP
616        if [ -f $APACHECFGDIR/envvars ]; then
617                source $APACHECFGDIR/envvars
618        fi
619        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
620        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
621}
622
623
624############################################################
625### Esqueleto para el Servicio pxe y contenedor tftpboot ###
626############################################################
627
628function tftpConfigure()
629{
630        echoAndLog "${FUNCNAME}(): Configuring TFTP service."
631        # reiniciamos demonio internet ????? porque ????
632        /etc/init.d/openbsd-inetd start
633
634        # preparacion contenedor tftpboot
635        cp -ar /usr/lib/syslinux/ $TFTPCFGDIR/syslinux
636        cp -a /usr/lib/syslinux/pxelinux.0 $TFTPCFGDIR
637        # prepamos el directorio de la configuracion de pxe
638        mkdir -p $TFTPCFGDIR/pxelinux.cfg
639        cat > $TFTPCFGDIR/pxelinux.cfg/default <<EOF
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
650EOF
651        # comprobamos el servicio tftp
652        sleep 1
653        testPxe
654}
655
656function testPxe ()
657{
658        echoAndLog "${FUNCNAME}(): Checking TFTP service... please wait."
659        cd /tmp
660        tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echoAndLog "TFTP service is OK." || errorAndLog "TFTP service is down."
661        cd /
662}
663
664
665########################################################################
666## Configuracion servicio Samba
667########################################################################
668function smbConfigure()
669{
670        echoAndLog "${FUNCNAME}(): Configuring Samba service."
671
672        backupFile $SAMBACFGDIR/smb.conf
673       
674        # Copiar plantailla de recursos para OpenGnSys
675        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
676                $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf
677        # Configurar y recargar Samba"
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
680        if [ $? -ne 0 ]; then
681                errorAndLog "${FUNCNAME}(): error while configure Samba"
682                return 1
683        fi
684        # Crear clave para usuario de acceso a los recursos.
685        echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | smbpasswd -a -s $OPENGNSYS_CLIENT_USER
686
687        echoAndLog "${FUNCNAME}(): Added Samba configuration."
688        return 0
689}
690
691
692########################################################################
693## Configuracion servicio DHCP
694########################################################################
695
696function dhcpConfigure()
697{
698        echoAndLog "${FUNCNAME}(): Sample DHCP configuration."
699
700        local errcode=0
701        local i=0
702        local dev=""
703
704        backupFile $DHCPCFGDIR/dhcpd.conf
705        for dev in ${DEVICE[*]}; do
706                if [ -n "${SERVERIP[i]}" ]; then
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
719                errorAndLog "${FUNCNAME}(): error while configuring DHCP server"
720                return 1
721        fi
722        ln -f $DHCPCFGDIR/dhcpd-$DEFAULTDEV.conf $DHCPCFGDIR/dhcpd.conf
723        $DHCPINIT restart
724        echoAndLog "${FUNCNAME}(): Sample DHCP configured in \"$DHCPCFGDIR\"."
725        return 0
726}
727
728
729#####################################################################
730####### Funciones específicas de la instalación de Opengnsys
731#####################################################################
732
733# Copiar ficheros del OpenGnSys Web Console.
734function installWebFiles()
735{
736        echoAndLog "${FUNCNAME}(): Installing web files..."
737        cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www   #*/ comentario para doxigen
738        if [ $? != 0 ]; then
739                errorAndLog "${FUNCNAME}(): Error copying web files."
740                exit 1
741        fi
742        find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null
743        # Descomprimir XAJAX.
744        unzip $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
745        # Cambiar permisos para ficheros especiales.
746        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/iconos
747        echoAndLog "${FUNCNAME}(): Web files installed successfully."
748}
749
750# Configuración específica de Apache.
751function openGnsysInstallWebConsoleApacheConf()
752{
753        if [ $# -ne 2 ]; then
754                errorAndLog "${FUNCNAME}(): invalid number of parameters"
755                exit 1
756        fi
757
758        local path_opengnsys_base=$1
759        local path_apache2_confd=$2
760        local path_web_console=${path_opengnsys_base}/www
761
762        if [ ! -d $path_apache2_confd ]; then
763                errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation"
764                return 1
765        fi
766
767        mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
768
769        echoAndLog "${FUNCNAME}(): creating apache2 config file.."
770
771        # Activar HTTPS.
772        $ENABLESITE default-ssl
773        $ENABLEMOD ssl
774        make-ssl-cert generate-default-snakeoil --force-overwrite
775
776        # Genera configuración de consola web.
777        cat > $path_opengnsys_base/etc/apache.conf <<EOF
778# OpenGnSys Web Console configuration for Apache
779
780Alias /opengnsys ${path_web_console}
781
782<Directory ${path_web_console}>
783        Options -Indexes FollowSymLinks
784        DirectoryIndex acceso.php
785</Directory>
786EOF
787
788        ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys
789        $ENABLESITE opengnsys
790        if [ $? -ne 0 ]; then
791                errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation"
792                return 1
793        else
794                echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon"
795                $APACHEINIT restart
796                return 0
797        fi
798}
799
800
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."
809                return 1
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
817# Crea la estructura base de la instalación de opengnsys
818function createDirs()
819{
820        if [ $# -ne 1 ]; then
821                errorAndLog "${FUNCNAME}(): invalid number of parameters"
822                exit 1
823        fi
824
825        local path_opengnsys_base="$1"
826
827        # Crear estructura de directorios.
828        echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base"
829        mkdir -p $path_opengnsys_base
830        mkdir -p $path_opengnsys_base/bin
831        mkdir -p $path_opengnsys_base/client
832        mkdir -p $path_opengnsys_base/doc
833        mkdir -p $path_opengnsys_base/etc
834        mkdir -p $path_opengnsys_base/lib
835        mkdir -p $path_opengnsys_base/log/clients
836        ln -fs $path_opengnsys_base/log /var/log/opengnsys
837        mkdir -p $path_opengnsys_base/sbin
838        mkdir -p $path_opengnsys_base/www
839        mkdir -p $path_opengnsys_base/images
840        ln -fs /var/lib/tftpboot $path_opengnsys_base
841        mkdir -p $path_opengnsys_base/tftpboot/pxelinux.cfg
842        mkdir -p $path_opengnsys_base/tftpboot/menu.lst
843        if [ $? -ne 0 ]; then
844                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
845                return 1
846        fi
847
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"
862        chmod -R 775 $path_opengnsys_base/{log/clients,images}
863        chown -R :$OPENGNSYS_CLIENT_USER $path_opengnsys_base/{log/clients,images}
864        if [ $? -ne 0 ]; then
865                errorAndLog "${FUNCNAME}(): error while setting permissions"
866                return 1
867        fi
868
869        echoAndLog "${FUNCNAME}(): directory paths created"
870        return 0
871}
872
873# Copia ficheros de configuración y ejecutables genéricos del servidor.
874function openGnsysCopyServerFiles ()
875{
876        if [ $# -ne 1 ]; then
877                errorAndLog "${FUNCNAME}(): invalid number of parameters"
878                exit 1
879        fi
880
881        local path_opengnsys_base="$1"
882
883        local SOURCES=( server/tftpboot \
884                        server/bin \
885                        repoman/bin \
886                        installer/opengnsys_uninstall.sh \
887                        installer/opengnsys_update.sh \
888                        doc )
889        local TARGETS=( tftpboot \
890                        bin \
891                        bin \
892                        lib \
893                        lib \
894                        doc )
895
896        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
897                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
898                exit 1
899        fi
900
901        echoAndLog "${FUNCNAME}(): copying files to server directories"
902
903        pushd $WORKDIR/opengnsys
904        local i
905        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
906                if [ -f "${SOURCES[$i]}" ]; then
907                        echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
908                        cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
909                elif [ -d "${SOURCES[$i]}" ]; then
910                        echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
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]}"
914                fi
915        done
916        popd
917}
918
919####################################################################
920### Funciones de compilación de código fuente de servicios
921####################################################################
922
923# Compilar los servicios de OpenGnSys
924function servicesCompilation ()
925{
926        local hayErrores=0
927
928        # Compilar OpenGnSys Server
929        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server"
930        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
931        make && mv ogAdmServer $INSTALL_TARGET/sbin
932        if [ $? -ne 0 ]; then
933                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
934                hayErrores=1
935        fi
936        popd
937        # Compilar OpenGnSys Repository Manager
938        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager"
939        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
940        make && mv ogAdmRepo $INSTALL_TARGET/sbin
941        if [ $? -ne 0 ]; then
942                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
943                hayErrores=1
944        fi
945        popd
946        # Compilar OpenGnSys Agent
947        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent"
948        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
949        make && mv ogAdmAgent $INSTALL_TARGET/sbin
950        if [ $? -ne 0 ]; then
951                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent"
952                hayErrores=1
953        fi
954        popd   
955        # Compilar OpenGnSys Client
956        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client"
957        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
958        make && mv ogAdmClient ../../../../client/shared/bin
959        if [ $? -ne 0 ]; then
960                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client"
961                hayErrores=1
962        fi
963        popd
964
965        return $hayErrores
966}
967
968####################################################################
969### Funciones de copia de la Interface de administración
970####################################################################
971
972# Copiar carpeta de Interface
973function copyInterfaceAdm ()
974{
975        local hayErrores=0
976       
977        # Crear carpeta y copiar Interface
978        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
979        cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm
980        if [ $? -ne 0 ]; then
981                echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder"
982                hayErrores=1
983        fi
984        chown $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
985        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
986
987        return $hayErrores
988}
989
990####################################################################
991### Funciones instalacion cliente opengnsys
992####################################################################
993
994function openGnsysCopyClientFiles()
995{
996        local errstatus=0
997
998        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
999        cp -ar $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
1000        if [ $? -ne 0 ]; then
1001                errorAndLog "${FUNCNAME}(): error while copying client estructure"
1002                errstatus=1
1003        fi
1004        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
1005       
1006        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
1007        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
1008        cp -ar $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
1009        if [ $? -ne 0 ]; then
1010                errorAndLog "${FUNCNAME}(): error while copying engine files"
1011                errstatus=1
1012        fi
1013       
1014        if [ $errstatus -eq 0 ]; then
1015                echoAndLog "${FUNCNAME}(): client copy files success."
1016        else
1017                errorAndLog "${FUNCNAME}(): client copy files with errors"
1018        fi
1019
1020        return $errstatus
1021}
1022
1023
1024# Crear cliente OpenGnSys 1.0.2
1025function clientCreate()
1026{
1027        local DOWNLOADURL="http://www.opengnsys.es/downloads"
1028        local FILENAME=ogclient-1.0.2-natty-32bit-beta01-rev2111.iso
1029        local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
1030        local TMPDIR=/tmp/${FILENAME%.iso}
1031 
1032        echoAndLog "${FUNCNAME}(): Loading Client"
1033        # Descargar, montar imagen, copiar cliente ogclient y desmontar.
1034        wget $DOWNLOADURL/$FILENAME -O $TARGETFILE
1035        if [ ! -s $TARGETFILE ]; then
1036                errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client"
1037                return 1
1038        fi
1039        echoAndLog "${FUNCNAME}(): Copying Client files"
1040        mkdir -p $TMPDIR
1041        mount -o loop,ro $TARGETFILE $TMPDIR
1042        cp -vr $TMPDIR/ogclient $INSTALL_TARGET/tftpboot
1043        umount $TMPDIR
1044        rmdir $TMPDIR
1045
1046        # Establecer los permisos.
1047        find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \;
1048        find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \;
1049        chown -R :$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/tftpboot/ogclient
1050        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg}
1051        echoAndLog "${FUNCNAME}(): Client generation success"
1052}
1053
1054
1055# Configuración básica de servicios de OpenGnSys
1056function openGnsysConfigure()
1057{
1058        local i=0
1059        local dev=""
1060
1061        echoAndLog "${FUNCNAME}(): Copying init files."
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
1064        cp -p $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepoAux /opt/opengnsys/sbin/
1065        update-rc.d opengnsys defaults
1066        echoAndLog "${FUNCNAME}(): Creating cron files."
1067        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
1068        echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
1069
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
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
1111        echoAndLog "${FUNCNAME}(): Starting OpenGnSys services."
1112        /etc/init.d/opengnsys start
1113}
1114
1115
1116#####################################################################
1117#######  Función de resumen informativo de la instalación
1118#####################################################################
1119
1120function installationSummary()
1121{
1122        # Crear fichero de versión y revisión, si no existe.
1123        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
1124        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}')
1125        [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE
1126        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
1127
1128        # Mostrar información.
1129        echo
1130        echoAndLog "OpenGnSys Installation Summary"
1131        echo       "=============================="
1132        echoAndLog "Project version:                  $(cat $VERSIONFILE 2>/dev/null)"
1133        echoAndLog "Installation directory:           $INSTALL_TARGET"
1134        echoAndLog "Repository directory:             $INSTALL_TARGET/images"
1135        echoAndLog "DHCP configuration directory:     $DHCPCFGDIR"
1136        echoAndLog "TFTP configuration directory:     /var/lib/tftpboot"
1137        echoAndLog "Samba configuration directory:    /etc/samba"
1138        echoAndLog "Web Console URL:                  $OPENGNSYS_CONSOLEURL"
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."
1145        echoAndLog "Insert DHCP configuration data and restart service."
1146        echoAndLog "Log-in as Web Console admin user."
1147        echoAndLog " - Review default Organization data and assign default user."
1148        echoAndLog "Log-in as Web Console organization user."
1149        echoAndLog " - Insert OpenGnSys data (rooms, computers, menus, etc)."
1150echo
1151}
1152
1153
1154
1155#####################################################################
1156####### Proceso de instalación de OpenGnSys
1157#####################################################################
1158
1159echoAndLog "OpenGnSys installation begins at $(date)"
1160pushd $WORKDIR
1161
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
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
1179
1180# Detener servicios de OpenGnSys, si están activos previamente.
1181[ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop
1182
1183# Actualizar repositorios
1184eval $UPDATEPKGLIST
1185
1186# Instalación de dependencias (paquetes de sistema operativo).
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
1197# Arbol de directorios de OpenGnSys.
1198createDirs ${INSTALL_TARGET}
1199if [ $? -ne 0 ]; then
1200        errorAndLog "Error while creating directory paths!"
1201        exit 1
1202fi
1203
1204# Si es necesario, descarga el repositorio de código en directorio temporal
1205if [ $USESVN -eq 1 ]; then
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
1213fi
1214
1215# Compilar código fuente de los servicios de OpenGnSys.
1216servicesCompilation
1217if [ $? -ne 0 ]; then
1218        errorAndLog "Error while compiling OpenGnsys services"
1219        exit 1
1220fi
1221
1222# Copiar carpeta Interface entre administración y motor de clonación.
1223copyInterfaceAdm
1224if [ $? -ne 0 ]; then
1225        errorAndLog "Error while copying Administration Interface"
1226        exit 1
1227fi
1228
1229# Configurando tftp
1230tftpConfigure
1231
1232# Configuración Samba
1233smbConfigure
1234if [ $? -ne 0 ]; then
1235        errorAndLog "Error while configuring Samba server!"
1236        exit 1
1237fi
1238
1239# Configuración ejemplo DHCP
1240dhcpConfigure
1241if [ $? -ne 0 ]; then
1242        errorAndLog "Error while copying your dhcp server files!"
1243        exit 1
1244fi
1245
1246# Copiar ficheros de servicios OpenGnSys Server.
1247openGnsysCopyServerFiles ${INSTALL_TARGET}
1248if [ $? -ne 0 ]; then
1249        errorAndLog "Error while copying the server files!"
1250        exit 1
1251fi
1252
1253# Instalar Base de datos de OpenGnSys Admin.
1254isInArray notinstalled "mysql-server"
1255if [ $? -eq 0 ]; then
1256        mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD}
1257else
1258        mysqlGetRootPassword
1259fi
1260
1261mysqlTestConnection ${MYSQL_ROOT_PASSWORD}
1262if [ $? -ne 0 ]; then
1263        errorAndLog "Error while connection to mysql"
1264        exit 1
1265fi
1266mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1267if [ $? -ne 0 ]; then
1268        echoAndLog "Creating Web Console database"
1269        mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1270        if [ $? -ne 0 ]; then
1271                errorAndLog "Error while creating Web Console database"
1272                exit 1
1273        fi
1274else
1275        echoAndLog "Web Console database exists, ommiting creation"
1276fi
1277
1278mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER}
1279if [ $? -ne 0 ]; then
1280        echoAndLog "Creating user in database"
1281        mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
1282        if [ $? -ne 0 ]; then
1283                errorAndLog "Error while creating database user"
1284                exit 1
1285        fi
1286
1287fi
1288
1289mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1290if [ $? -eq 0 ]; then
1291        echoAndLog "Creating tables..."
1292        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
1293                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
1294        else
1295                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
1296                exit 1
1297        fi
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)
1302        OPENGNSYS_DB_UPDATE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
1303        if [ -f $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE ]; then
1304                echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION"
1305                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE
1306        else
1307                echoAndLog "Database unchanged."
1308        fi
1309fi
1310
1311# copiando paqinas web
1312installWebFiles
1313# Generar páqinas web de documentación de la API
1314makeDoxygenFiles
1315
1316# creando configuracion de apache2
1317openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2
1318if [ $? -ne 0 ]; then
1319        errorAndLog "Error configuring Apache for OpenGnSYS Admin"
1320        exit 1
1321fi
1322
1323popd
1324
1325
1326# Crear la estructura de los accesos al servidor desde el cliente (shared)
1327openGnsysCopyClientFiles
1328if [ $? -ne 0 ]; then
1329        errorAndLog "Error creating client structure"
1330fi
1331
1332# Crear la estructura del cliente de OpenGnSys
1333clientCreate
1334if [ $? -ne 0 ]; then
1335        errorAndLog "Error creating client"
1336        exit 1
1337fi
1338
1339# Configuración de servicios de OpenGnSys
1340openGnsysConfigure
1341
1342# Mostrar sumario de la instalación e instrucciones de post-instalación.
1343installationSummary
1344
1345#rm -rf $WORKDIR
1346echoAndLog "OpenGnSys installation finished at $(date)"
1347
Note: See TracBrowser for help on using the repository browser.