source: installer/opengnsys_installer.sh @ 3998421

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 3998421 was 700299b, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: instalador configura logrotate desde la plantilla predefinida (cerrar #425)

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

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