#!/bin/bash ##################################################################### ####### Script instalador OpenGnsys ####### autor: Luis Guillén ##################################################################### #### AVISO: Editar configuración de acceso por defecto MYSQL_ROOT_PASSWORD="passwordroot" # Clave root de MySQL OPENGNSYS_DATABASE="ogAdmBD" # Nombre de la base datos OPENGNSYS_DB_USER="usuog" # Usuario de acceso OPENGNSYS_DB_PASSWD="passusuog" # Clave del usuario # Sólo ejecutable por usuario root if [ "$(whoami)" != 'root' ] then echo "ERROR: this program must run under root privileges!!" exit 1 fi # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). PROGRAMDIR=$(readlink -e $(dirname "$0")) if [ -d "$PROGRAMDIR/../installer" ]; then USESVN=0 else USESVN=1 SVN_URL="http://www.opengnsys.es/svn/tags/opengnsys-0.10" fi WORKDIR=/tmp/opengnsys_installer mkdir -p $WORKDIR INSTALL_TARGET=/opt/opengnsys LOG_FILE=/tmp/opengnsys_installation.log # Array con las dependencias DEPENDENCIES=( subversion apache2 php5 libapache2-mod-php5 mysql-server php5-mysql nfs-kernel-server dhcp3-server udpcast bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential g++-multilib libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent ) # Base de datos OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogAdmBD.sql ##################################################################### ####### Algunas funciones útiles de propósito general: ##################################################################### function getDateTime() { echo `date +%Y%m%d-%H%M%S` } # Escribe a fichero y muestra por pantalla function echoAndLog() { echo $1 FECHAHORA=`getDateTime` echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE } function errorAndLog() { echo "ERROR: $1" FECHAHORA=`getDateTime` echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE } # comprueba si el elemento pasado en $2 esta en el array $1 function isInArray() { if [ $# -ne 2 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1 fi echoAndLog "${FUNCNAME}(): checking if $2 is in $1" local deps eval "deps=( \"\${$1[@]}\" )" elemento=$2 local is_in_array=1 # copia local del array del parametro 1 for (( i = 0 ; i < ${#deps[@]} ; i++ )) do if [ "${deps[$i]}" = "${elemento}" ]; then echoAndLog "isInArray(): $elemento found in array" is_in_array=0 fi done if [ $is_in_array -ne 0 ]; then echoAndLog "${FUNCNAME}(): $elemento NOT found in array" fi return $is_in_array } ##################################################################### ####### Funciones de manejo de paquetes Debian ##################################################################### function checkPackage() { package=$1 if [ -z $package ]; then errorAndLog "${FUNCNAME}(): parameter required" exit 1 fi echoAndLog "${FUNCNAME}(): checking if package $package exists" dpkg -s $package &>/dev/null | grep Status | grep -qw install if [ $? -eq 0 ]; then echoAndLog "${FUNCNAME}(): package $package exists" return 0 else echoAndLog "${FUNCNAME}(): package $package doesn't exists" return 1 fi } # recibe array con dependencias # por referencia deja un array con las dependencias no resueltas # devuelve 1 si hay alguna dependencia no resuelta function checkDependencies() { if [ $# -ne 2 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1 fi echoAndLog "${FUNCNAME}(): checking dependences" uncompletedeps=0 # copia local del array del parametro 1 local deps eval "deps=( \"\${$1[@]}\" )" declare -a local_notinstalled for (( i = 0 ; i < ${#deps[@]} ; i++ )) do checkPackage ${deps[$i]} if [ $? -ne 0 ]; then local_notinstalled[$uncompletedeps]=$package let uncompletedeps=uncompletedeps+1 fi done # relleno el array especificado en $2 por referencia for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ )) do eval "${2}[$i]=${local_notinstalled[$i]}" done # retorna el numero de paquetes no resueltos echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps" return $uncompletedeps } # Recibe un array con las dependencias y lo instala function installDependencies() { if [ $# -ne 1 ]; then errorAndLog "installDependencies(): invalid number of parameters" exit 1 fi echoAndLog "installDependencies(): installing uncompleted dependencies" # copia local del array del parametro 1 local deps eval "deps=( \"\${$1[@]}\" )" local string_deps="" for (( i = 0 ; i < ${#deps[@]} ; i++ )) do string_deps="$string_deps ${deps[$i]}" done if [ -z "${string_deps}" ]; then errorAndLog "installDependencies(): array of dependeces is empty" exit 1 fi OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND export DEBIAN_FRONTEND=noninteractive echoAndLog "installDependencies(): now ${string_deps} will be installed" apt-get -y install --force-yes ${string_deps} if [ $? -ne 0 ]; then errorAndLog "installDependencies(): error installing dependencies" return 1 fi DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND echoAndLog "installDependencies(): dependencies installed" } # Hace un backup del fichero pasado por parámetro # deja un -last y uno para el día function backupFile() { if [ $# -ne 1 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1 fi local fichero=$1 local fecha=`date +%Y%m%d` if [ ! -f $fichero ]; then errorAndLog "${FUNCNAME}(): file $fichero doesn't exists" return 1 fi echoAndLog "${FUNCNAME}(): realizando backup de $fichero" # realiza una copia de la última configuración como last cp -p $fichero "${fichero}-LAST" # si para el día no hay backup lo hace, sino no if [ ! -f "${fichero}-${fecha}" ]; then cp -p $fichero "${fichero}-${fecha}" fi echoAndLog "${FUNCNAME}(): backup realizado" } ##################################################################### ####### Funciones para el manejo de bases de datos ##################################################################### # This function set password to root function mysqlSetRootPassword() { if [ $# -ne 1 ]; then errorAndLog "mysqlSetRootPassword(): invalid number of parameters" exit 1 fi local root_mysql=$1 echoAndLog "mysqlSetRootPassword(): setting root password in MySQL server" /usr/bin/mysqladmin -u root password ${root_mysql} if [ $? -ne 0 ]; then errorAndLog "mysqlSetRootPassword(): error while setting root password in MySQL server" return 1 fi echoAndLog "mysqlSetRootPassword(): root password saved!" return 0 } # Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente function mysqlGetRootPassword(){ local pass_mysql local pass_mysql2 # Comprobar si MySQL está instalado con la clave de root por defecto. if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then echoAndLog "${FUNCNAME}(): Using default mysql root password." else stty -echo echo "Existe un servicio mysql ya instalado" read -p "Insertar clave de root de Mysql: " pass_mysql echo "" read -p "Confirmar clave:" pass_mysql2 echo "" stty echo if [ "$pass_mysql" == "$pass_mysql2" ] ;then MYSQL_ROOT_PASSWORD=$pass_mysql echo "La clave es: ${MYSQL_ROOT_PASSWORD}" return 0 else echo "Las claves no coinciden no se configura la clave del servidor de base de datos." echo "las operaciones con la base de datos daran error" return 1 fi fi } # comprueba si puede conectar con mysql con el usuario root function mysqlTestConnection() { if [ $# -ne 1 ]; then errorAndLog "mysqlTestConnection(): invalid number of parameters" exit 1 fi local root_password="${1}" echoAndLog "mysqlTestConnection(): checking connection to mysql..." echo "" | mysql -uroot -p"${root_password}" if [ $? -ne 0 ]; then errorAndLog "mysqlTestConnection(): connection to mysql failed, check root password and if daemon is running!" return 1 else echoAndLog "mysqlTestConnection(): connection success" return 0 fi } # comprueba si la base de datos existe function mysqlDbExists() { if [ $# -ne 2 ]; then errorAndLog "mysqlDbExists(): invalid number of parameters" exit 1 fi local root_password="${1}" local database=$2 echoAndLog "mysqlDbExists(): checking if $database exists..." echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$" if [ $? -ne 0 ]; then echoAndLog "mysqlDbExists():database $database doesn't exists" return 1 else echoAndLog "mysqlDbExists():database $database exists" return 0 fi } function mysqlCheckDbIsEmpty() { if [ $# -ne 2 ]; then errorAndLog "mysqlCheckDbIsEmpty(): invalid number of parameters" exit 1 fi local root_password="${1}" local database=$2 echoAndLog "mysqlCheckDbIsEmpty(): checking if $database is empty..." num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l` if [ $? -ne 0 ]; then errorAndLog "mysqlCheckDbIsEmpty(): error executing query, check database and root password" exit 1 fi if [ $num_tablas -eq 0 ]; then echoAndLog "mysqlCheckDbIsEmpty():database $database is empty" return 0 else echoAndLog "mysqlCheckDbIsEmpty():database $database has tables" return 1 fi } function mysqlImportSqlFileToDb() { if [ $# -ne 3 ]; then errorAndLog "${FNCNAME}(): invalid number of parameters" exit 1 fi local root_password="$1" local database="$2" local sqlfile="$3" local tmpfile=$(mktemp) local status if [ ! -f $sqlfile ]; then errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!" return 1 fi echoAndLog "${FUNCNAME}(): importing sql file to ${database}..." chmod 600 $tmpfile sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" $sqlfile > $tmpfile mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $tmpfile status=$? rm -f $tmpfile if [ $status -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database" return 1 fi echoAndLog "${FUNCNAME}(): file imported to database $database" return 0 } # Crea la base de datos function mysqlCreateDb() { if [ $# -ne 2 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1 fi local root_password="${1}" local database=$2 echoAndLog "${FUNCNAME}(): creating database..." mysqladmin -u root --password="${root_password}" create $database if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while creating database $database" return 1 fi echoAndLog "${FUNCNAME}(): database $database created" return 0 } function mysqlCheckUserExists() { if [ $# -ne 2 ]; then errorAndLog "mysqlCheckUserExists(): invalid number of parameters" exit 1 fi local root_password="${1}" local userdb=$2 echoAndLog "mysqlCheckUserExists(): checking if $userdb exists..." echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user if [ $? -ne 0 ]; then echoAndLog "mysqlCheckUserExists(): user doesn't exists" return 1 else echoAndLog "mysqlCheckUserExists(): user already exists" return 0 fi } # Crea un usuario administrativo para la base de datos function mysqlCreateAdminUserToDb() { if [ $# -ne 4 ]; then errorAndLog "mysqlCreateAdminUserToDb(): invalid number of parameters" exit 1 fi local root_password=$1 local database=$2 local userdb=$3 local passdb=$4 echoAndLog "mysqlCreateAdminUserToDb(): creating admin user ${userdb} to database ${database}" cat > $WORKDIR/create_${database}.sql < ${basetftp}/pxelinux.cfg/default < /dev/null if [ $? -eq 0 ]; then echoAndLog "${FUNCNAME}(): $export exists in /etc/exports, omiting" return 0 fi cadenaexport="${export}" for parametro in $* do if [ $contador -gt 0 ] then host=`echo $parametro | awk -F: '{print $1}'` options=`echo $parametro | awk -F: '{print $2}'` if [ "${host}" == "" ]; then errorAndLog "${FUNCNAME}(): host can't be empty" return 1 fi cadenaexport="${cadenaexport}\t${host}" if [ "${options}" != "" ]; then cadenaexport="${cadenaexport}(${options})" fi fi let contador=contador+1 done echo -en "$cadenaexport\n" >> /etc/exports echoAndLog "${FUNCNAME}(): add $export to /etc/exports" return 0 } ######################################################################## ## Configuracion servicio DHCP ######################################################################## function dhcpConfigure() { echoAndLog "${FUNCNAME}(): Sample DHCP Configuration." backupFile /etc/dhcp3/dhcpd.conf sed -e "s/SERVERIP/$SERVERIP/g" \ -e "s/NETIP/$NETIP/g" \ -e "s/NETMASK/$NETMASK/g" \ -e "s/NETBROAD/$NETBROAD/g" \ -e "s/ROUTERIP/$ROUTERIP/g" \ -e "s/DNSIP/$DNSIP/g" \ $WORKDIR/opengnsys/server/DHCP/dhcpd.conf > /etc/dhcp3/dhcpd.conf if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while configuring dhcp server" return 1 fi /etc/init.d/dhcp3-server restart echoAndLog "${FUNCNAME}(): Sample DHCP Configured in file \"/etc/dhcp3/dhcpd.conf\"." return 0 } ##################################################################### ####### Funciones específicas de la instalación de Opengnsys ##################################################################### # Copiar ficheros del OpenGnSys Web Console. function installWebFiles() { echoAndLog "${FUNCNAME}(): Installing web files..." cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para doxigen if [ $? != 0 ]; then errorAndLog "${FUNCNAME}(): Error copying web files." exit 1 fi find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null # Cambiar permisos para ficheros especiales. chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/iconos echoAndLog "${FUNCNAME}(): Web files installed successfully." } # Configuración específica de Apache. function openGnsysInstallWebConsoleApacheConf() { if [ $# -ne 2 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1 fi local path_opengnsys_base=$1 local path_apache2_confd=$2 local path_web_console=${path_opengnsys_base}/www if [ ! -d $path_apache2_confd ]; then errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation" return 1 fi mkdir -p $path_apache2_confd/{sites-available,sites-enabled} echoAndLog "${FUNCNAME}(): creating apache2 config file.." # genera configuración cat > $path_opengnsys_base/etc/apache.conf < Options -Indexes FollowSymLinks DirectoryIndex acceso.php EOF ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys.conf ln -fs $path_apache2_confd/sites-available/opengnsys.conf $path_apache2_confd/sites-enabled/opengnsys.conf if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation" return 1 else echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon" /etc/init.d/apache2 restart return 0 fi } # Crear documentación Doxygen para la consola web. function makeDoxygenFiles() { echoAndLog "${FUNCNAME}(): Making Doxygen web files..." $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \ $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www if [ ! -d "$INSTALL_TARGET/www/html" ]; then errorAndLog "${FUNCNAME}(): unable to create Doxygen web files." return 1 fi mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api" chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api echoAndLog "${FUNCNAME}(): Doxygen web files created successfully." } # Crea la estructura base de la instalación de opengnsys function openGnsysInstallCreateDirs() { if [ $# -ne 1 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1 fi local path_opengnsys_base=$1 echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base" mkdir -p $path_opengnsys_base mkdir -p $path_opengnsys_base/bin mkdir -p $path_opengnsys_base/client mkdir -p $path_opengnsys_base/doc mkdir -p $path_opengnsys_base/etc mkdir -p $path_opengnsys_base/lib mkdir -p $path_opengnsys_base/log/clients mkdir -p $path_opengnsys_base/sbin mkdir -p $path_opengnsys_base/www mkdir -p $path_opengnsys_base/images ln -fs /var/lib/tftpboot $path_opengnsys_base ln -fs $path_opengnsys_base/log /var/log/opengnsys if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" return 1 fi echoAndLog "${FUNCNAME}(): directory paths created" return 0 } # Copia ficheros de configuración y ejecutables genéricos del servidor. function openGnsysCopyServerFiles () { if [ $# -ne 1 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1 fi local path_opengnsys_base=$1 local SOURCES=( client/boot/initrd-generator \ client/boot/upgrade-clients-udeb.sh \ client/boot/udeblist.conf \ client/boot/udeblist-jaunty.conf \ client/boot/udeblist-karmic.conf \ client/boot/udeblist-lucid.conf \ client/boot/udeblist-maverick.conf \ server/PXE/pxelinux.cfg \ server/bin \ repoman/bin \ doc ) local TARGETS=( bin/initrd-generator \ bin/upgrade-clients-udeb.sh \ etc/udeblist.conf \ etc/udeblist-jaunty.conf \ etc/udeblist-karmic.conf \ etc/udeblist-lucid.conf \ etc/udeblist-maverick.conf \ tftpboot/pxelinux.cfg \ bin \ bin \ doc ) if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then errorAndLog "${FUNCNAME}(): inconsistent number of array items" exit 1 fi echoAndLog "${FUNCNAME}(): copying files to server directories" pushd $WORKDIR/opengnsys local i for (( i = 0; i < ${#SOURCES[@]}; i++ )); do if [ -f "${SOURCES[$i]}" ]; then echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" elif [ -d "${SOURCES[$i]}" ]; then echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}" else echoAndLog "Warning: Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" fi done popd } #################################################################### ### Funciones de compilación de códifo fuente de servicios #################################################################### # Compilar los servicios de OpenGNsys function servicesCompilation () { local hayErrores=0 # Compilar OpenGnSys Server echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server" pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer make && make install if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server" hayErrores=1 fi popd # Compilar OpenGnSys Repository Manager echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager" pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo make && make install if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager" hayErrores=1 fi popd # Compilar OpenGnSys Agent echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent" pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent make && make install if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent" hayErrores=1 fi popd # Compilar OpenGnSys Client echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client" pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient make && mv ogAdmClient ../../../../client/nfsexport/bin if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client" hayErrores=1 fi popd return $hayErrores } #################################################################### ### Funciones de copia de la Interface de administración #################################################################### # Copiar carpeta de Interface function InterfaceAdm () { local hayErrores=0 # Crear carpeta y copiar Interface echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder" hayErrores=1 fi return $hayErrores } #################################################################### ### Funciones instalacion cliente opengnsys #################################################################### function openGnsysClientCreate() { local OSDISTRIB OSCODENAME local hayErrores=0 echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files." cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files." mkdir -p $INSTALL_TARGET/client/lib/engine/bin cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while copying engine files" hayErrores=1 fi # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto). OSDISTRIB=$(lsb_release -is 2>/dev/null) OSCODENAME=$(lsb_release -cs 2>/dev/null) if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME." $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v $OSCODENAME 2>&1 | tee -a $LOG_FILE if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client" hayErrores=1 fi echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME." $INSTALL_TARGET/bin/upgrade-clients-udeb.sh $OSCODENAME 2>&1 | tee -a $LOG_FILE if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client" hayErrores=1 fi else echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files." $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot 2>&1 | tee -a $LOG_FILE if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client" hayErrores=1 fi echoAndLog "${FUNCNAME}(): Loading default udeb files." $INSTALL_TARGET/bin/upgrade-clients-udeb.sh 2>&1 | tee -a $LOG_FILE if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client" hayErrores=1 fi fi if [ $hayErrores -eq 0 ]; then echoAndLog "${FUNCNAME}(): Client generation success." else errorAndLog "${FUNCNAME}(): Client generation with errors" fi return $hayErrores } # Configuración básica de servicios de OpenGnSys function openGnsysConfigure() { echoAndLog "${FUNCNAME}(): Copying init files." cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys update-rc.d opengnsys defaults echoAndLog "${FUNCNAME}(): Creating cron files." echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator echoAndLog "${FUNCNAME}(): Creating OpenGnSys config file in \"$INSTALL_TARGET/etc\"." perl -pi -e "s/SERVERIP/$SERVERIP/g; s/DBUSER/$OPENGNSYS_DB_USER/g; s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g; s/DATABASE/$OPENGNSYS_DATABASE/g" $INSTALL_TARGET/etc/ogAdmServer.cfg perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg perl -pi -e "s/SERVERIP/$SERVERIP/g; s/DBUSER/$OPENGNSYS_DB_USER/g; s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g; s/DATABASE/$OPENGNSYS_DATABASE/g" $INSTALL_TARGET/etc/ogAdmAgent.cfg chown root:root $INSTALL_TARGET/etc/{ogAdmServer.cfg,ogAdmAgent.cfg} chmod 600 $INSTALL_TARGET/etc/{ogAdmServer.cfg,ogAdmAgent.cfg} echoAndLog "${FUNCNAME}(): Creating Web Console config file" OPENGNSYS_CONSOLEURL="http://$SERVERIP/opengnsys" perl -pi -e "s/SERVERIP/$SERVERIP/g; s/DBUSER/$OPENGNSYS_DB_USER/g; s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g; s/DATABASE/$OPENGNSYS_DATABASE/g; s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" $INSTALL_TARGET/www/controlacceso.php chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso.php chmod 600 $INSTALL_TARGET/www/controlacceso.php sed -e "s/SERVERIP/$SERVERIP/g" -e "s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg echoAndLog "${FUNCNAME}(): Starting OpenGnSys services." /etc/init.d/opengnsys start } ##################################################################### ####### Función de resumen informativo de la instalación ##################################################################### function installationSummary(){ echo echoAndLog "OpenGnSys Installation Summary" echo "==============================" echoAndLog "Project version: $(cat $INSTALL_TARGET/doc/VERSION.txt 2>/dev/null)" echoAndLog "Installation directory: $INSTALL_TARGET" echoAndLog "Repository directory: $INSTALL_TARGET/images" echoAndLog "TFTP configuracion directory: /var/lib/tftpboot" echoAndLog "DHCP configuracion file: /etc/dhcp3/dhcpd.conf" echoAndLog "NFS configuracion file: /etc/exports" echoAndLog "Web Console URL: $OPENGNSYS_CONSOLEURL" echoAndLog "Web Console admin user: $OPENGNSYS_DB_USER" echoAndLog "Web Console admin password: $OPENGNSYS_DB_PASSWD" echo echoAndLog "Post-Installation Instructions:" echo "===============================" echoAndLog "Review or edit all configuration files." echoAndLog "Insert DHCP configuration data and restart service." echoAndLog "Log-in as Web Console admin user." echoAndLog " - Review default Organization data and assign default user." echoAndLog "Log-in as Web Console organization user." echoAndLog " - Insert OpenGnSys data (rooms, computers, menus, etc)." echo } ##################################################################### ####### Proceso de instalación de OpenGnSys ##################################################################### echoAndLog "OpenGnSys installation begins at $(date)" pushd $WORKDIR # Detener servicios de OpenGnSys, si están activos previamente. [ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop # Detectar parámetros de red por defecto getNetworkSettings if [ $? -ne 0 ]; then errorAndLog "Error reading default network settings." exit 1 fi # Actualizar repositorios apt-get update # Instalación de dependencias (paquetes de sistema operativo). declare -a notinstalled checkDependencies DEPENDENCIES notinstalled if [ $? -ne 0 ]; then installDependencies notinstalled if [ $? -ne 0 ]; then echoAndLog "Error while installing some dependeces, please verify your server installation before continue" exit 1 fi fi # Arbol de directorios de OpenGnSys. openGnsysInstallCreateDirs ${INSTALL_TARGET} if [ $? -ne 0 ]; then errorAndLog "Error while creating directory paths!" exit 1 fi # Si es necesario, descarga el repositorio de código en directorio temporal if [ $USESVN -eq 1 ]; then svnExportCode $SVN_URL if [ $? -ne 0 ]; then errorAndLog "Error while getting code from svn" exit 1 fi else ln -fs "$(dirname $PROGRAMDIR)" opengnsys fi # Compilar código fuente de los servicios de OpenGnSys. servicesCompilation if [ $? -ne 0 ]; then errorAndLog "Error while compiling OpenGnsys services" exit 1 fi # Copiar carpeta Interface entre administración y motor de clonación. InterfaceAdm if [ $? -ne 0 ]; then errorAndLog "Error while copying Interface Administration" exit 1 fi # Configurando tftp tftpConfigure # Configuración NFS nfsConfigure if [ $? -ne 0 ]; then errorAndLog "Error while configuring nfs server!" exit 1 fi # Configuración ejemplo DHCP dhcpConfigure if [ $? -ne 0 ]; then errorAndLog "Error while copying your dhcp server files!" exit 1 fi # Copiar ficheros de servicios OpenGnSys Server. openGnsysCopyServerFiles ${INSTALL_TARGET} if [ $? -ne 0 ]; then errorAndLog "Error while copying the server files!" exit 1 fi # Instalar Base de datos de OpenGnSys Admin. isInArray notinstalled "mysql-server" if [ $? -eq 0 ]; then mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD} else mysqlGetRootPassword fi mysqlTestConnection ${MYSQL_ROOT_PASSWORD} if [ $? -ne 0 ]; then errorAndLog "Error while connection to mysql" exit 1 fi mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} if [ $? -ne 0 ]; then echoAndLog "Creating Web Console database" mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} if [ $? -ne 0 ]; then errorAndLog "Error while creating Web Console database" exit 1 fi else echoAndLog "Web Console database exists, ommiting creation" fi mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER} if [ $? -ne 0 ]; then echoAndLog "Creating user in database" mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}" if [ $? -ne 0 ]; then errorAndLog "Error while creating database user" exit 1 fi fi mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} if [ $? -eq 0 ]; then echoAndLog "Creating tables..." if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE else errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!" exit 1 fi else # Si existe fichero ogBDAdmin-VersLocal-VersRepo.sql; aplicar cambios. INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt) REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt) OPENGNSYS_DB_UPDADE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql" if [ -f $WORKDIR/$OPENGNSYS_DB_UPDADE_FILE ]; then echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION" mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDADE_FILE else echoAndLog "Database unchanged." fi fi # copiando paqinas web installWebFiles # Generar páqinas web de documentación de la API makeDoxygenFiles # creando configuracion de apache2 openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2 if [ $? -ne 0 ]; then errorAndLog "Error configuring Apache for OpenGnSYS Admin" exit 1 fi popd # Creando la estructura del cliente openGnsysClientCreate if [ $? -ne 0 ]; then errorAndLog "Error creating clients" exit 1 fi # Configuración de servicios de OpenGnSys openGnsysConfigure # Mostrar sumario de la instalación e instrucciones de post-instalación. installationSummary #rm -rf $WORKDIR echoAndLog "OpenGnSys installation finished at $(date)"