source: ogLive-Builder-Git/ogInstaller.lib @ e972c32

browserbuild-browserdeps-vadimfilebeat-installerimprove-versionlgromero-testsmainno-apt-moduleoglive-ipv6pull-from-cloning-enginepybuilderqndtest
Last change on this file since e972c32 was d17950b, checked in by adv <adv@…>, 14 years ago

version1.0 renombrando ogclient boot-tools

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

  • Property mode set to 100644
File size: 28.8 KB
Line 
1#!/bin/bash
2
3
4#####################################################################
5####### Algunas funciones útiles de propósito general:
6#####################################################################
7function getDateTime()
8{
9        echo `date +%Y%m%d-%H%M%S`
10}
11
12# Escribe a fichero y muestra por pantalla
13function echoAndLog()
14{
15        echo $1
16        FECHAHORA=`getDateTime`
17        echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE
18}
19
20function errorAndLog()
21{
22        echo "ERROR: $1"
23        FECHAHORA=`getDateTime`
24        echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
25}
26
27# comprueba si el elemento pasado en $2 esta en el array $1
28function isInArray()
29{
30        if [ $# -ne 2 ]; then
31                errorAndLog "${FUNCNAME}(): invalid number of parameters"
32                exit 1
33        fi
34
35        echoAndLog "${FUNCNAME}(): checking if $2 is in $1"
36        local deps
37        eval "deps=( \"\${$1[@]}\" )"
38        elemento=$2
39
40        local is_in_array=1
41        # copia local del array del parametro 1
42        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
43        do
44                if [ "${deps[$i]}" = "${elemento}" ]; then
45                        echoAndLog "isInArray(): $elemento found in array"
46                        is_in_array=0
47                fi
48        done
49
50        if [ $is_in_array -ne 0 ]; then
51                echoAndLog "${FUNCNAME}(): $elemento NOT found in array"
52        fi
53
54        return $is_in_array
55
56}
57
58#####################################################################
59####### Funciones de manejo de paquetes Debian
60#####################################################################
61
62function checkPackage()
63{
64        package=$1
65        if [ -z $package ]; then
66                errorAndLog "checkPackage(): parameter required"
67                exit 1
68        fi
69        echoAndLog "checkPackage(): checking if package $package exists"
70        dpkg -s $package | grep Status | grep -qw install &>/dev/null
71        if [ $? -eq 0 ]; then
72                echoAndLog "checkPackage(): package $package exists"
73                return 0
74        else
75                echoAndLog "checkPackage(): package $package doesn't exists"
76                return 1
77        fi
78}
79
80# recibe array con dependencias
81# por referencia deja un array con las dependencias no resueltas
82# devuelve 1 si hay alguna dependencia no resuelta
83function checkDependencies()
84{
85        if [ $# -ne 2 ]; then
86                errorAndLog "checkDependencies(): invalid number of parameters"
87                exit 1
88        fi
89
90        echoAndLog "checkDependencies(): checking dependences"
91        uncompletedeps=0
92
93        # copia local del array del parametro 1
94        local deps
95        eval "deps=( \"\${$1[@]}\" )"
96
97        declare -a local_notinstalled
98
99        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
100        do
101                checkPackage ${deps[$i]}
102                if [ $? -ne 0 ]; then
103                        local_notinstalled[$uncompletedeps]=$package
104                        let uncompletedeps=uncompletedeps+1
105                fi
106        done
107
108        # relleno el array especificado en $2 por referencia
109        for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ ))
110        do
111                eval "${2}[$i]=${local_notinstalled[$i]}"
112        done
113
114        # retorna el numero de paquetes no resueltos
115        echoAndLog "checkDependencies(): dependencies uncompleted: $uncompletedeps"
116        return $uncompletedeps
117}
118
119# Recibe un array con las dependencias y lo instala
120function installDependencies()
121{
122        if [ $# -ne 1 ]; then
123                errorAndLog "installDependencies(): invalid number of parameters"
124                exit 1
125        fi
126        echoAndLog "installDependencies(): installing uncompleted dependencies"
127
128        # copia local del array del parametro 1
129        local deps
130        eval "deps=( \"\${$1[@]}\" )"
131
132        local string_deps=""
133        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
134        do
135                string_deps="$string_deps ${deps[$i]}"
136        done
137
138        if [ -z "${string_deps}" ]; then
139                errorAndLog "installDependencies(): array of dependeces is empty"
140                exit 1
141        fi
142
143        OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND
144        export DEBIAN_FRONTEND=noninteractive
145
146        echoAndLog "installDependencies(): now ${string_deps} will be installed"
147        apt-get -y install --force-yes ${string_deps}
148        if [ $? -ne 0 ]; then
149                errorAndLog "installDependencies(): error installing dependencies"
150                return 1
151        fi
152
153        DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND
154        echoAndLog "installDependencies(): dependencies installed"
155}
156
157# Hace un backup del fichero pasado por parámetro
158# deja un -last y uno para el día
159function backupFile()
160{
161        if [ $# -ne 1 ]; then
162                errorAndLog "${FUNCNAME}(): invalid number of parameters"
163                exit 1
164        fi
165
166        local fichero=$1
167        local fecha=`date +%Y%m%d`
168
169        if [ ! -f $fichero ]; then
170                errorAndLog "${FUNCNAME}(): file $fichero doesn't exists"
171                return 1
172        fi
173
174        echoAndLog "${FUNCNAME}(): realizando backup de $fichero"
175
176        # realiza una copia de la última configuración como last
177        cp -p $fichero "${fichero}-LAST"
178
179        # si para el día no hay backup lo hace, sino no
180        if [ ! -f "${fichero}-${fecha}" ]; then
181                cp -p $fichero "${fichero}-${fecha}"
182        fi
183
184        echoAndLog "${FUNCNAME}(): backup realizado"
185}
186
187#####################################################################
188####### Funciones para el manejo de bases de datos
189#####################################################################
190
191# This function set password to root
192function mysqlSetRootPassword()
193{
194        if [ $# -ne 1 ]; then
195                errorAndLog "mysqlSetRootPassword(): invalid number of parameters"
196                exit 1
197        fi
198
199        local root_mysql=$1
200        echoAndLog "mysqlSetRootPassword(): setting root password in MySQL server"
201        /usr/bin/mysqladmin -u root password ${root_mysql}
202        if [ $? -ne 0 ]; then
203                errorAndLog "mysqlSetRootPassword(): error while setting root password in MySQL server"
204                return 1
205        fi
206        echoAndLog "mysqlSetRootPassword(): root password saved!"
207        return 0
208}
209
210# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
211function mysqlGetRootPassword(){
212        local pass_mysql
213        local pass_mysql2
214        # Comprobar si MySQL está instalado con la clave de root por defecto.
215        if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then
216                echoAndLog "${FUNCNAME}(): Using default mysql root password."
217        else
218                stty -echo
219                echo "Existe un servicio mysql ya instalado"
220                read -p  "Insertar clave de root de Mysql: " pass_mysql
221                echo ""
222                read -p "Confirmar clave:" pass_mysql2
223                echo ""
224                stty echo
225                if [ "$pass_mysql" == "$pass_mysql2" ] ;then
226                        MYSQL_ROOT_PASSWORD=$pass_mysql
227                        echo "La clave es: ${MYSQL_ROOT_PASSWORD}"
228                        return 0
229                else
230                        echo "Las claves no coinciden no se configura la clave del servidor de base de datos."
231                        echo "las operaciones con la base de datos daran error"
232                        return 1
233                fi
234        fi
235}
236
237# comprueba si puede conectar con mysql con el usuario root
238function mysqlTestConnection()
239{
240        if [ $# -ne 1 ]; then
241                errorAndLog "mysqlTestConnection(): invalid number of parameters"
242                exit 1
243        fi
244
245        local root_password="${1}"
246        echoAndLog "mysqlTestConnection(): checking connection to mysql..."
247        echo "" | mysql -uroot -p"${root_password}"
248        if [ $? -ne 0 ]; then
249                errorAndLog "mysqlTestConnection(): connection to mysql failed, check root password and if daemon is running!"
250                return 1
251        else
252                echoAndLog "mysqlTestConnection(): connection success"
253                return 0
254        fi
255}
256
257# comprueba si la base de datos existe
258function mysqlDbExists()
259{
260        if [ $# -ne 2 ]; then
261                errorAndLog "mysqlDbExists(): invalid number of parameters"
262                exit 1
263        fi
264
265        local root_password="${1}"
266        local database=$2
267        echoAndLog "mysqlDbExists(): checking if $database exists..."
268        echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$"
269        if [ $? -ne 0 ]; then
270                echoAndLog "mysqlDbExists():database $database doesn't exists"
271                return 1
272        else
273                echoAndLog "mysqlDbExists():database $database exists"
274                return 0
275        fi
276}
277
278function mysqlCheckDbIsEmpty()
279{
280        if [ $# -ne 2 ]; then
281                errorAndLog "mysqlCheckDbIsEmpty(): invalid number of parameters"
282                exit 1
283        fi
284
285        local root_password="${1}"
286        local database=$2
287        echoAndLog "mysqlCheckDbIsEmpty(): checking if $database is empty..."
288        num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l`
289        if [ $? -ne 0 ]; then
290                errorAndLog "mysqlCheckDbIsEmpty(): error executing query, check database and root password"
291                exit 1
292        fi
293
294        if [ $num_tablas -eq 0 ]; then
295                echoAndLog "mysqlCheckDbIsEmpty():database $database is empty"
296                return 0
297        else
298                echoAndLog "mysqlCheckDbIsEmpty():database $database has tables"
299                return 1
300        fi
301
302}
303
304
305function mysqlImportSqlFileToDb()
306{
307        if [ $# -ne 3 ]; then
308                errorAndLog "${FNCNAME}(): invalid number of parameters"
309                exit 1
310        fi
311
312        local root_password="${1}"
313        local database=$2
314        local sqlfile=$3
315
316        if [ ! -f $sqlfile ]; then
317                errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!"
318                return 1
319        fi
320
321        echoAndLog "${FUNCNAME}(): importing sql file to ${database}..."
322        perl -pi -e "s/SERVERIP/$SERVERIP/g; s/DEFAULTUSER/$OPENGNSYS_DB_DEFAULTUSER/g; s/DEFAULTPASSWD/$OPENGNSYS_DB_DEFAULTPASSWD/g" $sqlfile
323        mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $sqlfile
324        if [ $? -ne 0 ]; then
325                errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database"
326                return 1
327        fi
328        echoAndLog "${FUNCNAME}(): file imported to database $database"
329        return 0
330}
331
332# Crea la base de datos
333function mysqlCreateDb()
334{
335        if [ $# -ne 2 ]; then
336                errorAndLog "${FUNCNAME}(): invalid number of parameters"
337                exit 1
338        fi
339
340        local root_password="${1}"
341        local database=$2
342
343        echoAndLog "${FUNCNAME}(): creating database..."
344        mysqladmin -u root --password="${root_password}" create $database
345        if [ $? -ne 0 ]; then
346                errorAndLog "${FUNCNAME}(): error while creating database $database"
347                return 1
348        fi
349        echoAndLog "${FUNCNAME}(): database $database created"
350        return 0
351}
352
353
354function mysqlCheckUserExists()
355{
356        if [ $# -ne 2 ]; then
357                errorAndLog "mysqlCheckUserExists(): invalid number of parameters"
358                exit 1
359        fi
360
361        local root_password="${1}"
362        local userdb=$2
363
364        echoAndLog "mysqlCheckUserExists(): checking if $userdb exists..."
365        echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user
366        if [ $? -ne 0 ]; then
367                echoAndLog "mysqlCheckUserExists(): user doesn't exists"
368                return 1
369        else
370                echoAndLog "mysqlCheckUserExists(): user already exists"
371                return 0
372        fi
373
374}
375
376# Crea un usuario administrativo para la base de datos
377function mysqlCreateAdminUserToDb()
378{
379        if [ $# -ne 4 ]; then
380                errorAndLog "mysqlCreateAdminUserToDb(): invalid number of parameters"
381                exit 1
382        fi
383
384        local root_password=$1
385        local database=$2
386        local userdb=$3
387        local passdb=$4
388
389        echoAndLog "mysqlCreateAdminUserToDb(): creating admin user ${userdb} to database ${database}"
390
391        cat > $WORKDIR/create_${database}.sql <<EOF
392GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
393GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
394FLUSH PRIVILEGES ;
395EOF
396        mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql
397        if [ $? -ne 0 ]; then
398                errorAndLog "mysqlCreateAdminUserToDb(): error while creating user in mysql"
399                rm -f $WORKDIR/create_${database}.sql
400                return 1
401        else
402                echoAndLog "mysqlCreateAdminUserToDb(): user created ok"
403                rm -f $WORKDIR/create_${database}.sql
404                return 0
405        fi
406}
407
408
409#####################################################################
410####### Funciones para el manejo de Subversion
411#####################################################################
412
413function svnExportCode()
414{
415        if [ $# -ne 1 ]; then
416                errorAndLog "${FUNCNAME}(): invalid number of parameters"
417                exit 1
418        fi
419
420        local url=$1
421
422        echoAndLog "${FUNCNAME}(): downloading subversion code..."
423
424        svn export "${url}" opengnsys
425        if [ $? -ne 0 ]; then
426                errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
427                return 1
428        fi
429        echoAndLog "${FUNCNAME}(): subversion code downloaded"
430        return 0
431}
432
433
434############################################################
435###  Detectar red
436############################################################
437
438function getNetworkSettings()
439{
440        # Variables globales definidas:
441        # - SERVERIP: IP local del servidor.
442        # - NETIP:    IP de la red.
443        # - NETMASK:  máscara de red.
444        # - NETBROAD: IP de difusión de la red.
445        # - ROUTERIP: IP del router.
446        # - DNSIP:    IP del servidor DNS.
447
448        local MAINDEV
449
450        echoAndLog "${FUNCNAME}(): Detecting default network parameters."
451        MAINDEV=$(ip -o link show up | awk '!/loopback/ {d=d$2} END {sub(/:.*/,"",d); print d}')
452        if [ -z "$MAINDEV" ]; then
453                errorAndLog "${FUNCNAME}(): Network device not detected."
454                exit 1
455        fi
456        SERVERIP=$(ip -o addr show dev $MAINDEV | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
457        NETMASK=$(LANG=C ifconfig $MAINDEV | awk '/Mask/ {sub(/.*:/,"",$4); print $4}')
458        NETBROAD=$(ip -o addr show dev $MAINDEV | awk '$3~/inet$/ {print ($6)}')
459        NETIP=$(netstat -nr | grep $MAINDEV | awk '$1!~/0\.0\.0\.0/ {if (n=="") n=$1} END {print n}')
460        ROUTERIP=$(netstat -nr | awk '$1~/0\.0\.0\.0/ {print $2}')
461        DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1)
462        if [ -z "$NETIP" -o -z "$NETMASK" ]; then
463                errorAndLog "${FUNCNAME}(): Network not detected."
464                exit 1
465        fi
466
467        # Variables de ejecución de Apache
468        # - APACHE_RUN_USER
469        # - APACHE_RUN_GROUP
470        if [ -f /etc/apache2/envvars ]; then
471                source /etc/apache2/envvars
472        fi
473        APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
474        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
475}
476
477
478############################################################
479### Esqueleto para el Servicio pxe y contenedor tftpboot ###
480############################################################
481
482function tftpConfigure() {
483        echo "Configurando el servicio tftp"
484        basetftp=/var/lib/tftpboot
485
486        # reiniciamos demonio internet ????? porque ????
487        /etc/init.d/openbsd-inetd start
488
489        # preparacion contenedor tftpboot
490        cp -pr /usr/lib/syslinux/ ${basetftp}/syslinux
491        cp /usr/lib/syslinux/pxelinux.0 ${basetftp}
492        # prepamos el directorio de la configuracion de pxe
493        mkdir -p ${basetftp}/pxelinux.cfg
494        cat > ${basetftp}/pxelinux.cfg/default <<EOF
495DEFAULT pxe
496
497LABEL pxe
498KERNEL linux
499APPEND initrd=initrd.gz ip=dhcp ro vga=788 irqpoll acpi=on
500EOF
501        # comprobamos el servicio tftp
502        sleep 1
503        testPxe
504        ## damos perfimos de lectura a usuario web.
505        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP ${basetftp}
506}
507
508function testPxe () {
509        cd /tmp
510        echo "comprobando servicio pxe ..... Espere"
511        tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echo "servidor tftp OK" || echo "servidor tftp KO"
512        cd /
513}
514
515########################################################################
516## Configuracion servicio NFS
517########################################################################
518
519# ADVERTENCIA: usa variables globales NETIP y NETMASK!
520function nfsConfigure()
521{
522        echoAndLog "${FUNCNAME}(): Config nfs server."
523
524        backupFile /etc/exports
525
526        nfsAddExport /opt/opengnsys/client ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync
527        if [ $? -ne 0 ]; then
528                errorAndLog "${FUNCNAME}(): error while adding nfs client config"
529                return 1
530        fi
531
532        nfsAddExport /opt/opengnsys/images ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync,crossmnt
533        if [ $? -ne 0 ]; then
534                errorAndLog "${FUNCNAME}(): error while adding nfs images config"
535                return 1
536        fi
537
538        nfsAddExport /opt/opengnsys/log/clients ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync
539        if [ $? -ne 0 ]; then
540                errorAndLog "${FUNCNAME}(): error while adding logging client config"
541                return 1
542        fi
543
544        /etc/init.d/nfs-kernel-server restart
545
546        exportfs -va
547        if [ $? -ne 0 ]; then
548                errorAndLog "${FUNCNAME}(): error while configure exports"
549                return 1
550        fi
551
552        echoAndLog "${FUNCNAME}(): Added NFS configuration to file \"/etc/exports\"."
553        return 0
554}
555
556
557# ejemplos:
558#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0:ro,no_subtree_check,no_root_squash,sync
559#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0
560#nfsAddExport /opt/opengnsys 80.20.2.1:ro 192.123.32.2:rw
561function nfsAddExport()
562{
563        if [ $# -lt 2 ]; then
564                errorAndLog "${FUNCNAME}(): invalid number of parameters"
565                exit 1
566        fi
567
568        if [ ! -f /etc/exports ]; then
569                errorAndLog "${FUNCNAME}(): /etc/exports don't exists"
570                return 1
571        fi
572
573        local export="${1}"
574        local contador=0
575        local cadenaexport
576
577        grep "^${export}" /etc/exports > /dev/null
578        if [ $? -eq 0 ]; then
579                echoAndLog "${FUNCNAME}(): $export exists in /etc/exports, omiting"
580                return 0
581        fi
582
583        cadenaexport="${export}"
584        for parametro in $*
585        do
586                if [ $contador -gt 0 ]
587                then
588                        host=`echo $parametro | awk -F: '{print $1}'`
589                        options=`echo $parametro | awk -F: '{print $2}'`
590                        if [ "${host}" == "" ]; then
591                                errorAndLog "${FUNCNAME}(): host can't be empty"
592                                return 1
593                        fi
594                        cadenaexport="${cadenaexport}\t${host}"
595
596                        if [ "${options}" != "" ]; then
597                                cadenaexport="${cadenaexport}(${options})"
598                        fi
599                fi
600                let contador=contador+1
601        done
602
603        echo -en "$cadenaexport\n" >> /etc/exports
604
605        echoAndLog "${FUNCNAME}(): add $export to /etc/exports"
606
607        return 0
608}
609
610########################################################################
611## Configuracion servicio DHCP
612########################################################################
613
614function dhcpConfigure()
615{
616        echoAndLog "${FUNCNAME}(): Sample DHCP Configuration."
617
618        backupFile /etc/dhcp3/dhcpd.conf
619
620        sed -e "s/SERVERIP/$SERVERIP/g" \
621            -e "s/NETIP/$NETIP/g" \
622            -e "s/NETMASK/$NETMASK/g" \
623            -e "s/NETBROAD/$NETBROAD/g" \
624            -e "s/ROUTERIP/$ROUTERIP/g" \
625            -e "s/DNSIP/$DNSIP/g" \
626            $WORKDIR/opengnsys/server/DHCP/dhcpd.conf > /etc/dhcp3/dhcpd.conf
627        if [ $? -ne 0 ]; then
628                errorAndLog "${FUNCNAME}(): error while configuring dhcp server"
629                return 1
630        fi
631
632        /etc/init.d/dhcp3-server restart
633        echoAndLog "${FUNCNAME}(): Sample DHCP Configured in file \"/etc/dhcp3/dhcpd.conf\"."
634        return 0
635}
636
637
638#####################################################################
639####### Funciones específicas de la instalación de Opengnsys
640#####################################################################
641
642# Copiar ficheros del OpenGnSys Web Console.
643function installWebFiles()
644{
645        echoAndLog "${FUNCNAME}(): Installing web files..."
646        cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www   #*/ comentario para doxigen
647        if [ $? != 0 ]; then
648                errorAndLog "${FUNCNAME}(): Error copying web files."
649                exit 1
650        fi
651        find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null
652        # Cambiar permisos para ficheros especiales.
653        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP \
654                        $INSTALL_TARGET/www/includes \
655                        $INSTALL_TARGET/www/comandos/gestores/filescripts \
656                        $INSTALL_TARGET/www/images/iconos
657        echoAndLog "${FUNCNAME}(): Web files installed successfully."
658}
659
660# Configuración específica de Apache.
661function openGnsysInstallWebConsoleApacheConf()
662{
663        if [ $# -ne 2 ]; then
664                errorAndLog "${FUNCNAME}(): invalid number of parameters"
665                exit 1
666        fi
667
668        local path_opengnsys_base=$1
669        local path_apache2_confd=$2
670        local path_web_console=${path_opengnsys_base}/www
671
672        if [ ! -d $path_apache2_confd ]; then
673                errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation"
674                return 1
675        fi
676
677        mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
678
679        echoAndLog "${FUNCNAME}(): creating apache2 config file.."
680
681
682        # genera configuración
683        cat > $path_opengnsys_base/etc/apache.conf <<EOF
684# OpenGnSys Web Console configuration for Apache
685
686Alias /opengnsys ${path_web_console}
687
688<Directory ${path_web_console}>
689        Options -Indexes FollowSymLinks
690        DirectoryIndex acceso.php
691</Directory>
692EOF
693
694        ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys.conf
695        ln -fs $path_apache2_confd/sites-available/opengnsys.conf $path_apache2_confd/sites-enabled/opengnsys.conf
696        if [ $? -ne 0 ]; then
697                errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation"
698                return 1
699        else
700                echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon"
701                /etc/init.d/apache2 restart
702                return 0
703        fi
704}
705
706# Crear documentación Doxygen para la consola web.
707function makeDoxygenFiles()
708{
709        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
710        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
711                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
712        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
713                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
714                return 1
715        fi
716        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
717        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
718        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
719}
720
721
722# Crea la estructura base de la instalación de opengnsys
723function openGnsysInstallCreateDirs()
724{
725        if [ $# -ne 1 ]; then
726                errorAndLog "${FUNCNAME}(): invalid number of parameters"
727                exit 1
728        fi
729
730        local path_opengnsys_base=$1
731
732        echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base"
733
734        mkdir -p $path_opengnsys_base
735        mkdir -p $path_opengnsys_base/admin/{autoexec,comandos,menus,usuarios}
736        mkdir -p $path_opengnsys_base/bin
737        mkdir -p $path_opengnsys_base/client
738        mkdir -p $path_opengnsys_base/doc
739        mkdir -p $path_opengnsys_base/etc
740        mkdir -p $path_opengnsys_base/lib
741        mkdir -p $path_opengnsys_base/log/clients
742        mkdir -p $path_opengnsys_base/sbin
743        mkdir -p $path_opengnsys_base/www
744        mkdir -p $path_opengnsys_base/images
745        ln -fs /var/lib/tftpboot $path_opengnsys_base
746        ln -fs $path_opengnsys_base/log /var/log/opengnsys
747
748        if [ $? -ne 0 ]; then
749                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
750                return 1
751        fi
752
753        echoAndLog "${FUNCNAME}(): directory paths created"
754        return 0
755}
756
757# Copia ficheros de configuración y ejecutables genéricos del servidor.
758function openGnsysCopyServerFiles () {
759        if [ $# -ne 1 ]; then
760                errorAndLog "${FUNCNAME}(): invalid number of parameters"
761                exit 1
762        fi
763
764        local path_opengnsys_base=$1
765
766        local SOURCES=( client/boot/initrd-generator \
767                        client/boot/upgrade-clients-udeb.sh \
768                        client/boot/udeblist.conf  \
769                        client/boot/udeblist-jaunty.conf  \
770                        client/boot/udeblist-karmic.conf \
771                        client/boot/udeblist-lucid.conf \
772                        server/PXE/pxelinux.cfg/default \
773                        doc )
774        local TARGETS=( bin/initrd-generator \
775                        bin/upgrade-clients-udeb.sh \
776                        etc/udeblist.conf \
777                        etc/udeblist-jaunty.conf  \
778                        etc/udeblist-karmic.conf \
779                        etc/udeblist-lucid.conf \
780                        tftpboot/pxelinux.cfg/default \
781                        doc )
782
783        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
784                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
785                exit 1
786        fi
787
788        echoAndLog "${FUNCNAME}(): copying files to server directories"
789
790        pushd $WORKDIR/opengnsys
791        local i
792        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
793                if [ -f "${SOURCES[$i]}" ]; then
794                        echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
795                        cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
796                elif [ -d "${SOURCES[$i]}" ]; then
797                        echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
798                        cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}"
799        else
800                        echoAndLog "Warning: Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
801                fi
802        done
803        popd
804}
805
806####################################################################
807### Funciones de compilación de códifo fuente de servicios
808####################################################################
809
810# Compilar los servicios de OpenGNsys
811function servicesCompilation ()
812{
813        local hayErrores=0
814
815        # Compilar OpenGnSys Server
816        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server"
817        pushd $WORKDIR/opengnsys/admin/Services/ogAdmServer
818        make && make install
819        if [ $? -ne 0 ]; then
820                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
821                hayErrores=1
822        fi
823        popd
824        # Compilar OpenGnSys Repository Manager
825        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager"
826        pushd $WORKDIR/opengnsys/admin/Services/ogAdmRepo
827        make && make install
828        if [ $? -ne 0 ]; then
829                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
830                hayErrores=1
831        fi
832        popd
833        # Compilar OpenGnSys Client
834        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client"
835        pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
836        make && mv ogAdmClient ../../../client/nfsexport/bin
837        if [ $? -ne 0 ]; then
838                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client"
839                hayErrores=1
840        fi
841        popd
842
843        return $hayErrores
844}
845
846
847####################################################################
848### Funciones instalacion cliente opengnsys
849####################################################################
850
851function openGnsysClientCreate()
852{
853        local OSDISTRIB OSCODENAME
854
855        local hayErrores=0
856
857        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
858        cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
859        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
860        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
861        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
862        cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
863        if [ $? -ne 0 ]; then
864                errorAndLog "${FUNCNAME}(): error while copying engine files"
865                hayErrores=1
866        fi
867
868        # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
869        OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
870        OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
871        if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
872                echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
873                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
874                if [ $? -ne 0 ]; then
875                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
876                        hayErrores=1
877                fi
878                echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
879                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
880                if [ $? -ne 0 ]; then
881                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
882                        hayErrores=1
883                fi
884        else
885                echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
886                $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
887                if [ $? -ne 0 ]; then
888                        errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
889                        hayErrores=1
890                fi
891                echoAndLog "${FUNCNAME}(): Loading default udeb files."
892                $INSTALL_TARGET/bin/upgrade-clients-udeb.sh
893                if [ $? -ne 0 ]; then
894                        errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
895                        hayErrores=1
896                fi
897        fi
898
899        if [ $hayErrores -eq 0 ]; then
900                echoAndLog "${FUNCNAME}(): Client generation success."
901        else
902                errorAndLog "${FUNCNAME}(): Client generation with errors"
903        fi
904
905        return $hayErrores
906}
907
908
909# Configuración básica de servicios de OpenGnSys
910function openGnsysConfigure()
911{
912        echoAndLog "openGnsysConfigure(): Copying init files."
913        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
914        cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.default /etc/default/opengnsys
915        update-rc.d opengnsys defaults
916        echoAndLog "openGnsysConfigure(): Creating OpenGnSys config file in \"$INSTALL_TARGET/etc\"."
917        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmServer.cfg
918        perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg
919        echoAndLog "${FUNCNAME}(): Creating Web Console config file"
920        OPENGNSYS_CONSOLEURL="http://$SERVERIP/opengnsys"
921        perl -pi -e "s/SERVERIP/$SERVERIP/g; s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" $INSTALL_TARGET/www/controlacceso.php
922        sed -e "s/SERVERIP/$SERVERIP/g" -e "s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" $WORKDIR/opengnsys/admin/Services/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg
923        echoAndLog "openGnsysConfiguration(): Starting OpenGnSys services."
924        /etc/init.d/opengnsys start
925}
926
927
928#####################################################################
929#######  Función de resumen informativo de la instalación
930#####################################################################
931
932function installationSummary(){
933        echo
934        echoAndLog "OpenGnSys Installation Summary"
935        echo       "=============================="
936        echoAndLog "Project version:                  $(cat $INSTALL_TARGET/doc/VERSION.txt 2>/dev/null)"
937        echoAndLog "Installation directory:           $INSTALL_TARGET"
938        echoAndLog "Repository directory:             $INSTALL_TARGET/images"
939        echoAndLog "TFTP configuracion directory:     /var/lib/tftpboot"
940        echoAndLog "DHCP configuracion file:          /etc/dhcp3/dhcpd.conf"
941        echoAndLog "NFS configuracion file:           /etc/exports"
942        echoAndLog "Web Console URL:                  $OPENGNSYS_CONSOLEURL"
943        echoAndLog "Web Console admin user:           $OPENGNSYS_DB_USER"
944        echoAndLog "Web Console admin password:       $OPENGNSYS_DB_PASSWD"
945        echoAndLog "Web Console default user:         $OPENGNSYS_DB_DEFAULTUSER"
946        echoAndLog "Web Console default password:     $OPENGNSYS_DB_DEFAULTPASSWD"
947        echo
948        echoAndLog "Post-Installation Instructions:"
949        echo       "==============================="
950        echoAndLog "Review or edit all configuration files."
951        echoAndLog "Insert DHCP configuration data and restart service."
952        echoAndLog "Log-in as Web Console admin user."
953        echoAndLog " - Review default Organization data and default user."
954        echoAndLog "Log-in as Web Console organization user."
955        echoAndLog " - Insert OpenGnSys data (rooms, computers, etc)."
956echo
957}
958
Note: See TracBrowser for help on using the repository browser.