diff options
author | ramon <ramongomez@us.es> | 2011-12-22 13:38:11 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2011-12-22 13:38:11 +0000 |
commit | c3c7cb3ae6f6600223111a572050f34f2df6fa71 (patch) | |
tree | 96fce1db6bf64fee2845d3a48abcbe07d9937562 /installer | |
parent | 4caea352de0d0a19d4e0a2e2dd04980dd28e6be0 (diff) |
Congelar versión 1.0.2 en tags/opengnsys-1.0.2 (modifica #446).opengnsys-1.0.2
git-svn-id: https://opengnsys.es/svn/tags/opengnsys-1.0.2@2405 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'installer')
-rwxr-xr-x | installer/opengnsys_installer.sh | 571 | ||||
-rwxr-xr-x | installer/opengnsys_uninstall.sh | 8 | ||||
-rwxr-xr-x | installer/opengnsys_update.sh | 142 |
3 files changed, 368 insertions, 353 deletions
diff --git a/installer/opengnsys_installer.sh b/installer/opengnsys_installer.sh index f910dab1..c6aa77c5 100755 --- a/installer/opengnsys_installer.sh +++ b/installer/opengnsys_installer.sh @@ -1,49 +1,38 @@ #!/bin/bash ##################################################################### -####### Script instalador OpenGnsys +####### Script instalador OpenGnSys ####### autor: Luis Guillén <lguillen@unizar.es> ##################################################################### -#### AVISO: Editar configuración de acceso por defecto a la Base de Datos. +#### 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 +OPENGNSYS_DB_USER="usuog" # Usuario de acceso a la base de datos +OPENGNSYS_DB_PASSWD="passusuog" # Clave de acceso a la base de datos +OPENGNSYS_CLIENT_PASSWD="og" # Clave de acceso del cliente + #### AVISO: NO EDITAR. -#### configuración de acceso smb para clientes OG. -OPENGNSYS_CLIENT_USER="opengnsys" # Nombre del usuario -OPENGNSYS_CLIENT_PASSWD="og" # Clave del usuario opengnsys +OPENGNSYS_DATABASE="ogAdmBD" # Nombre de la base datos +OPENGNSYS_CLIENT_USER="opengnsys" # Usuario del cliente para acceso remoto # Sólo ejecutable por usuario root -if [ "$(whoami)" != 'root' ] -then +if [ "$(whoami)" != 'root' ]; then echo "ERROR: this program must run under root privileges!!" exit 1 fi -# Detectar sistema operativo del servidor (debe soportar LSB). -OSDISTRIB=$(lsb_release -is 2>/dev/null) -# Array con las dependencias que deben estar instaladas, según de la distribución detectada. -case "$OSDISTRIB" in - Ubuntu) DEPENDENCIES=( subversion apache2 php5 libapache2-mod-php5 mysql-server php5-mysql nfs-kernel-server dhcp3-server bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential g++-multilib libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent samba unzip netpipes debootstrap schroot squashfs-tools ) - ;; - *) echo "ERROR: Distribution not supported by OpenGnSys." - exit 1 ;; -esac - # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). PROGRAMDIR=$(readlink -e $(dirname "$0")) OPENGNSYS_SERVER="www.opengnsys.es" if [ -d "$PROGRAMDIR/../installer" ]; then - USESVN=0 + USESVN=0 else - USESVN=1 + USESVN=1 fi SVN_URL="http://$OPENGNSYS_SERVER/svn/trunk/" @@ -58,26 +47,98 @@ OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogAdmBD.sql ##################################################################### +####### Funciones de configuración +##################################################################### + +# Generar variables de configuración del instalador +# Variables globales: +# - OSDISTRIB, OSCODENAME - datos de la distribución Linux +# - DEPENDENCIES - array de dependencias que deben estar instaladas +# - UPDATEPKGLIST, INSTALLPKGS, CHECKPKGS - comandos para gestión de paquetes +# - APACHEINIT, APACHECFGDIR, APACHEUSER, APACHEGROUP - arranque y configuración de Apache +# - ENABLEMOD, ENABLESITE - habilitar módulo Apache y sitio web +# - DHCPINIT, DHCPCFGDIR - arranque y configuración de DHCP +# - SAMBAINIT, SAMBACFGDIR - arranque y configuración de Samba +# - TFTPCFGDIR - configuración de TFTP +function autoConfigure() +{ +# Detectar sistema operativo del servidor (debe soportar LSB). +OSDISTRIB=$(lsb_release -is 2>/dev/null) +OSCODENAME=$(lsb_release -cs 2>/dev/null) + +# Configuración según la distribución de Linux. +case "$OSDISTRIB" in + Ubuntu) DEPENDENCIES=( subversion apache2 php5 libapache2-mod-php5 mysql-server php5-mysql isc-dhcp-server bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential g++-multilib libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent samba unzip netpipes debootstrap schroot squashfs-tools ) + UPDATEPKGLIST="apt-get update" + INSTALLPKG="apt-get -y install --force-yes" + CHECKPKG="dpkg -s \$package 2>/dev/null | grep Status | grep -qw install" + APACHEINIT=/etc/init.d/apache2 + APACHECFGDIR=/etc/apache2 + APACHEUSER="www-data" + APACHEGROUP="www-data" + ENABLEMOD="a2enmod" + ENABLESITE="a2ensite" + DHCPINIT=/etc/init.d/isc-dhcp-server + DHCPCFGDIR=/etc/dhcp + SAMBAINIT=/etc/init.d/smbd + SAMBACFGDIR=/etc/samba + TFTPCFGDIR=/var/lib/tftpboot + ;; + "") echo "ERROR: Unknown Linux distribution, please install \"lsb_release\" command." + exit 1 ;; + *) echo "ERROR: Distribution not supported by OpenGnSys." + exit 1 ;; +esac +} + +# Cargar lista de paquetes del sistema y actualizar algunas variables de configuración +# dependiendo de la versión instalada. +function updatePackageList() +{ +local DHCPVERSION + +# Si es necesario, actualizar la lista de paquetes disponibles. +[ -n "$UPDATEPKGLIST" ] && eval $UPDATEPKGLIST + +# Configuración personallizada de algunos paquetes. +case "$OSDISTRIB" in + Ubuntu) # Postconfiguación personalizada para Ubuntu. + # Configuración para DHCP v3. + DHCPVERSION=$(apt-cache show dhcp.?-server$ | \ + awk '/Version/ {print substr($2,1,1);}' | \ + sort -n | tail -1) + if [ $DHCPVERSION = 3 ]; then + DEPENDENCIES=${DEPENDENCIES[@]/isc-dhcp-server/dhcp3-server} + DHCPINIT=/etc/init.d/dhcp3-server + DHCPCFGDIR=/etc/dhcp3 + fi + ;; +esac +} + + +##################################################################### ####### Algunas funciones útiles de propósito general: ##################################################################### + function getDateTime() { - date "+%Y%m%d-%H%M%S" + 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 + echo "$1" + local DATETIME=`getDateTime` + echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE } function errorAndLog() { - echo "ERROR: $1" - FECHAHORA=`getDateTime` - echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE + echo "ERROR: $1" + local DATETIME=`getDateTime` + echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE } # comprueba si el elemento pasado en $2 esta en el array $1 @@ -123,7 +184,7 @@ function checkPackage() exit 1 fi echoAndLog "${FUNCNAME}(): checking if package $package exists" - dpkg -s $package &>/dev/null | grep Status | grep -qw install + eval $CHECKPKG if [ $? -eq 0 ]; then echoAndLog "${FUNCNAME}(): package $package exists" return 0 @@ -199,8 +260,8 @@ function installDependencies() OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND export DEBIAN_FRONTEND=noninteractive - echoAndLog "${FUNCNAME}(): now ${string_deps} will be installed" - apt-get -y install --force-yes ${string_deps} + echoAndLog "${FUNCNAME}(): now $string_deps will be installed" + eval $INSTALLPKG $string_deps if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error installing dependencies" return 1 @@ -219,25 +280,25 @@ function backupFile() exit 1 fi - local fichero=$1 - local fecha=`date +%Y%m%d` + local file="$1" + local dateymd=`date +%Y%m%d` - if [ ! -f $fichero ]; then - errorAndLog "${FUNCNAME}(): file $fichero doesn't exists" + if [ ! -f "$file" ]; then + errorAndLog "${FUNCNAME}(): file $file doesn't exists" return 1 fi - echoAndLog "${FUNCNAME}(): realizando backup de $fichero" + echoAndLog "${FUNCNAME}(): making $file backup" # realiza una copia de la última configuración como last - cp -p $fichero "${fichero}-LAST" + cp -a "$file" "${file}-LAST" # si para el día no hay backup lo hace, sino no - if [ ! -f "${fichero}-${fecha}" ]; then - cp -p $fichero "${fichero}-${fecha}" + if [ ! -f "${file}-${dateymd}" ]; then + cp -a "$file" "${file}-${dateymd}" fi - echoAndLog "${FUNCNAME}(): backup realizado" + echoAndLog "${FUNCNAME}(): $file backup success" } ##################################################################### @@ -369,6 +430,8 @@ function mysqlImportSqlFileToDb() local database="$2" local sqlfile="$3" local tmpfile=$(mktemp) + local i=0 + local dev="" local status if [ ! -f $sqlfile ]; then @@ -376,10 +439,17 @@ function mysqlImportSqlFileToDb() return 1 fi - echoAndLog "${FUNCNAME}(): importing sql file to ${database}..." + 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 + for dev in ${DEVICE[*]}; do + if [ "${DEVICE[i]} == $DEFAULTDEV" ]; then + sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ + -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ + -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ + $sqlfile > $tmpfile + fi + let i++ + done mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $tmpfile status=$? rm -f $tmpfile @@ -507,29 +577,39 @@ function checkNetworkConnection() # Obtener los parámetros de red de la interfaz por defecto. function getNetworkSettings() { - # Variables globales definidas: - # - SERVERIP: IP local del servidor. - # - NETIP: IP de la red. - # - NETMASK: máscara de red. - # - NETBROAD: IP de difusión de la red. - # - ROUTERIP: IP del router. - # - DNSIP: IP del servidor DNS. - - local MAINDEV - - echoAndLog "${FUNCNAME}(): Detecting default network parameters." - MAINDEV=$(ip -o link show up | awk '!/loopback/ {d=d$2} END {sub(/:.*/,"",d); print d}') - if [ -z "$MAINDEV" ]; then - errorAndLog "${FUNCNAME}(): Network device not detected." + # Arrays globales definidas: + # - DEVICE: nombres de dispositivos de red activos. + # - SERVERIP: IPs locales del servidor. + # - NETIP: IPs de redes. + # - NETMASK: máscaras de red. + # - NETBROAD: IPs de difusión de redes. + # - ROUTERIP: IPs de routers. + # Otras variables globales: + # - DEFAULTDEV: dispositivo de red por defecto. + # - DNSIP: IP del servidor DNS principal. + + local i=0 + local dev="" + + echoAndLog "${FUNCNAME}(): Detecting network parameters." + DEVICE=( $(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}') ) + if [ -z "$DEVICE" ]; then + errorAndLog "${FUNCNAME}(): Network devices not detected." exit 1 fi - SERVERIP=$(ip -o addr show dev $MAINDEV | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}') - NETMASK=$(LANG=C ifconfig $MAINDEV | awk '/Mask/ {sub(/.*:/,"",$4); print $4}') - NETBROAD=$(ip -o addr show dev $MAINDEV | awk '$3~/inet$/ {print ($6)}') - NETIP=$(netstat -nr | grep $MAINDEV | awk '$1!~/0\.0\.0\.0/ {if (n=="") n=$1} END {print n}') - ROUTERIP=$(netstat -nr | awk '$1~/0\.0\.0\.0/ {print $2}') + for dev in ${DEVICE[*]}; do + SERVERIP[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}') + if [ -n "${SERVERIP[i]}" ]; then + NETMASK[i]=$(LANG=C ifconfig $dev | awk '/Mask/ {sub(/.*:/,"",$4); print $4}') + NETBROAD[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {print ($6)}') + NETIP[i]=$(netstat -nr | awk -v d="$dev" '$1!~/0\.0\.0\.0/&&$8==d {if (n=="") n=$1} END {print n}') + ROUTERIP[i]=$(netstat -nr | awk -v d="$dev" '$1~/0\.0\.0\.0/&&$8==d {print $2}') + DEFAULTDEV=${DEFAULTDEV:-"$dev"} + let i++ + fi + done DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1) - if [ -z "$NETIP" -o -z "$NETMASK" ]; then + if [ -z "${NETIP}[*]" -o -z "${NETMASK[*]}" ]; then errorAndLog "${FUNCNAME}(): Network not detected." exit 1 fi @@ -537,11 +617,11 @@ function getNetworkSettings() # Variables de ejecución de Apache # - APACHE_RUN_USER # - APACHE_RUN_GROUP - if [ -f /etc/apache2/envvars ]; then - source /etc/apache2/envvars + if [ -f $APACHECFGDIR/envvars ]; then + source $APACHECFGDIR/envvars fi - APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"} - APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"} + APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"} + APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"} } @@ -551,18 +631,16 @@ function getNetworkSettings() function tftpConfigure() { - local basetftp=/var/lib/tftpboot - echoAndLog "${FUNCNAME}(): Configuring TFTP service." # reiniciamos demonio internet ????? porque ???? /etc/init.d/openbsd-inetd start # preparacion contenedor tftpboot - cp -ar /usr/lib/syslinux/ ${basetftp}/syslinux - cp -a /usr/lib/syslinux/pxelinux.0 ${basetftp} + cp -ar /usr/lib/syslinux/ $TFTPCFGDIR/syslinux + cp -a /usr/lib/syslinux/pxelinux.0 $TFTPCFGDIR # prepamos el directorio de la configuracion de pxe - mkdir -p ${basetftp}/pxelinux.cfg - cat > ${basetftp}/pxelinux.cfg/default <<EOF + mkdir -p $TFTPCFGDIR/pxelinux.cfg + cat > $TFTPCFGDIR/pxelinux.cfg/default <<EOF DEFAULT syslinux/vesamenu.c32 MENU TITLE Aplicacion GNSYS @@ -589,122 +667,20 @@ function testPxe () ######################################################################## -## Configuracion servicio NFS -######################################################################## - -# ADVERTENCIA: usa variables globales NETIP y NETMASK! -function nfsConfigure() -{ - echoAndLog "${FUNCNAME}(): Config nfs server." - - backupFile /etc/exports - - nfsAddExport /opt/opengnsys/client ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error while adding nfs client config" - return 1 - fi - - nfsAddExport /opt/opengnsys/images ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync,crossmnt - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error while adding nfs images config" - return 1 - fi - - nfsAddExport /opt/opengnsys/log/clients ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error while adding logging client config" - return 1 - fi - - nfsAddExport /var/lib/tftpboot ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error while adding second filesystem for the pxe ogclient" - return 1 - fi - - /etc/init.d/nfs-kernel-server restart - - exportfs -va - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error while configure exports" - return 1 - fi - - echoAndLog "${FUNCNAME}(): Added NFS configuration to file \"/etc/exports\"." - return 0 -} - - -# ejemplos: -#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0:ro,no_subtree_check,no_root_squash,sync -#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0 -#nfsAddExport /opt/opengnsys 80.20.2.1:ro 192.123.32.2:rw -function nfsAddExport() -{ - if [ $# -lt 2 ]; then - errorAndLog "${FUNCNAME}(): invalid number of parameters" - exit 1 - fi - - if [ ! -f /etc/exports ]; then - errorAndLog "${FUNCNAME}(): /etc/exports don't exists" - return 1 - fi - - local export="${1}" - local contador=0 - local cadenaexport - - grep "^${export}" /etc/exports > /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 Samba ######################################################################## function smbConfigure() { echoAndLog "${FUNCNAME}(): Configuring Samba service." - backupFile /etc/samba/smb.conf + backupFile $SAMBACFGDIR/smb.conf # Copiar plantailla de recursos para OpenGnSys sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ - $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > /etc/samba/smb-og.conf + $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf # Configurar y recargar Samba" - perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnSys Samba Server/; s/^\; *include \=.*$/ include \= \/etc\/samba\/smb-og.conf/" /etc/samba/smb.conf - /etc/init.d/smbd restart + perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnSys Samba Server/; s/^\; *include \=.*$/ include \= \/etc\/samba\/smb-og.conf/" $SAMBACFGDIR/smb.conf + $SAMBAINIT restart if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while configure Samba" return 1 @@ -725,28 +701,31 @@ function dhcpConfigure() { echoAndLog "${FUNCNAME}(): Sample DHCP configuration." - local DHCPSERVER=/etc/init.d/isc-dhcp-server - DHCPCONFIG=/etc/dhcp/dhcpd.conf - if [ ! -x $DHCPSERVER ]; then - DHCPSERVER=/etc/init.d/dhcp3-server - DHCPCONFIG=/etc/dhcp3/dhcpd.conf - fi - backupFile $DHCPCONFIG - - 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/etc/dhcpd.conf.tmpl > $DHCPCONFIG - if [ $? -ne 0 ]; then + local errcode=0 + local i=0 + local dev="" + + backupFile $DHCPCFGDIR/dhcpd.conf + for dev in ${DEVICE[*]}; do + if [ -n "${SERVERIP[i]}" ]; then + backupFile $DHCPCFGDIR/dhcpd-$dev.conf + sed -e "s/SERVERIP/${SERVERIP[$i]}/g" \ + -e "s/NETIP/${NETIP[$i]}/g" \ + -e "s/NETMASK/${NETMASK[$i]}/g" \ + -e "s/NETBROAD/${NETBROAD[$i]}/g" \ + -e "s/ROUTERIP/${ROUTERIP[$i]}/g" \ + -e "s/DNSIP/$DNSIP/g" \ + $WORKDIR/opengnsys/server/etc/dhcpd.conf.tmpl > $DHCPCFGDIR/dhcpd-$dev.conf || errcode=1 + fi + let i++ + done + if [ $errcode -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while configuring DHCP server" return 1 fi - - $DHCPSERVER restart - echoAndLog "${FUNCNAME}(): Sample DHCP configured in file \"$DHCPCONFIG\"." + ln -f $DHCPCFGDIR/dhcpd-$DEFAULTDEV.conf $DHCPCFGDIR/dhcpd.conf + $DHCPINIT restart + echoAndLog "${FUNCNAME}(): Sample DHCP configured in \"$DHCPCFGDIR\"." return 0 } @@ -793,8 +772,12 @@ function openGnsysInstallWebConsoleApacheConf() echoAndLog "${FUNCNAME}(): creating apache2 config file.." + # Activar HTTPS. + $ENABLESITE default-ssl + $ENABLEMOD ssl + make-ssl-cert generate-default-snakeoil --force-overwrite - # genera configuración + # Genera configuración de consola web. cat > $path_opengnsys_base/etc/apache.conf <<EOF # OpenGnSys Web Console configuration for Apache @@ -806,14 +789,14 @@ Alias /opengnsys ${path_web_console} </Directory> 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 + ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys + $ENABLESITE opengnsys 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 + $APACHEINIT restart return 0 fi } @@ -880,7 +863,7 @@ function createDirs() # Establecer los permisos básicos. echoAndLog "${FUNCNAME}(): setting directory permissions" - chmod -R 775 $path_opengnsys_base/{log/clients,images,tftpboot} + chmod -R 775 $path_opengnsys_base/{log/clients,images} chown -R :$OPENGNSYS_CLIENT_USER $path_opengnsys_base/{log/clients,images} if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while setting permissions" @@ -949,7 +932,7 @@ function servicesCompilation () # Compilar OpenGnSys Server echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server" pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer - make && make install + make && mv ogAdmServer $INSTALL_TARGET/sbin if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server" hayErrores=1 @@ -958,7 +941,7 @@ function servicesCompilation () # Compilar OpenGnSys Repository Manager echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager" pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo - make && make install + make && mv ogAdmRepo $INSTALL_TARGET/sbin if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager" hayErrores=1 @@ -967,7 +950,7 @@ function servicesCompilation () # Compilar OpenGnSys Agent echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent" pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent - make && make install + make && mv ogAdmAgent $INSTALL_TARGET/sbin if [ $? -ne 0 ]; then echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent" hayErrores=1 @@ -1014,13 +997,13 @@ function copyInterfaceAdm () function openGnsysCopyClientFiles() { - local hayErrores=0 + local errstatus=0 echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files." cp -ar $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while copying client estructure" - hayErrores=1 + errstatus=1 fi find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null @@ -1029,76 +1012,27 @@ function openGnsysCopyClientFiles() 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 + errstatus=1 fi - if [ $hayErrores -eq 0 ]; then + if [ $errstatus -eq 0 ]; then echoAndLog "${FUNCNAME}(): client copy files success." else errorAndLog "${FUNCNAME}(): client copy files with errors" fi - return $hayErrores + return $errstatus } - - -# Crear antiguo cliente initrd para OpenGnSys 0.10 -function openGnsysOldClientCreate() -{ - local OSCODENAME - - local hayErrores=0 - - # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto). - 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}(): Old client generation success." - else - errorAndLog "${FUNCNAME}(): Old client generation with errors" - fi - - return $hayErrores -} - - -# Crear cliente OpenGnSys 1.0.1 +# Crear cliente OpenGnSys 1.0.2 function clientCreate() { - local DOWNLOADURL="http://www.opengnsys.es/downloads" - local FILENAME=ogclient-1.0.2-natty-32bit-beta00-rev2046.iso + local DOWNLOADURL="http://$OPENGNSYS_SERVER/downloads" + local FILENAME=ogLive-natty-2.6.38-8-generic-pae-r2303.iso local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME local TMPDIR=/tmp/${FILENAME%.iso} - + echoAndLog "${FUNCNAME}(): Loading Client" # Descargar, montar imagen, copiar cliente ogclient y desmontar. wget $DOWNLOADURL/$FILENAME -O $TARGETFILE @@ -1109,15 +1043,24 @@ function clientCreate() echoAndLog "${FUNCNAME}(): Copying Client files" mkdir -p $TMPDIR mount -o loop,ro $TARGETFILE $TMPDIR - cp -vr $TMPDIR/ogclient $INSTALL_TARGET/tftpboot + cp -avr $TMPDIR/ogclient $INSTALL_TARGET/tftpboot umount $TMPDIR rmdir $TMPDIR + # Asignar la clave cliente para acceso a Samba. + echoAndLog "${FUNCNAME}(): Set client access key" + echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | \ + $INSTALL_TARGET/bin/setsmbpass # Establecer los permisos. find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \; find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \; chown -R :$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/tftpboot/ogclient chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg} + + # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache + cp -arv $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot + cp -arv $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot + echoAndLog "${FUNCNAME}(): Client generation success" } @@ -1125,26 +1068,60 @@ function clientCreate() # Configuración básica de servicios de OpenGnSys function openGnsysConfigure() { + local i=0 + local dev="" + 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 - cp -p $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepoAux /opt/opengnsys/sbin/ + cp -p $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepoAux $INSTALL_TARGET/sbin update-rc.d opengnsys defaults echoAndLog "${FUNCNAME}(): Creating cron files." + echo "* * * * * root [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator echo "5 * * * * root [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker - 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}(): Creating logrotate configuration file." + sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ + $WORKDIR/opengnsys/server/etc/logrotate.tmpl > /etc/logrotate.d/opengnsys + + echoAndLog "${FUNCNAME}(): Creating OpenGnSys config files." + for dev in ${DEVICE[*]}; do + if [ -n "${SERVERIP[i]}" ]; then + sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ + -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ + -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ + -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ + $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer/ogAdmServer.cfg > $INSTALL_TARGET/etc/ogAdmServer-$dev.cfg + sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ + $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo/ogAdmRepo.cfg > $INSTALL_TARGET/etc/ogAdmRepo-$dev.cfg + sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ + -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ + -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ + -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ + $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent/ogAdmAgent.cfg > $INSTALL_TARGET/etc/ogAdmAgent-$dev.cfg + OPENGNSYS_CONSOLEURL="http://${SERVERIP[i]}/opengnsys" + sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ + -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ + -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ + -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ + -e "s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" \ + $INSTALL_TARGET/www/controlacceso.php > $INSTALL_TARGET/www/controlacceso-$dev.php + sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ + -e "s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" \ + $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient-$dev.cfg + fi + let i++ + done + ln -f $INSTALL_TARGET/etc/ogAdmServer-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmServer.cfg + ln -f $INSTALL_TARGET/etc/ogAdmRepo-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmRepo.cfg + ln -f $INSTALL_TARGET/etc/ogAdmAgent-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmAgent.cfg + ln -f $INSTALL_TARGET/client/etc/ogAdmClient-$DEFAULTDEV.cfg $INSTALL_TARGET/client/etc/ogAdmClient.cfg + ln -f $INSTALL_TARGET/www/controlacceso-$DEFAULTDEV.php $INSTALL_TARGET/www/controlacceso.php + chown root:root $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg + chmod 600 $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg + chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso*.php + chmod 600 $INSTALL_TARGET/www/controlacceso*.php echoAndLog "${FUNCNAME}(): Starting OpenGnSys services." /etc/init.d/opengnsys start } @@ -1169,7 +1146,7 @@ function installationSummary() echoAndLog "Project version: $(cat $VERSIONFILE 2>/dev/null)" echoAndLog "Installation directory: $INSTALL_TARGET" echoAndLog "Repository directory: $INSTALL_TARGET/images" - echoAndLog "DHCP configuration file: $DHCPCONFIG" + echoAndLog "DHCP configuration directory: $DHCPCFGDIR" echoAndLog "TFTP configuration directory: /var/lib/tftpboot" echoAndLog "Samba configuration directory: /etc/samba" echoAndLog "Web Console URL: $OPENGNSYS_CONSOLEURL" @@ -1196,7 +1173,15 @@ echo echoAndLog "OpenGnSys installation begins at $(date)" pushd $WORKDIR -# Comprobar si hay conexión y detectar parámetros de red por defecto. +# Detectar datos de auto-configuración del instalador. +autoConfigure + +# Detectar parámetros de red y comprobar si hay conexión. +getNetworkSettings +if [ $? -ne 0 ]; then + errorAndLog "Error reading default network settings." + exit 1 +fi checkNetworkConnection if [ $? -ne 0 ]; then errorAndLog "Error connecting to server. Causes:" @@ -1205,17 +1190,12 @@ if [ $? -ne 0 ]; then errorAndLog " - Server is temporally down, try agian later." exit 1 fi -getNetworkSettings -if [ $? -ne 0 ]; then - errorAndLog "Error reading default network settings." - exit 1 -fi # Detener servicios de OpenGnSys, si están activos previamente. [ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop # Actualizar repositorios -apt-get update +updatePackageList # Instalación de dependencias (paquetes de sistema operativo). declare -a notinstalled @@ -1263,14 +1243,6 @@ fi # Configurando tftp tftpConfigure -# Configuración NFS -#### (descomentar las siguientes líneas para exportar servicios por NFS) -#nfsConfigure -#if [ $? -ne 0 ]; then -# errorAndLog "Error while configuring nfs server!" -# exit 1 -#fi - # Configuración Samba smbConfigure if [ $? -ne 0 ]; then @@ -1371,14 +1343,7 @@ if [ $? -ne 0 ]; then errorAndLog "Error creating client structure" fi -# Crear la estructura del antiguo cliente initrd de OpenGnSys 0.10 -#### (descomentar las siguientes líneas para generar cliente initrd) -#openGnsysOldClientCreate -#if [ $? -ne 0 ]; then -# errorAndLog "Warning: cannot create old initrd client" -#fi - -# Crear la estructura del cliente de OpenGnSys 1.0 +# Crear la estructura del cliente de OpenGnSys clientCreate if [ $? -ne 0 ]; then errorAndLog "Error creating client" diff --git a/installer/opengnsys_uninstall.sh b/installer/opengnsys_uninstall.sh index 0ee3b947..f9b5ce0e 100755 --- a/installer/opengnsys_uninstall.sh +++ b/installer/opengnsys_uninstall.sh @@ -11,6 +11,7 @@ DBUSER="usuog" # Usuario de acceso a la base de datos # Variables. OPENGNSYS="/opt/opengnsys" # Directorio de OpenGnSys OGIMG="images" # Directorio de imágenes del repositorio +CLIENTUSER="opengnsys" # Usuario de acceso del cliente # Parar servicio. echo "Uninstalling OpenGnSys services." @@ -37,6 +38,10 @@ if test $DROP; then mysql -u root -p"$MYSQLROOT" <<<"DROP USER '$DBUSER';" 2>/dev/null mysql -u root -p"$MYSQLROOT" <<<"DROP USER '$DBUSER'@'localhost';" 2>/dev/null fi +# Quitar configuración específica de Apache. +a2dissite opengnsys +rm -f /etc/apache2/{sites-available,sites-enabled}/opengnsys* +/etc/init.d/apache2 reload # Eliminar ficheros. echo "Deleting OpenGnSys files." for dir in $OPENGNSYS/*; do @@ -48,6 +53,9 @@ rm -f /etc/init.d/opengnsys /etc/default/opengnsys /var/log/opengnsys # Comentar recursos de OpenGnSys en Samba. perl -pi -e "s/^ *include \= \/etc\/samba\/smb-og.conf/\; include \= \/etc\/samba\/smb-og.conf/" /etc/samba/smb.conf /etc/init.d/smbd restart +# Eliminar usuario de OpenGnSys. +smbpasswd -x $CLIENTUSER +userdel $CLIENTUSER # Tareas manuales a realizar después de desinstalar. echo "Manual tasks:" echo "- You may stop or uninstall manually all other services" diff --git a/installer/opengnsys_update.sh b/installer/opengnsys_update.sh index 3c46ce57..ad376290 100755 --- a/installer/opengnsys_update.sh +++ b/installer/opengnsys_update.sh @@ -25,8 +25,7 @@ OPENGNSYS_CLIENTUSER="opengnsys" # Usuario Samba # Sólo ejecutable por usuario root -if [ "$(whoami)" != 'root' ] -then +if [ "$(whoami)" != 'root' ]; then echo "ERROR: this program must run under root privileges!!" exit 1 fi @@ -43,12 +42,12 @@ PROGRAMNAME=$(basename "$0") DEPS="build-essential g++-multilib rsync ctorrent samba unzip netpipes debootstrap schroot squashfs-tools" OPENGNSYS_SERVER="www.opengnsys.es" if [ -d "$PROGRAMDIR/../installer" ]; then - USESVN=0 + USESVN=0 else - USESVN=1 - DEPS="$DEPS subversion" + USESVN=1 + DEPS="$DEPS subversion" fi -SVN_URL="http://$OPENGNSYS_SERVER/svn/trunk/" +SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/" WORKDIR=/tmp/opengnsys_update mkdir -p $WORKDIR @@ -131,11 +130,11 @@ function backupFile() echoAndLog "${FUNCNAME}(): Making $fichero back-up" # realiza una copia de la última configuración como last - cp -p $fichero "${fichero}-LAST" + cp -a $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}" + cp -a $fichero "${fichero}-${fecha}" fi } @@ -151,7 +150,7 @@ function restoreFile() echoAndLog "${FUNCNAME}(): restoring file $fichero" if [ -f "${fichero}-LAST" ]; then - cp -p "$fichero-LAST" "$fichero" + cp -a "$fichero-LAST" "$fichero" fi } @@ -265,18 +264,6 @@ function checkNetworkConnection() ####### Funciones específicas de la instalación de Opengnsys ##################################################################### -# Copiar ficheros de arranque de los servicios del sistema de OpenGnSys -function updateServicesStart() -{ - echoAndLog "${FUNCNAME}(): Updating OpenGnSys init file ..." - cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys - if [ $? != 0 ]; then - errorAndLog "${FUNCNAME}(): Error updating /etc/init.d/opengnsys" - exit 1 - fi - echoAndLog "${FUNCNAME}(): init file updated successfully." -} - # Actualizar cliente OpenGnSys function updateClientFiles() { @@ -289,7 +276,7 @@ function updateClientFiles() find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null echoAndLog "${FUNCNAME}(): Updating OpenGnSys Cloning Engine files." - rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin + rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while updating engine files" exit 1 @@ -298,14 +285,27 @@ function updateClientFiles() echoAndLog "${FUNCNAME}(): client files update success." } -# Exportar nombre de usuario y grupo del servicio Apache. -function getApacheUser() +# Configurar HTTPS y exportar usuario y grupo del servicio Apache. +function apacheConfiguration () { - # Variables de ejecución de Apache + local APACHECONF=/etc/apache2 + + # Activar HTTPS, si es necesario. + if [ -e $APACHECONF/sites-available/opengnsys.conf ]; then + echoAndLog "${FUNCNAME}(): Configuring HTTPS access..." + mv $APACHECONF/sites-available/opengnsys.conf $APACHECONF/sites-available/opengnsys + a2ensite default-ssl + a2enmod ssl + a2dissite opengnsys.conf + a2ensite opengnsys + /etc/init.d/apache2 restart + fi + + # Variables de ejecución de Apache. # - APACHE_RUN_USER # - APACHE_RUN_GROUP - if [ -f /etc/apache2/envvars ]; then - source /etc/apache2/envvars + if [ -f $APACHECONF/envvars ]; then + source $APACHECONF/envvars fi APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"} APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"} @@ -443,7 +443,29 @@ function updateServerFiles() fi done popd >/dev/null + NEWFILES="" # Ficheros de configuración que han cambiado de formato. + if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then + echoAndLog "${FUNCNAME}(): updating DHCP files" + perl -pi -e 's/pxelinux.0/grldr/' /etc/dhcp*/dhcpd*.conf + for i in isc-dhcp-server dhcpd3-server dhcpd; do + [ -f /etc/init.d/$i ] && /etc/init.d/$i restart + done + NEWFILES="/etc/dhcp*/dhcpd*.conf" + fi + if ! diff --quiet $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys 2>/dev/null; then + echoAndLog "${FUNCNAME}(): updating new init file" + backupFile /etc/init.d/opengnsys + cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys + NEWFILES="$NEWFILES /etc/init.d/opengnsys" + fi + if grep -q "UrlMsg=.*msgbrowser.php" $INSTALL_TARGET/client/etc/ogAdmClient.cfg 2>/dev/null; then + echoAndLog "${FUNCNAME}(): updating new client config file" + backupFile $INSTALL_TARGET/client/etc/ogAdmClient.cfg + perl -pi -e 's!UrlMsg=.*msgbrowser\.php!UrlMsg=http://localhost/cgi-bin/httpd-log\.sh!g' $INSTALL_TARGET/client/etc/ogAdmClient.cfg + NEWFILES="$NEWFILES $INSTALL_TARGET/client/etc/ogAdmClient.cfg" + fi echoAndLog "${FUNCNAME}(): updating cron files" + echo "* * * * * root [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator echoAndLog "${FUNCNAME}(): server files updated successfully." } @@ -506,17 +528,20 @@ function compileServices() # Actualizar nuevo cliente para OpenGnSys 1.0 function updateClient() { - local DOWNLOADURL="http://www.opengnsys.es/downloads" - local FILENAME=ogclient-1.0.2-natty-32bit-beta00-rev2046.iso + local DOWNLOADURL="http://$OPENGNSYS_SERVER/downloads" + local FILENAME=ogLive-natty-2.6.38-8-generic-pae-r2303.iso local SOURCEFILE=$DOWNLOADURL/$FILENAME local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME local SOURCELENGTH local TARGETLENGTH local TMPDIR=/tmp/${FILENAME%.iso} + local OGINITRD=$INSTALL_TARGET/tftpboot/ogclient/oginitrd.img + local SAMBAPASS # Comprobar si debe actualizarse el cliente. SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}') TARGETLENGTH=$(ls -l $TARGETFILE 2>/dev/null | awk '{print $5}') + [ -z $TARGETLENGTH ] && TARGETLENGTH=0 if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then echoAndLog "${FUNCNAME}(): Loading Client" wget $DOWNLOADURL/$FILENAME -O $TARGETFILE @@ -524,23 +549,40 @@ function updateClient() errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client" return 1 fi + # Obtener la clave actual de acceso a Samba para restaurarla. + if [ -f $OGINITRD ]; then + SAMBAPASS=$(gzip -dc $OGINITRD | \ + cpio -i --to-stdout scripts/ogfunctions 2>&1 | \ + grep "^[ ]*OPTIONS=" | \ + sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/') + fi + # Montar la imagen ISO del ogclient, actualizar ficheros y desmontar. + echoAndLog "${FUNCNAME}(): Updatting ogclient files" + mkdir -p $TMPDIR + mount -o loop,ro $TARGETFILE $TMPDIR + rsync -irlt $TMPDIR/ogclient $INSTALL_TARGET/tftpboot + umount $TMPDIR + rmdir $TMPDIR + # Recuperar la clave de acceso a Samba. + if [ -n "$SAMBAPASS" ]; then + echoAndLog "${FUNCNAME}(): Restoring client access key" + echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | \ + $INSTALL_TARGET/bin/setsmbpass + fi + # Establecer los permisos. + find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \; + find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \; + chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient + chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg} + + # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache + cp -arv $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot + cp -arv $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot + + echoAndLog "${FUNCNAME}(): Client update successfully" else - echoAndLog "${FUNCNAME}(): Client is already loaded" + echoAndLog "${FUNCNAME}(): Client is already updated" fi - # Montar la imagen ISO del ogclient, actualizar ficheros y desmontar. - echoAndLog "${FUNCNAME}(): Updating ogclient files" - mkdir -p $TMPDIR - mount -o loop,ro $TARGETFILE $TMPDIR - rsync -irlt $TMPDIR/ogclient $INSTALL_TARGET/tftpboot - umount $TMPDIR - rmdir $TMPDIR - - # Establecer los permisos. - find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \; - find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \; - chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient - chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg} - echoAndLog "${FUNCNAME}(): Client update successfully" } # Resumen de actualización. @@ -555,8 +597,11 @@ function updateSummary() echo echoAndLog "OpenGnSys Update Summary" - echo "========================" - echoAndLog "Project version: $(cat $VERSIONFILE)" + echo "========================" + echoAndLog "Project version: $(cat $VERSIONFILE)" + if [ -n "$NEWFILES" ]; then + echoAndLog "Check the new config files: $(echo $NEWFILES)" + fi echo } @@ -639,7 +684,7 @@ updateClientFiles updateInterfaceAdm # Actualizar páqinas web -getApacheUser +apacheConfiguration updateWebFiles if [ $? -ne 0 ]; then errorAndLog "Error updating OpenGnSys Web Admin files" @@ -658,9 +703,6 @@ if [ $? -ne 0 ]; then exit 1 fi -# Actualizamos el fichero que arranca los servicios de OpenGnSys -updateServicesStart - # Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes if [ -f /tmp/dstate ]; then rm -f /tmp/dstate |