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