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