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