source: installer/opengnsys_installer.sh @ 35f55cb

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 35f55cb was 7669bca, checked in by ramon <ramongomez@…>, 12 years ago

Versión 1.0.5, #562. Instalador y actualizador protegen su fichero de log, porque puede contener información sensible.

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

  • Property mode set to 100755
File size: 50.9 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.
11####  WARNING: Edit default access configuration.
12MYSQL_ROOT_PASSWORD="passwordroot"      # Clave root de MySQL
13OPENGNSYS_DB_USER="usuog"               # Usuario de acceso a la base de datos
14OPENGNSYS_DB_PASSWD="passusuog"         # Clave de acceso a la base de datos
15OPENGNSYS_CLIENT_PASSWD="og"            # Clave de acceso del cliente
16
17
18####  AVISO: NO EDITAR.
19####  WARNING: DO NOT EDIT.
20OPENGNSYS_DATABASE="ogAdmBD"            # Nombre de la base datos
21OPENGNSYS_CLIENT_USER="opengnsys"       # Usuario del cliente para acceso remoto
22
23
24
25# Sólo ejecutable por usuario root
26if [ "$(whoami)" != 'root' ]; then
27        echo "ERROR: this program must run under root privileges!!"
28        exit 1
29fi
30# Solo se deben aceptar números y letras en la clave de acceso del cliente.
31if [ -n "${OPENGNSYS_CLIENT_PASSWD//[a-zA-Z0-9]/}" ]; then
32        echo "ERROR: client password must be alphanumeric, edit installer variables."
33        exit 1
34fi
35
36# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1).
37PROGRAMDIR=$(readlink -e $(dirname "$0"))
38OPENGNSYS_SERVER="www.opengnsys.es"
39if [ -d "$PROGRAMDIR/../installer" ]; then
40        USESVN=0
41else
42        USESVN=1
43fi
44SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/"
45
46WORKDIR=/tmp/opengnsys_installer
47mkdir -p $WORKDIR
48
49INSTALL_TARGET=/opt/opengnsys
50OGLOGFILE=$INSTALL_TARGET/log/opengnsys_installation.log
51LOG_FILE=/tmp/$(basename $OGLOGFILE)
52
53# Base de datos
54OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogAdmBD.sql
55
56
57#####################################################################
58####### Funciones de configuración
59#####################################################################
60
61# Generar variables de configuración del instalador
62# Variables globales:
63# - OSDISTRIB, OSCODENAME - datos de la distribución Linux
64# - DEPENDENCIES - array de dependencias que deben estar instaladas
65# - UPDATEPKGLIST, INSTALLPKGS, CHECKPKGS - comandos para gestión de paquetes
66# - INSTALLEXTRADEPS - instalar dependencias no incluidas en la distribución
67# - STARTSERVICE, ENABLESERVICE - iniciar y habilitar un servicio
68# - STOPSERVICE, DISABLESERVICE - parar y deshabilitar un servicio
69# - APACHESERV, APACHECFGDIR, APACHESITESDIR, APACHEUSER, APACHEGROUP - servicio y configuración de Apache
70# - APACHESSLMOD, APACHEENABLESSL, APACHEMAKECERT - habilitar módulo Apache y certificado SSL
71# - APACHEENABLEOG, APACHEOGSITE, - habilitar sitio web de OpenGnSys
72# - INETDSERV - servicio Inetd
73# - IPTABLESSERV - servicio IPTables
74# - DHCPSERV, DHCPCFGDIR - servicio y configuración de DHCP
75# - MYSQLSERV - servicio MySQL
76# - RSYNCSERV, RSYNCCFGDIR - servicio y configuración de Rsync
77# - SAMBASERV, SAMBACFGDIR - servicio y configuración de Samba
78# - TFTPSERV, TFTPCFGDIR, SYSLINUXDIR - servicio y configuración de TFTP/PXE
79function autoConfigure()
80{
81# Detectar sistema operativo del servidor (debe soportar LSB).
82OSDISTRIB=$(lsb_release -is 2>/dev/null)
83OSCODENAME=$(lsb_release -cs 2>/dev/null)
84
85# Configuración según la distribución de Linux.
86case "$OSDISTRIB" in
87        Ubuntu|Debian|LinuxMint)
88                DEPENDENCIES=( subversion apache2 php5 php5-ldap libapache2-mod-php5 mysql-server php5-mysql isc-dhcp-server bittorrent tftp-hpa tftpd-hpa syslinux xinetd build-essential g++-multilib libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent samba rsync unzip netpipes debootstrap schroot squashfs-tools )
89                UPDATEPKGLIST="apt-get update"
90                INSTALLPKG="apt-get -y install --force-yes"
91                CHECKPKG="dpkg -s \$package 2>/dev/null | grep Status | grep -qw install"
92                if which service &>/dev/null; then
93                        STARTSERVICE="eval service \$service restart"
94                        STOPSERVICE="eval service \$service stop"
95                else
96                        STARTSERVICE="eval /etc/init.d/\$service restart"
97                        STOPSERVICE="eval /etc/init.d/\$service stop"
98                fi
99                ENABLESERVICE="eval update-rc.d \$service defaults"
100                DISABLESERVICE="eval update-rc.d \$service disable"
101                APACHESERV=apache2
102                APACHECFGDIR=/etc/apache2
103                APACHESITESDIR=sites-available
104                APACHEOGSITE=opengnsys
105                APACHEUSER="www-data"
106                APACHEGROUP="www-data"
107                APACHESSLMOD="a2enmod ssl"
108                APACHEENABLESSL="a2ensite default-ssl"
109                APACHEENABLEOG="a2ensite $APACHEOGSITE"
110                APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite"
111                DHCPSERV=isc-dhcp-server
112                DHCPCFGDIR=/etc/dhcp
113                INETDSERV=xinetd
114                INETDCFGDIR=/etc/xinetd.d
115                MYSQLSERV=mysql
116                RSYNCSERV=rsync
117                RSYNCCFGDIR=/etc
118                SAMBASERV=smbd
119                SAMBACFGDIR=/etc/samba
120                SYSLINUXDIR=/usr/lib/syslinux
121                TFTPCFGDIR=/var/lib/tftpboot
122                ;;
123        Fedora|CentOS)
124                DEPENDENCIES=( subversion httpd mod_ssl php php-ldap mysql-server mysql-devel mysql-devel.i686 php-mysql dhcp tftp-server tftp syslinux xinetd binutils gcc gcc-c++ glibc-devel glibc-devel.i686 glibc-static glibc-static.i686 libstdc++ libstdc++.i686 libstdc++-static.i686 libstdc++-devel.i686 make wget doxygen graphviz ctorrent samba rsync unzip debootstrap schroot squashfs-tools )
125                INSTALLEXTRADEPS=( 'rpm -Uv ftp://ftp.altlinux.org/pub/distributions/ALTLinux/5.1/branch/files/i586/RPMS/netpipes-4.2-alt1.i586.rpm'
126                                   'pushd /tmp; wget http://download.bittornado.com/download/BitTornado-0.3.18.tar.gz; tar xvzf BitTornado-0.3.18.tar.gz; cd BitTornado-CVS; python setup.py install; ln -fs btlaunchmany.py /usr/bin/btlaunchmany; ln -fs bttrack.py /usr/bin/bttrack; popd' )
127                if [ "$OSDISTRIB" == "CentOS" ]; then
128                        UPDATEPKGLIST='test rpm -q --quiet epel-release || echo -e "[epel]\nname=EPEL temporal\nmirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-\$releasever&arch=\$basearch\nenabled=1\ngpgcheck=0" >/etc/yum.repos.d/epel.repo'
129                fi
130                INSTALLPKG="yum install -y"
131                CHECKPKG="rpm -q --quiet \$package"
132                SYSTEMD=$(which systemctl 2>/dev/null)
133                if [ -n "$SYSTEMD" ]; then
134                        STARTSERVICE="eval systemctl start \$service.service"
135                        STOPSERVICE="eval systemctl stop \$service.service"
136                        ENABLESERVICE="eval systemctl enable \$service.service"
137                        DISABLESERVICE="eval systemctl disable \$service.service"
138                else
139                        STARTSERVICE="eval service \$service start"
140                        STOPSERVICE="eval service \$service stop"
141                        ENABLESERVICE="eval chkconfig \$service on"
142                        DISABLESERVICE="eval chkconfig \$service off"
143                fi
144                APACHESERV=httpd
145                APACHECFGDIR=/etc/httpd/conf.d
146                APACHEOGSITE=opengnsys.conf
147                APACHEUSER="apache"
148                APACHEGROUP="apache"
149                DHCPSERV=dhcpd
150                DHCPCFGDIR=/etc/dhcp
151                INETDSERV=xinetd
152                INETDCFGDIR=/etc/xinetd.d
153                IPTABLESSERV=iptables
154                MYSQLSERV=mysqld
155                RSYNCSERV=rsync
156                RSYNCCFGDIR=/etc
157                SAMBASERV=smb
158                SAMBACFGDIR=/etc/samba
159                SYSLINUXDIR=/usr/share/syslinux
160                TFTPSERV=tftp
161                TFTPCFGDIR=/var/lib/tftpboot
162                ;;
163        "")     echo "ERROR: Unknown Linux distribution, please install \"lsb_release\" command."
164                exit 1 ;;
165        *)      echo "ERROR: Distribution not supported by OpenGnSys."
166                exit 1 ;;
167esac
168}
169
170# Modificar variables de configuración tras instalar paquetes del sistema.
171function autoConfigurePost()
172{
173[ -z "$SYSTEMD" -a ! -e /etc/init.d/$SAMBASERV ] && SAMBASERV=samba     # Debian 6
174[ ! -e $TFTPCFGDIR ] && TFTPCFGDIR=/srv/tftp            # Debian 6
175[ -f /selinux/enforce ] && echo 0 > /selinux/enforce    # SELinux permisivo
176selinuxenabled && setenforce 0 2>/dev/null              # SELinux permisivo (Fedora 17)
177}
178
179
180# Cargar lista de paquetes del sistema y actualizar algunas variables de configuración
181# dependiendo de la versión instalada.
182function updatePackageList()
183{
184local DHCPVERSION
185
186# Si es necesario, actualizar la lista de paquetes disponibles.
187[ -n "$UPDATEPKGLIST" ] && eval $UPDATEPKGLIST
188
189# Configuración personallizada de algunos paquetes.
190case "$OSDISTRIB" in
191        Ubuntu|LinuxMint)       # Postconfiguación personalizada para Ubuntu.
192                # Configuración para DHCP v3.
193                DHCPVERSION=$(apt-cache show $(apt-cache pkgnames|egrep "dhcp.?-server$") | \
194                              awk '/Version/ {print substr($2,1,1);}' | \
195                              sort -n | tail -1)
196                if [ $DHCPVERSION = 3 ]; then
197                        DEPENDENCIES=( ${DEPENDENCIES[@]/isc-dhcp-server/dhcp3-server} )
198                        DHCPSERV=dhcp3-server
199                        DHCPCFGDIR=/etc/dhcp3
200                fi
201                ;;
202        CentOS) # Postconfiguación personalizada para CentOS.
203                # Incluir repositorio de paquetes EPEL.
204                DEPENDENCIES=( ${DEPENDENCIES[@]} epel-release )
205                ;;
206esac
207}
208
209
210#####################################################################
211####### Algunas funciones útiles de propósito general:
212#####################################################################
213
214function getDateTime()
215{
216        date "+%Y%m%d-%H%M%S"
217}
218
219# Escribe a fichero y muestra por pantalla
220function echoAndLog()
221{
222        local DATETIME=`getDateTime`
223        echo "$1"
224        echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
225}
226
227# Escribe a fichero y muestra mensaje de error
228function errorAndLog()
229{
230        local DATETIME=`getDateTime`
231        echo "ERROR: $1"
232        echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
233}
234
235# Comprueba si el elemento pasado en $2 está en el array $1
236function isInArray()
237{
238        if [ $# -ne 2 ]; then
239                errorAndLog "${FUNCNAME}(): invalid number of parameters"
240                exit 1
241        fi
242
243        local deps
244        local is_in_array=1
245        local element="$2"
246
247        echoAndLog "${FUNCNAME}(): checking if $2 is in $1"
248        eval "deps=( \"\${$1[@]}\" )"
249
250        # Copia local del array del parámetro 1.
251        for (( i = 0 ; i < ${#deps[@]} ; i++ )); do
252                if [ "${deps[$i]}" = "${element}" ]; then
253                        echoAndLog "isInArray(): $element found in array"
254                        is_in_array=0
255                fi
256        done
257
258        if [ $is_in_array -ne 0 ]; then
259                echoAndLog "${FUNCNAME}(): $element NOT found in array"
260        fi
261
262        return $is_in_array
263}
264
265
266#####################################################################
267####### Funciones de manejo de paquetes Debian
268#####################################################################
269
270function checkPackage()
271{
272        package=$1
273        if [ -z $package ]; then
274                errorAndLog "${FUNCNAME}(): parameter required"
275                exit 1
276        fi
277        echoAndLog "${FUNCNAME}(): checking if package $package exists"
278        eval $CHECKPKG
279        if [ $? -eq 0 ]; then
280                echoAndLog "${FUNCNAME}(): package $package exists"
281                return 0
282        else
283                echoAndLog "${FUNCNAME}(): package $package doesn't exists"
284                return 1
285        fi
286}
287
288# Recibe array con dependencias
289# por referencia deja un array con las dependencias no resueltas
290# devuelve 1 si hay alguna dependencia no resuelta
291function checkDependencies()
292{
293        if [ $# -ne 2 ]; then
294                errorAndLog "${FUNCNAME}(): invalid number of parameters"
295                exit 1
296        fi
297
298        echoAndLog "${FUNCNAME}(): checking dependences"
299        uncompletedeps=0
300
301        # copia local del array del parametro 1
302        local deps
303        eval "deps=( \"\${$1[@]}\" )"
304
305        declare -a local_notinstalled
306
307        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
308        do
309                checkPackage ${deps[$i]}
310                if [ $? -ne 0 ]; then
311                        local_notinstalled[$uncompletedeps]=$package
312                        let uncompletedeps=uncompletedeps+1
313                fi
314        done
315
316        # relleno el array especificado en $2 por referencia
317        for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ ))
318        do
319                eval "${2}[$i]=${local_notinstalled[$i]}"
320        done
321
322        # retorna el numero de paquetes no resueltos
323        echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps"
324        return $uncompletedeps
325}
326
327# Recibe un array con las dependencias y lo instala
328function installDependencies()
329{
330        if [ $# -ne 1 ]; then
331                errorAndLog "${FUNCNAME}(): invalid number of parameters"
332                exit 1
333        fi
334        echoAndLog "${FUNCNAME}(): installing uncompleted dependencies"
335
336        # copia local del array del parametro 1
337        local deps
338        eval "deps=( \"\${$1[@]}\" )"
339
340        local string_deps=""
341        for (( i = 0 ; i < ${#deps[@]} ; i++ ))
342        do
343                string_deps="$string_deps ${deps[$i]}"
344        done
345
346        if [ -z "${string_deps}" ]; then
347                errorAndLog "${FUNCNAME}(): array of dependeces is empty"
348                exit 1
349        fi
350
351        OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND            # Debian/Ubuntu
352        export DEBIAN_FRONTEND=noninteractive
353
354        echoAndLog "${FUNCNAME}(): now $string_deps will be installed"
355        eval $INSTALLPKG $string_deps
356        if [ $? -ne 0 ]; then
357                errorAndLog "${FUNCNAME}(): error installing dependencies"
358                return 1
359        fi
360
361        DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND            # Debian/Ubuntu
362        test grep -q "EPEL temporal" /etc/yum.repos.d/epel.repo 2>/dev/null ] || mv -f /etc/yum.repos.d/epel.repo.rpmnew /etc/yum.repos.d/epel.repo 2>/dev/null # CentOS/RedHat EPEL
363
364        echoAndLog "${FUNCNAME}(): dependencies installed"
365}
366
367# Hace un backup del fichero pasado por parámetro
368# deja un -last y uno para el día
369function backupFile()
370{
371        if [ $# -ne 1 ]; then
372                errorAndLog "${FUNCNAME}(): invalid number of parameters"
373                exit 1
374        fi
375
376        local file="$1"
377        local dateymd=`date +%Y%m%d`
378
379        if [ ! -f "$file" ]; then
380                errorAndLog "${FUNCNAME}(): file $file doesn't exists"
381                return 1
382        fi
383
384        echoAndLog "${FUNCNAME}(): making $file backup"
385
386        # realiza una copia de la última configuración como last
387        cp -a "$file" "${file}-LAST"
388
389        # si para el día no hay backup lo hace, sino no
390        if [ ! -f "${file}-${dateymd}" ]; then
391                cp -a "$file" "${file}-${dateymd}"
392        fi
393
394        echoAndLog "${FUNCNAME}(): $file backup success"
395}
396
397#####################################################################
398####### Funciones para el manejo de bases de datos
399#####################################################################
400
401# This function set password to root
402function mysqlSetRootPassword()
403{
404        if [ $# -ne 1 ]; then
405                errorAndLog "${FUNCNAME}(): invalid number of parameters"
406                exit 1
407        fi
408
409        local root_mysql="$1"
410        echoAndLog "${FUNCNAME}(): setting root password in MySQL server"
411        mysqladmin -u root password "$root_mysql"
412        if [ $? -ne 0 ]; then
413                errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server"
414                return 1
415        fi
416        echoAndLog "${FUNCNAME}(): root password saved!"
417        return 0
418}
419
420# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
421function mysqlGetRootPassword()
422{
423        local pass_mysql
424        local pass_mysql2
425        # Comprobar si MySQL está instalado con la clave de root por defecto.
426        if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then
427                echoAndLog "${FUNCNAME}(): Using default mysql root password."
428        else
429                stty -echo
430                echo "There is a MySQL service already installed."
431                read -p "Enter MySQL root password: " pass_mysql
432                echo ""
433                read -p "Confrim password:" pass_mysql2
434                echo ""
435                stty echo
436                if [ "$pass_mysql" == "$pass_mysql2" ] ;then
437                        MYSQL_ROOT_PASSWORD="$pass_mysql"
438                        return 0
439                else
440                        echo "The keys don't match. Do not configure the server's key,"
441                        echo "transactions in the database will give error."
442                        return 1
443                fi
444        fi
445}
446
447# comprueba si puede conectar con mysql con el usuario root
448function mysqlTestConnection()
449{
450        if [ $# -ne 1 ]; then
451                errorAndLog "${FUNCNAME}(): invalid number of parameters"
452                exit 1
453        fi
454
455        local root_password="${1}"
456        echoAndLog "${FUNCNAME}(): checking connection to mysql..."
457        echo "" | mysql -uroot -p"${root_password}"
458        if [ $? -ne 0 ]; then
459                errorAndLog "${FUNCNAME}(): connection to mysql failed, check root password and if daemon is running!"
460                return 1
461        else
462                echoAndLog "${FUNCNAME}(): connection success"
463                return 0
464        fi
465}
466
467# comprueba si la base de datos existe
468function mysqlDbExists()
469{
470        if [ $# -ne 2 ]; then
471                errorAndLog "${FUNCNAME}(): invalid number of parameters"
472                exit 1
473        fi
474
475        local root_password="${1}"
476        local database=$2
477        echoAndLog "${FUNCNAME}(): checking if $database exists..."
478        echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$"
479        if [ $? -ne 0 ]; then
480                echoAndLog "${FUNCNAME}():database $database doesn't exists"
481                return 1
482        else
483                echoAndLog "${FUNCNAME}():database $database exists"
484                return 0
485        fi
486}
487
488function mysqlCheckDbIsEmpty()
489{
490        if [ $# -ne 2 ]; then
491                errorAndLog "${FUNCNAME}(): invalid number of parameters"
492                exit 1
493        fi
494
495        local root_password="${1}"
496        local database=$2
497        echoAndLog "${FUNCNAME}(): checking if $database is empty..."
498        num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l`
499        if [ $? -ne 0 ]; then
500                errorAndLog "${FUNCNAME}(): error executing query, check database and root password"
501                exit 1
502        fi
503
504        if [ $num_tablas -eq 0 ]; then
505                echoAndLog "${FUNCNAME}():database $database is empty"
506                return 0
507        else
508                echoAndLog "${FUNCNAME}():database $database has tables"
509                return 1
510        fi
511
512}
513
514
515function mysqlImportSqlFileToDb()
516{
517        if [ $# -ne 3 ]; then
518                errorAndLog "${FNCNAME}(): invalid number of parameters"
519                exit 1
520        fi
521
522        local root_password="$1"
523        local database="$2"
524        local sqlfile="$3"
525        local tmpfile=$(mktemp)
526        local i=0
527        local dev=""
528        local status
529
530        if [ ! -f $sqlfile ]; then
531                errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!"
532                return 1
533        fi
534
535        echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
536        chmod 600 $tmpfile
537        for dev in ${DEVICE[*]}; do
538                if [ "${DEVICE[i]}" == "$DEFAULTDEV" ]; then
539                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
540                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
541                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
542                                $sqlfile > $tmpfile
543                fi
544                let i++
545        done
546        mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $tmpfile
547        status=$?
548        rm -f $tmpfile
549        if [ $status -ne 0 ]; then
550                errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database"
551                return 1
552        fi
553        echoAndLog "${FUNCNAME}(): file imported to database $database"
554        return 0
555}
556
557# Crea la base de datos
558function mysqlCreateDb()
559{
560        if [ $# -ne 2 ]; then
561                errorAndLog "${FUNCNAME}(): invalid number of parameters"
562                exit 1
563        fi
564
565        local root_password="${1}"
566        local database=$2
567
568        echoAndLog "${FUNCNAME}(): creating database..."
569        mysqladmin -u root --password="${root_password}" create $database
570        if [ $? -ne 0 ]; then
571                errorAndLog "${FUNCNAME}(): error while creating database $database"
572                return 1
573        fi
574        echoAndLog "${FUNCNAME}(): database $database created"
575        return 0
576}
577
578
579function mysqlCheckUserExists()
580{
581        if [ $# -ne 2 ]; then
582                errorAndLog "${FUNCNAME}(): invalid number of parameters"
583                exit 1
584        fi
585
586        local root_password="${1}"
587        local userdb=$2
588
589        echoAndLog "${FUNCNAME}(): checking if $userdb exists..."
590        echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user
591        if [ $? -ne 0 ]; then
592                echoAndLog "${FUNCNAME}(): user doesn't exists"
593                return 1
594        else
595                echoAndLog "${FUNCNAME}(): user already exists"
596                return 0
597        fi
598
599}
600
601# Crea un usuario administrativo para la base de datos
602function mysqlCreateAdminUserToDb()
603{
604        if [ $# -ne 4 ]; then
605                errorAndLog "${FUNCNAME}(): invalid number of parameters"
606                exit 1
607        fi
608
609        local root_password=$1
610        local database=$2
611        local userdb=$3
612        local passdb=$4
613
614        echoAndLog "${FUNCNAME}(): creating admin user ${userdb} to database ${database}"
615
616        cat > $WORKDIR/create_${database}.sql <<EOF
617GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
618GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
619FLUSH PRIVILEGES ;
620EOF
621        mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql
622        if [ $? -ne 0 ]; then
623                errorAndLog "${FUNCNAME}(): error while creating user in mysql"
624                rm -f $WORKDIR/create_${database}.sql
625                return 1
626        else
627                echoAndLog "${FUNCNAME}(): user created ok"
628                rm -f $WORKDIR/create_${database}.sql
629                return 0
630        fi
631}
632
633
634#####################################################################
635####### Funciones para el manejo de Subversion
636#####################################################################
637
638function svnExportCode()
639{
640        if [ $# -ne 1 ]; then
641                errorAndLog "${FUNCNAME}(): invalid number of parameters"
642                exit 1
643        fi
644
645        local url="$1"
646
647        echoAndLog "${FUNCNAME}(): downloading subversion code..."
648
649        svn export --force "$url" opengnsys
650        if [ $? -ne 0 ]; then
651                errorAndLog "${FUNCNAME}(): error getting OpenGnSys code from $url"
652                return 1
653        fi
654        echoAndLog "${FUNCNAME}(): subversion code downloaded"
655        return 0
656}
657
658
659############################################################
660###  Detectar red
661############################################################
662
663# Comprobar si existe conexión.
664function checkNetworkConnection()
665{
666        echoAndLog "${FUNCNAME}(): Disabling IPTables."
667        if [ -n "$IPTABLESSERV" ]; then
668                service=$IPTABLESSERV
669                $STOPSERVICE; $DISABLESERVICE
670        fi
671
672        echoAndLog "${FUNCNAME}(): Checking OpenGnSys server conectivity."
673        OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"}
674        wget --spider -q $OPENGNSYS_SERVER
675}
676
677# Obtener los parámetros de red de la interfaz por defecto.
678function getNetworkSettings()
679{
680        # Arrays globales definidas:
681        # - DEVICE:     nombres de dispositivos de red activos.
682        # - SERVERIP:   IPs locales del servidor.
683        # - NETIP:      IPs de redes.
684        # - NETMASK:    máscaras de red.
685        # - NETBROAD:   IPs de difusión de redes.
686        # - ROUTERIP:   IPs de routers.
687        # Otras variables globales:
688        # - DEFAULTDEV: dispositivo de red por defecto.
689        # - DNSIP:      IP del servidor DNS principal.
690
691        local i=0
692        local dev=""
693
694        echoAndLog "${FUNCNAME}(): Detecting network parameters."
695        DEVICE=( $(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}') )
696        if [ -z "$DEVICE" ]; then
697                errorAndLog "${FUNCNAME}(): Network devices not detected."
698                exit 1
699        fi
700        for dev in ${DEVICE[*]}; do
701                SERVERIP[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
702                if [ -n "${SERVERIP[i]}" ]; then
703                        NETMASK[i]=$(LANG=C ifconfig $dev | \
704                                                awk '/Mask/ {sub(/.*:/,"",$4); print $4}
705                                                     /netmask/ {print $4}')
706                        NETBROAD[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {print ($6)}')
707                        NETIP[i]=$(netstat -nr | awk -v d="$dev" '$1!~/0\.0\.0\.0/&&$8==d {if (n=="") n=$1} END {print n}')
708                        ROUTERIP[i]=$(netstat -nr | awk -v d="$dev" '$1~/0\.0\.0\.0/&&$8==d {print $2}')
709                        DEFAULTDEV=${DEFAULTDEV:-"$dev"}
710                fi
711                let i++
712        done
713        DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1)
714        if [ -z "${NETIP[*]}" -o -z "${NETMASK[*]}" ]; then
715                errorAndLog "${FUNCNAME}(): Network not detected."
716                exit 1
717        fi
718
719        # Variables de ejecución de Apache
720        # - APACHE_RUN_USER
721        # - APACHE_RUN_GROUP
722        if [ -f $APACHECFGDIR/envvars ]; then
723                source $APACHECFGDIR/envvars
724        fi
725        APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"}
726        APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"}
727
728        echoAndLog "${FUNCNAME}(): Default network device: $DEFAULTDEV."
729}
730
731
732############################################################
733### Esqueleto para el Servicio pxe y contenedor tftpboot ###
734############################################################
735
736function tftpConfigure()
737{
738        echoAndLog "${FUNCNAME}(): Configuring TFTP service."
739        # Habilitar TFTP y reiniciar Inetd.
740        if [ -n "$TFTPSERV" ]; then
741                service=$TFTPSERV
742                $ENABLESERVICE
743        fi
744        service=$INETDSERV
745        $ENABLESERVICE; $STARTSERVICE
746
747        # preparacion contenedor tftpboot
748        cp -a $SYSLINUXDIR $TFTPCFGDIR/syslinux
749        cp -a $SYSLINUXDIR/pxelinux.0 $TFTPCFGDIR
750        # prepamos el directorio de la configuracion de pxe
751        mkdir -p $TFTPCFGDIR/pxelinux.cfg
752        cat > $TFTPCFGDIR/pxelinux.cfg/default <<EOF
753DEFAULT syslinux/vesamenu.c32
754MENU TITLE Aplicacion GNSYS
755 
756LABEL 1
757MENU LABEL 1
758KERNEL syslinux/chain.c32
759APPEND hd0
760 
761PROMPT 0
762TIMEOUT 10
763EOF
764        # comprobamos el servicio tftp
765        sleep 1
766        testPxe
767}
768
769function testPxe ()
770{
771        echoAndLog "${FUNCNAME}(): Checking TFTP service... please wait."
772        pushd /tmp
773        tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echoAndLog "TFTP service is OK." || errorAndLog "TFTP service is down."
774        popd
775}
776
777
778########################################################################
779## Configuracion servicio NFS
780########################################################################
781
782# Configurar servicio NFS.
783# ADVERTENCIA: usa variables globales NETIP y NETMASK!
784function nfsConfigure()
785{
786        echoAndLog "${FUNCNAME}(): Config nfs server."
787        backupFile /etc/exports
788
789        nfsAddExport $INSTALL_TARGET/client ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync
790        if [ $? -ne 0 ]; then
791                errorAndLog "${FUNCNAME}(): error while adding NFS client config"
792                return 1
793        fi
794
795        nfsAddExport $INSTALL_TARGET/images ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync,crossmnt
796        if [ $? -ne 0 ]; then
797                errorAndLog "${FUNCNAME}(): error while adding NFS images config"
798                return 1
799        fi
800
801        nfsAddExport $INSTALL_TARGET/log/clients ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync
802        if [ $? -ne 0 ]; then
803                errorAndLog "${FUNCNAME}(): error while adding logging client config"
804                return 1
805        fi
806
807        nfsAddExport $INSTALL_TARGET/tftpboot ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync
808        if [ $? -ne 0 ]; then
809                errorAndLog "${FUNCNAME}(): error while adding second filesystem for the PXE ogclient"
810                return 1
811        fi
812
813        /etc/init.d/nfs-kernel-server restart
814        exportfs -va
815        if [ $? -ne 0 ]; then
816                errorAndLog "${FUNCNAME}(): error while configure exports"
817                return 1
818        fi
819
820        echoAndLog "${FUNCNAME}(): Added NFS configuration to file \"/etc/exports\"."
821        return 0
822}
823
824
825# Añadir entrada en fichero de configuración del servidor NFS.
826# Ejemplos:
827#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0:ro,no_subtree_check,no_root_squash,sync
828#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0
829#nfsAddExport /opt/opengnsys 80.20.2.1:ro 192.123.32.2:rw
830function nfsAddExport()
831{
832        if [ $# -lt 2 ]; then
833                errorAndLog "${FUNCNAME}(): invalid number of parameters"
834                exit 1
835        fi
836        if [ ! -f /etc/exports ]; then
837                errorAndLog "${FUNCNAME}(): /etc/exports don't exists"
838                return 1
839        fi
840
841        local export="$1"
842        local contador=0
843        local cadenaexport
844
845        grep "^$export" /etc/exports > /dev/null
846        if [ $? -eq 0 ]; then
847                echoAndLog "${FUNCNAME}(): $export exists in /etc/exports, omiting"
848                return 0
849        fi
850
851        cadenaexport="${export}"
852        for parametro in $*; do
853                if [ $contador -gt 0 ]; then
854                        host=`echo $parametro | awk -F: '{print $1}'`
855                        options=`echo $parametro | awk -F: '{print $2}'`
856                        if [ "${host}" == "" ]; then
857                                errorAndLog "${FUNCNAME}(): host can't be empty"
858                                return 1
859                        fi
860                        cadenaexport="${cadenaexport}\t${host}"
861
862                        if [ "${options}" != "" ]; then
863                                cadenaexport="${cadenaexport}(${options})"
864                        fi
865                fi
866                let contador=contador+1
867        done
868
869        echo -en "$cadenaexport\n" >> /etc/exports
870
871        echoAndLog "${FUNCNAME}(): add $export to /etc/exports"
872        return 0
873}
874
875
876########################################################################
877## Configuracion servicio Samba
878########################################################################
879
880# Configurar servicios Samba.
881function smbConfigure()
882{
883        echoAndLog "${FUNCNAME}(): Configuring Samba service."
884
885        backupFile $SAMBACFGDIR/smb.conf
886       
887        # Copiar plantailla de recursos para OpenGnSys
888        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
889                $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf
890        # Configurar y recargar Samba"
891        perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnSys Samba Server/" $SAMBACFGDIR/smb.conf
892        if ! grep -q "smb-og" $SAMBACFGDIR/smb.conf; then
893                echo "include = $SAMBACFGDIR/smb-og.conf" >> $SAMBACFGDIR/smb.conf
894        fi
895        service=$SAMBASERV
896        $ENABLESERVICE; $STARTSERVICE
897        if [ $? -ne 0 ]; then
898                errorAndLog "${FUNCNAME}(): error while configure Samba"
899                return 1
900        fi
901        # Crear clave para usuario de acceso a los recursos.
902        echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | smbpasswd -a -s $OPENGNSYS_CLIENT_USER
903
904        echoAndLog "${FUNCNAME}(): Added Samba configuration."
905        return 0
906}
907
908
909########################################################################
910## Configuracion servicio Rsync
911########################################################################
912
913# Configurar servicio Rsync.
914function rsyncConfigure()
915{
916        echoAndLog "${FUNCNAME}(): Configuring Rsync service."
917
918        backupFile $RSYNCCFGDIR/rsyncd.conf
919
920        # Configurar acceso a Rsync.
921        sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENT_USER/g" \
922                $WORKDIR/opengnsys/repoman/etc/rsyncd.conf.tmpl > $RSYNCCFGDIR/rsyncd.conf
923        sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENT_USER/g" \
924            -e "s/CLIENTPASSWORD/$OPENGNSYS_CLIENT_PASSWD/g" \
925                $WORKDIR/opengnsys/repoman/etc/rsyncd.secrets.tmpl > $RSYNCCFGDIR/rsyncd.secrets
926        chown root.root $RSYNCCFGDIR/rsyncd.secrets
927        chmod 600 $RSYNCCFGDIR/rsyncd.secrets
928
929        # Habilitar Rsync y reiniciar Inetd.
930        if [ -n "$RSYNCSERV" ]; then
931                if [ -f /etc/default/rsync ]; then
932                        perl -pi -e 's/RSYNC_ENABLE=.*/RSYNC_ENABLE=inetd/' /etc/default/rsync
933                fi
934                if [ -f $INETDCFGDIR/rsync ]; then
935                        perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/rsync
936                else
937                        cat << EOT > $INETDCFGDIR/rsync
938service rsync
939{
940        disable = no
941        socket_type = stream
942        wait = no
943        user = root
944        server = $(which rsync)
945        server_args = --daemon
946        log_on_failure += USERID
947        flags = IPv6
948}
949EOT
950                fi
951                service=$RSYNCSERV $ENABLESERVICE
952                service=$INETDSERV $STARTSERVICE
953        fi
954
955        echoAndLog "${FUNCNAME}(): Added Rsync configuration."
956        return 0
957}
958
959       
960########################################################################
961## Configuracion servicio DHCP
962########################################################################
963
964# Configurar servicios DHCP.
965function dhcpConfigure()
966{
967        echoAndLog "${FUNCNAME}(): Sample DHCP configuration."
968
969        local errcode=0
970        local i=0
971        local dev=""
972
973        backupFile $DHCPCFGDIR/dhcpd.conf
974        for dev in ${DEVICE[*]}; do
975                if [ -n "${SERVERIP[i]}" ]; then
976                        backupFile $DHCPCFGDIR/dhcpd-$dev.conf
977                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
978                            -e "s/NETIP/${NETIP[i]}/g" \
979                            -e "s/NETMASK/${NETMASK[i]}/g" \
980                            -e "s/NETBROAD/${NETBROAD[i]}/g" \
981                            -e "s/ROUTERIP/${ROUTERIP[i]}/g" \
982                            -e "s/DNSIP/$DNSIP/g" \
983                            $WORKDIR/opengnsys/server/etc/dhcpd.conf.tmpl > $DHCPCFGDIR/dhcpd-$dev.conf || errcode=1
984                fi
985                let i++
986        done
987        if [ $errcode -ne 0 ]; then
988                errorAndLog "${FUNCNAME}(): error while configuring DHCP server"
989                return 1
990        fi
991        ln -f $DHCPCFGDIR/dhcpd-$DEFAULTDEV.conf $DHCPCFGDIR/dhcpd.conf
992        service=$DHCPSERV
993        $ENABLESERVICE; $STARTSERVICE
994        echoAndLog "${FUNCNAME}(): Sample DHCP configured in \"$DHCPCFGDIR\"."
995        return 0
996}
997
998
999#####################################################################
1000####### Funciones específicas de la instalación de Opengnsys
1001#####################################################################
1002
1003# Copiar ficheros del OpenGnSys Web Console.
1004function installWebFiles()
1005{
1006        echoAndLog "${FUNCNAME}(): Installing web files..."
1007        cp -a $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www   #*/ comentario para doxigen
1008        if [ $? != 0 ]; then
1009                errorAndLog "${FUNCNAME}(): Error copying web files."
1010                exit 1
1011        fi
1012        find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null
1013        # Descomprimir XAJAX.
1014        unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax
1015        # Cambiar permisos para ficheros especiales.
1016        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/{fotos,iconos}
1017        echoAndLog "${FUNCNAME}(): Web files installed successfully."
1018}
1019
1020# Configuración específica de Apache.
1021function installWebConsoleApacheConf()
1022{
1023        if [ $# -ne 2 ]; then
1024                errorAndLog "${FUNCNAME}(): invalid number of parameters"
1025                exit 1
1026        fi
1027
1028        local path_opengnsys_base=$1
1029        local path_apache2_confd=$2
1030        local CONSOLEDIR=${path_opengnsys_base}/www
1031
1032        if [ ! -d $path_apache2_confd ]; then
1033                errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation"
1034                return 1
1035        fi
1036
1037        mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
1038
1039        echoAndLog "${FUNCNAME}(): creating apache2 config file.."
1040
1041        # Activar HTTPS.
1042        $APACHESSLMOD
1043        $APACHEENABLESSL
1044        $APACHEMAKECERT
1045
1046        # Genera configuración de consola web a partir del fichero plantilla.
1047        sed -e "s/CONSOLEDIR/${CONSOLEDIR//\//\\/}/g" \
1048                $WORKDIR/opengnsys/server/etc/apache.conf.tmpl > $path_opengnsys_base/etc/apache.conf
1049
1050        ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/$APACHESITESDIR/$APACHEOGSITE
1051        $APACHEENABLEOG
1052        if [ $? -ne 0 ]; then
1053                errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation"
1054                return 1
1055        else
1056                echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon"
1057                service=$APACHESERV
1058                $ENABLESERVICE; $STARTSERVICE
1059                return 0
1060        fi
1061}
1062
1063
1064# Crear documentación Doxygen para la consola web.
1065function makeDoxygenFiles()
1066{
1067        echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
1068        $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
1069                        $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
1070        if [ ! -d "$INSTALL_TARGET/www/html" ]; then
1071                errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
1072                return 1
1073        fi
1074        mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
1075        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
1076        echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
1077}
1078
1079
1080# Crea la estructura base de la instalación de opengnsys
1081function createDirs()
1082{
1083        if [ $# -ne 1 ]; then
1084                errorAndLog "${FUNCNAME}(): invalid number of parameters"
1085                exit 1
1086        fi
1087
1088        local path_opengnsys_base="$1"
1089
1090        # Crear estructura de directorios.
1091        echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base"
1092        mkdir -p $path_opengnsys_base
1093        mkdir -p $path_opengnsys_base/bin
1094        mkdir -p $path_opengnsys_base/client
1095        mkdir -p $path_opengnsys_base/doc
1096        mkdir -p $path_opengnsys_base/etc
1097        mkdir -p $path_opengnsys_base/lib
1098        mkdir -p $path_opengnsys_base/log/clients
1099        ln -fs $path_opengnsys_base/log /var/log/opengnsys
1100        mkdir -p $path_opengnsys_base/sbin
1101        mkdir -p $path_opengnsys_base/www
1102        mkdir -p $path_opengnsys_base/images
1103        mkdir -p $TFTPCFGDIR
1104        ln -fs $TFTPCFGDIR $path_opengnsys_base/tftpboot
1105        mkdir -p $path_opengnsys_base/tftpboot/pxelinux.cfg
1106        mkdir -p $path_opengnsys_base/tftpboot/menu.lst
1107        if [ $? -ne 0 ]; then
1108                errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
1109                return 1
1110        fi
1111
1112        # Crear usuario ficticio.
1113        if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then
1114                echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created"
1115        else
1116                echoAndLog "${FUNCNAME}(): creating OpenGnSys user"
1117                useradd $OPENGNSYS_CLIENT_USER 2>/dev/null
1118                if [ $? -ne 0 ]; then
1119                        errorAndLog "${FUNCNAME}(): error creating OpenGnSys user"
1120                        return 1
1121                fi
1122        fi
1123
1124        # Establecer los permisos básicos.
1125        echoAndLog "${FUNCNAME}(): setting directory permissions"
1126        chmod -R 775 $path_opengnsys_base/{log/clients,images}
1127        chown -R :$OPENGNSYS_CLIENT_USER $path_opengnsys_base/{log/clients,images}
1128        if [ $? -ne 0 ]; then
1129                errorAndLog "${FUNCNAME}(): error while setting permissions"
1130                return 1
1131        fi
1132
1133        # Mover el fichero de registro de instalación al directorio de logs.
1134        echoAndLog "${FUNCNAME}(): moving installation log file"
1135        mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE
1136        chmod 600 $LOG_FILE
1137
1138        echoAndLog "${FUNCNAME}(): directory paths created"
1139        return 0
1140}
1141
1142# Copia ficheros de configuración y ejecutables genéricos del servidor.
1143function copyServerFiles ()
1144{
1145        if [ $# -ne 1 ]; then
1146                errorAndLog "${FUNCNAME}(): invalid number of parameters"
1147                exit 1
1148        fi
1149
1150        local path_opengnsys_base="$1"
1151
1152        local SOURCES=( server/tftpboot \
1153                        server/bin \
1154                        repoman/bin \
1155                        installer/opengnsys_uninstall.sh \
1156                        installer/opengnsys_update.sh \
1157                        installer/install_ticket_wolunicast.sh \
1158                        doc )
1159        local TARGETS=( tftpboot \
1160                        bin \
1161                        bin \
1162                        lib \
1163                        lib \
1164                        lib \
1165                        doc )
1166
1167        if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
1168                errorAndLog "${FUNCNAME}(): inconsistent number of array items"
1169                exit 1
1170        fi
1171
1172        echoAndLog "${FUNCNAME}(): copying files to server directories"
1173
1174        pushd $WORKDIR/opengnsys
1175        local i
1176        for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
1177                if [ -f "${SOURCES[$i]}" ]; then
1178                        echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
1179                        cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
1180                elif [ -d "${SOURCES[$i]}" ]; then
1181                        echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
1182                        cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}"
1183        else
1184                        echoAndLog "Warning: Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
1185                fi
1186        done
1187        popd
1188}
1189
1190####################################################################
1191### Funciones de compilación de código fuente de servicios
1192####################################################################
1193
1194# Compilar los servicios de OpenGnSys
1195function servicesCompilation ()
1196{
1197        local hayErrores=0
1198
1199        # Compilar OpenGnSys Server
1200        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server"
1201        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer
1202        make && mv ogAdmServer $INSTALL_TARGET/sbin
1203        if [ $? -ne 0 ]; then
1204                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
1205                hayErrores=1
1206        fi
1207        popd
1208        # Compilar OpenGnSys Repository Manager
1209        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager"
1210        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo
1211        make && mv ogAdmRepo $INSTALL_TARGET/sbin
1212        if [ $? -ne 0 ]; then
1213                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
1214                hayErrores=1
1215        fi
1216        popd
1217        # Compilar OpenGnSys Agent
1218        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent"
1219        pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent
1220        make && mv ogAdmAgent $INSTALL_TARGET/sbin
1221        if [ $? -ne 0 ]; then
1222                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent"
1223                hayErrores=1
1224        fi
1225        popd   
1226        # Compilar OpenGnSys Client
1227        echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client"
1228        pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient
1229        make && mv ogAdmClient ../../../../client/shared/bin
1230        if [ $? -ne 0 ]; then
1231                echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client"
1232                hayErrores=1
1233        fi
1234        popd
1235
1236        return $hayErrores
1237}
1238
1239####################################################################
1240### Funciones de copia de la Interface de administración
1241####################################################################
1242
1243# Copiar carpeta de Interface
1244function copyInterfaceAdm ()
1245{
1246        local hayErrores=0
1247       
1248        # Crear carpeta y copiar Interface
1249        echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
1250        cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm
1251        if [ $? -ne 0 ]; then
1252                echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder"
1253                hayErrores=1
1254        fi
1255        chown $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
1256        chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso
1257
1258        return $hayErrores
1259}
1260
1261####################################################################
1262### Funciones instalacion cliente opengnsys
1263####################################################################
1264
1265function copyClientFiles()
1266{
1267        local errstatus=0
1268
1269        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
1270        cp -a $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client
1271        if [ $? -ne 0 ]; then
1272                errorAndLog "${FUNCNAME}(): error while copying client estructure"
1273                errstatus=1
1274        fi
1275        find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
1276       
1277        echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
1278        mkdir -p $INSTALL_TARGET/client/lib/engine/bin
1279        cp -a $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin
1280        if [ $? -ne 0 ]; then
1281                errorAndLog "${FUNCNAME}(): error while copying engine files"
1282                errstatus=1
1283        fi
1284       
1285        if [ $errstatus -eq 0 ]; then
1286                echoAndLog "${FUNCNAME}(): client copy files success."
1287        else
1288                errorAndLog "${FUNCNAME}(): client copy files with errors"
1289        fi
1290
1291        return $errstatus
1292}
1293
1294
1295# Crear cliente OpenGnSys 1.0.2 y posteriores.
1296function clientCreate()
1297{
1298        local DOWNLOADURL="http://$OPENGNSYS_SERVER/downloads"
1299        local FILENAME=ogLive-precise-3.2.0-23-generic-r3257.iso        # 1.0.4-rc2
1300        local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
1301        local TMPDIR=/tmp/${FILENAME%.iso}
1302 
1303        # Descargar cliente, si es necesario.
1304        if [ -s $PROGRAMDIR/$FILENAME ]; then
1305                echoAndLog "${FUNCNAME}(): Moving $PROGRAMDIR/$FILENAME file to $(dirname $TARGETFILE)"
1306                mv $PROGRAMDIR/$FILENAME $TARGETFILE
1307        else
1308                echoAndLog "${FUNCNAME}(): Loading Client"
1309                wget $DOWNLOADURL/$FILENAME -O $TARGETFILE
1310        fi
1311        if [ ! -s $TARGETFILE ]; then
1312                errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client"
1313                return 1
1314        fi
1315        # Montar imagen, copiar cliente ogclient y desmontar.
1316        echoAndLog "${FUNCNAME}(): Copying Client files"
1317        mkdir -p $TMPDIR
1318        mount -o loop,ro $TARGETFILE $TMPDIR
1319        cp -av $TMPDIR/ogclient $INSTALL_TARGET/tftpboot
1320        umount $TMPDIR
1321        rmdir $TMPDIR
1322        # Asignar la clave cliente para acceso a Samba.
1323        echoAndLog "${FUNCNAME}(): Set client access key"
1324        echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | \
1325                        $INSTALL_TARGET/bin/setsmbpass
1326
1327        # Establecer los permisos.
1328        find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \;
1329        find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \;
1330        chown -R :$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/tftpboot/ogclient
1331        chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg}
1332
1333        # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache
1334        cp -av $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot
1335        cp -av $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot
1336
1337        echoAndLog "${FUNCNAME}(): Client generation success"
1338}
1339
1340
1341# Configuración básica de servicios de OpenGnSys
1342function openGnsysConfigure()
1343{
1344        local i=0
1345        local dev=""
1346        local CONSOLEURL
1347
1348        echoAndLog "${FUNCNAME}(): Copying init files."
1349        cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
1350        cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys
1351        cp -p $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepoAux $INSTALL_TARGET/sbin
1352        echoAndLog "${FUNCNAME}(): Creating cron files."
1353        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys
1354        echo "* * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
1355        echo "5 * * * *   root   [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
1356
1357        echoAndLog "${FUNCNAME}(): Creating logrotate configuration file."
1358        sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
1359                $WORKDIR/opengnsys/server/etc/logrotate.tmpl > /etc/logrotate.d/opengnsys
1360
1361        echoAndLog "${FUNCNAME}(): Creating OpenGnSys config files."
1362        for dev in ${DEVICE[*]}; do
1363                if [ -n "${SERVERIP[i]}" ]; then
1364                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1365                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1366                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1367                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1368                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer/ogAdmServer.cfg > $INSTALL_TARGET/etc/ogAdmServer-$dev.cfg
1369                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1370                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo/ogAdmRepo.cfg > $INSTALL_TARGET/etc/ogAdmRepo-$dev.cfg
1371                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1372                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1373                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1374                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1375                                $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent/ogAdmAgent.cfg > $INSTALL_TARGET/etc/ogAdmAgent-$dev.cfg
1376                        CONSOLEURL="http://${SERVERIP[i]}/opengnsys"
1377                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1378                            -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
1379                            -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
1380                            -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
1381                            -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \
1382                                $INSTALL_TARGET/www/controlacceso.php > $INSTALL_TARGET/www/controlacceso-$dev.php
1383                        sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
1384                            -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \
1385                                $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient-$dev.cfg
1386                        if [ "$dev" == "$DEFAULTDEV" ]; then
1387                                OPENGNSYS_CONSOLEURL="${CONSOLEURL/http:/https:}"
1388                        fi
1389                fi
1390                let i++
1391        done
1392        ln -f $INSTALL_TARGET/etc/ogAdmServer-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmServer.cfg
1393        ln -f $INSTALL_TARGET/etc/ogAdmRepo-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmRepo.cfg
1394        ln -f $INSTALL_TARGET/etc/ogAdmAgent-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmAgent.cfg
1395        ln -f $INSTALL_TARGET/client/etc/ogAdmClient-$DEFAULTDEV.cfg $INSTALL_TARGET/client/etc/ogAdmClient.cfg
1396        ln -f $INSTALL_TARGET/www/controlacceso-$DEFAULTDEV.php $INSTALL_TARGET/www/controlacceso.php
1397        chown root:root $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg
1398        chmod 600 $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg
1399        chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso*.php
1400        chmod 600 $INSTALL_TARGET/www/controlacceso*.php
1401        echoAndLog "${FUNCNAME}(): Starting OpenGnSys services."
1402        service="opengnsys"
1403        $ENABLESERVICE; $STARTSERVICE
1404}
1405
1406
1407#####################################################################
1408#######  Función de resumen informativo de la instalación
1409#####################################################################
1410
1411function installationSummary()
1412{
1413        # Crear fichero de versión y revisión, si no existe.
1414        local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt"
1415        local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}')
1416        [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE
1417        perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE
1418
1419        # Mostrar información.
1420        echo
1421        echoAndLog "OpenGnSys Installation Summary"
1422        echo       "=============================="
1423        echoAndLog "Project version:                  $(cat $VERSIONFILE 2>/dev/null)"
1424        echoAndLog "Installation directory:           $INSTALL_TARGET"
1425        echoAndLog "Installation log file:            $LOG_FILE"
1426        echoAndLog "Repository directory:             $INSTALL_TARGET/images"
1427        echoAndLog "DHCP configuration directory:     $DHCPCFGDIR"
1428        echoAndLog "TFTP configuration directory:     $TFTPCFGDIR"
1429        echoAndLog "Samba configuration directory:    $SAMBACFGDIR"
1430        echoAndLog "Web Console URL:                  $OPENGNSYS_CONSOLEURL"
1431        echoAndLog "Web Console admin user:           $OPENGNSYS_DB_USER"
1432        echoAndLog "Web Console admin password:       $OPENGNSYS_DB_PASSWD"
1433        echo
1434        echoAndLog "Post-Installation Instructions:"
1435        echo       "==============================="
1436        echoAndLog "Change IPTables and SELinux system configuration, if needed."
1437        echoAndLog "Review or edit all configuration files."
1438        echoAndLog "Insert DHCP configuration data and restart service."
1439        echoAndLog "Optional: Log-in as Web Console admin user."
1440        echoAndLog " - Review default Organization data and assign access to users."
1441        echoAndLog "Log-in as Web Console organization user."
1442        echoAndLog " - Insert OpenGnSys data (labs, computers, menus, etc)."
1443echo
1444}
1445
1446
1447
1448#####################################################################
1449####### Proceso de instalación de OpenGnSys
1450#####################################################################
1451
1452echoAndLog "OpenGnSys installation begins at $(date)"
1453pushd $WORKDIR
1454
1455# Detectar datos iniciales de auto-configuración del instalador.
1456autoConfigure
1457
1458# Detectar parámetros de red y comprobar si hay conexión.
1459getNetworkSettings
1460if [ $? -ne 0 ]; then
1461        errorAndLog "Error reading default network settings."
1462        exit 1
1463fi
1464checkNetworkConnection
1465if [ $? -ne 0 ]; then
1466        errorAndLog "Error connecting to server. Causes:"
1467        errorAndLog " - Network is unreachable, review devices parameters."
1468        errorAndLog " - You are inside a private network, configure the proxy service."
1469        errorAndLog " - Server is temporally down, try agian later."
1470        exit 1
1471fi
1472
1473# Detener servicios de OpenGnSys, si están activos previamente.
1474[ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop
1475
1476# Actualizar repositorios
1477updatePackageList
1478
1479# Instalación de dependencias (paquetes de sistema operativo).
1480declare -a notinstalled
1481checkDependencies DEPENDENCIES notinstalled
1482if [ $? -ne 0 ]; then
1483        installDependencies notinstalled
1484        if [ $? -ne 0 ]; then
1485                echoAndLog "Error while installing some dependeces, please verify your server installation before continue"
1486                exit 1
1487        fi
1488fi
1489if [ -n "$INSTALLEXTRADEPS" ]; then
1490        echoAndLog "Installing extra dependencies"
1491        for (( i=0; i<${#INSTALLEXTRADEPS[*]}; i++ )); do
1492                eval ${INSTALLEXTRADEPS[i]}
1493        done
1494fi     
1495
1496# Detectar datos de auto-configuración después de instalar paquetes.
1497autoConfigurePost
1498
1499# Arbol de directorios de OpenGnSys.
1500createDirs ${INSTALL_TARGET}
1501if [ $? -ne 0 ]; then
1502        errorAndLog "Error while creating directory paths!"
1503        exit 1
1504fi
1505
1506# Si es necesario, descarga el repositorio de código en directorio temporal
1507if [ $USESVN -eq 1 ]; then
1508        svnExportCode $SVN_URL
1509        if [ $? -ne 0 ]; then
1510                errorAndLog "Error while getting code from svn"
1511                exit 1
1512        fi
1513else
1514        ln -fs "$(dirname $PROGRAMDIR)" opengnsys
1515fi
1516
1517# Compilar código fuente de los servicios de OpenGnSys.
1518servicesCompilation
1519if [ $? -ne 0 ]; then
1520        errorAndLog "Error while compiling OpenGnsys services"
1521        exit 1
1522fi
1523
1524# Copiar carpeta Interface entre administración y motor de clonación.
1525copyInterfaceAdm
1526if [ $? -ne 0 ]; then
1527        errorAndLog "Error while copying Administration Interface"
1528        exit 1
1529fi
1530
1531# Configuración de TFTP.
1532tftpConfigure
1533
1534# Configuración de Samba.
1535smbConfigure
1536if [ $? -ne 0 ]; then
1537        errorAndLog "Error while configuring Samba server!"
1538        exit 1
1539fi
1540
1541# Configuración de Rsync.
1542rsyncConfigure
1543
1544# Configuración ejemplo DHCP.
1545dhcpConfigure
1546if [ $? -ne 0 ]; then
1547        errorAndLog "Error while copying your dhcp server files!"
1548        exit 1
1549fi
1550
1551# Copiar ficheros de servicios OpenGnSys Server.
1552copyServerFiles ${INSTALL_TARGET}
1553if [ $? -ne 0 ]; then
1554        errorAndLog "Error while copying the server files!"
1555        exit 1
1556fi
1557
1558# Instalar Base de datos de OpenGnSys Admin.
1559isInArray notinstalled "mysql-server"
1560if [ $? -eq 0 ]; then
1561        service=$MYSQLSERV
1562        $ENABLESERVICE; $STARTSERVICE
1563        mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD}
1564else
1565        mysqlGetRootPassword
1566fi
1567
1568mysqlTestConnection ${MYSQL_ROOT_PASSWORD}
1569if [ $? -ne 0 ]; then
1570        errorAndLog "Error while connection to mysql"
1571        exit 1
1572fi
1573mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1574if [ $? -ne 0 ]; then
1575        echoAndLog "Creating Web Console database"
1576        mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1577        if [ $? -ne 0 ]; then
1578                errorAndLog "Error while creating Web Console database"
1579                exit 1
1580        fi
1581else
1582        echoAndLog "Web Console database exists, ommiting creation"
1583fi
1584
1585mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER}
1586if [ $? -ne 0 ]; then
1587        echoAndLog "Creating user in database"
1588        mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
1589        if [ $? -ne 0 ]; then
1590                errorAndLog "Error while creating database user"
1591                exit 1
1592        fi
1593
1594fi
1595
1596mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE}
1597if [ $? -eq 0 ]; then
1598        echoAndLog "Creating tables..."
1599        if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then
1600                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE
1601        else
1602                errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!"
1603                exit 1
1604        fi
1605else
1606        # Si existe fichero ogBDAdmin-VersLocal-VersRepo.sql; aplicar cambios.
1607        INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt)
1608        REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt)
1609        OPENGNSYS_DB_UPDATE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql"
1610        if [ -f $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE ]; then
1611                echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION"
1612                mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE
1613        else
1614                echoAndLog "Database unchanged."
1615        fi
1616fi
1617
1618# copiando paqinas web
1619installWebFiles
1620# Generar páqinas web de documentación de la API
1621makeDoxygenFiles
1622
1623# creando configuracion de apache2
1624installWebConsoleApacheConf $INSTALL_TARGET $APACHECFGDIR
1625if [ $? -ne 0 ]; then
1626        errorAndLog "Error configuring Apache for OpenGnSys Admin"
1627        exit 1
1628fi
1629
1630popd
1631
1632# Crear la estructura de los accesos al servidor desde el cliente (shared)
1633copyClientFiles
1634if [ $? -ne 0 ]; then
1635        errorAndLog "Error creating client structure"
1636fi
1637
1638# Crear la estructura del cliente de OpenGnSys
1639clientCreate
1640if [ $? -ne 0 ]; then
1641        errorAndLog "Error creating client"
1642        exit 1
1643fi
1644
1645# Configuración de servicios de OpenGnSys
1646openGnsysConfigure
1647
1648# Mostrar sumario de la instalación e instrucciones de post-instalación.
1649installationSummary
1650
1651#rm -rf $WORKDIR
1652echoAndLog "OpenGnSys installation finished at $(date)"
1653exit 0
1654
Note: See TracBrowser for help on using the repository browser.