[a01156a] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | ##################################################################### |
---|
| 4 | ####### Script instalador OpenGnsys |
---|
| 5 | ####### autor: Luis Guillén <lguillen@unizar.es> |
---|
| 6 | ##################################################################### |
---|
| 7 | |
---|
| 8 | |
---|
[1e7eaab] | 9 | |
---|
[8fc9552] | 10 | #### AVISO: Editar configuración de acceso por defecto a la Base de Datos. |
---|
[4a3cd1f] | 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 | |
---|
[8fc9552] | 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 | |
---|
[4a3cd1f] | 22 | |
---|
[1e7eaab] | 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 | |
---|
[c1e00e4] | 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 | |
---|
[1e7eaab] | 40 | # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). |
---|
[49c6891] | 41 | PROGRAMDIR=$(readlink -e $(dirname "$0")) |
---|
[1e7eaab] | 42 | if [ -d "$PROGRAMDIR/../installer" ]; then |
---|
| 43 | USESVN=0 |
---|
| 44 | else |
---|
| 45 | USESVN=1 |
---|
[8fc9552] | 46 | SVN_URL=http://www.opengnsys.es/svn/branches/version1.0 |
---|
[1e7eaab] | 47 | fi |
---|
| 48 | |
---|
[a01156a] | 49 | WORKDIR=/tmp/opengnsys_installer |
---|
[1e7eaab] | 50 | mkdir -p $WORKDIR |
---|
| 51 | |
---|
| 52 | INSTALL_TARGET=/opt/opengnsys |
---|
[13a01a7] | 53 | LOG_FILE=/tmp/opengnsys_installation.log |
---|
[a01156a] | 54 | |
---|
[4a3cd1f] | 55 | # Base de datos |
---|
[7510561] | 56 | OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/ogAdmBD.sql |
---|
[3aaf91d] | 57 | |
---|
[a01156a] | 58 | |
---|
| 59 | ##################################################################### |
---|
| 60 | ####### Algunas funciones útiles de propósito general: |
---|
| 61 | ##################################################################### |
---|
[13a01a7] | 62 | function getDateTime() |
---|
[a01156a] | 63 | { |
---|
| 64 | echo `date +%Y%m%d-%H%M%S` |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | # Escribe a fichero y muestra por pantalla |
---|
[13a01a7] | 68 | function echoAndLog() |
---|
[a01156a] | 69 | { |
---|
| 70 | echo $1 |
---|
| 71 | FECHAHORA=`getDateTime` |
---|
| 72 | echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
| 73 | } |
---|
| 74 | |
---|
[13a01a7] | 75 | function errorAndLog() |
---|
[a01156a] | 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 |
---|
[13a01a7] | 83 | function isInArray() |
---|
[a01156a] | 84 | { |
---|
| 85 | if [ $# -ne 2 ]; then |
---|
[13a01a7] | 86 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 87 | exit 1 |
---|
| 88 | fi |
---|
| 89 | |
---|
[13a01a7] | 90 | echoAndLog "${FUNCNAME}(): checking if $2 is in $1" |
---|
[a01156a] | 91 | local deps |
---|
[5c33840] | 92 | eval "deps=( \"\${$1[@]}\" )" |
---|
[a01156a] | 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 |
---|
[13a01a7] | 106 | echoAndLog "${FUNCNAME}(): $elemento NOT found in array" |
---|
[a01156a] | 107 | fi |
---|
| 108 | |
---|
| 109 | return $is_in_array |
---|
| 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | ##################################################################### |
---|
| 114 | ####### Funciones de manejo de paquetes Debian |
---|
| 115 | ##################################################################### |
---|
| 116 | |
---|
[13a01a7] | 117 | function checkPackage() |
---|
[a01156a] | 118 | { |
---|
| 119 | package=$1 |
---|
| 120 | if [ -z $package ]; then |
---|
[73cfa0a] | 121 | errorAndLog "${FUNCNAME}(): parameter required" |
---|
[a01156a] | 122 | exit 1 |
---|
| 123 | fi |
---|
[73cfa0a] | 124 | echoAndLog "${FUNCNAME}(): checking if package $package exists" |
---|
[da8db11] | 125 | dpkg -s $package &>/dev/null | grep Status | grep -qw install |
---|
[a01156a] | 126 | if [ $? -eq 0 ]; then |
---|
[73cfa0a] | 127 | echoAndLog "${FUNCNAME}(): package $package exists" |
---|
[a01156a] | 128 | return 0 |
---|
| 129 | else |
---|
[73cfa0a] | 130 | echoAndLog "${FUNCNAME}(): package $package doesn't exists" |
---|
[a01156a] | 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 |
---|
[13a01a7] | 138 | function checkDependencies() |
---|
[a01156a] | 139 | { |
---|
| 140 | if [ $# -ne 2 ]; then |
---|
[73cfa0a] | 141 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 142 | exit 1 |
---|
| 143 | fi |
---|
| 144 | |
---|
[73cfa0a] | 145 | echoAndLog "${FUNCNAME}(): checking dependences" |
---|
[a01156a] | 146 | uncompletedeps=0 |
---|
| 147 | |
---|
| 148 | # copia local del array del parametro 1 |
---|
| 149 | local deps |
---|
[5c33840] | 150 | eval "deps=( \"\${$1[@]}\" )" |
---|
[a01156a] | 151 | |
---|
| 152 | declare -a local_notinstalled |
---|
[5c33840] | 153 | |
---|
[a01156a] | 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 |
---|
[73cfa0a] | 170 | echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps" |
---|
[a01156a] | 171 | return $uncompletedeps |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | # Recibe un array con las dependencias y lo instala |
---|
[13a01a7] | 175 | function installDependencies() |
---|
[a01156a] | 176 | { |
---|
| 177 | if [ $# -ne 1 ]; then |
---|
[813f617] | 178 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 179 | exit 1 |
---|
| 180 | fi |
---|
[813f617] | 181 | echoAndLog "${FUNCNAME}(): installing uncompleted dependencies" |
---|
[a01156a] | 182 | |
---|
| 183 | # copia local del array del parametro 1 |
---|
| 184 | local deps |
---|
[5c33840] | 185 | eval "deps=( \"\${$1[@]}\" )" |
---|
[a01156a] | 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 |
---|
[813f617] | 194 | errorAndLog "${FUNCNAME}(): array of dependeces is empty" |
---|
[a01156a] | 195 | exit 1 |
---|
| 196 | fi |
---|
| 197 | |
---|
| 198 | OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND |
---|
| 199 | export DEBIAN_FRONTEND=noninteractive |
---|
| 200 | |
---|
[813f617] | 201 | echoAndLog "${FUNCNAME}(): now ${string_deps} will be installed" |
---|
[a01156a] | 202 | apt-get -y install --force-yes ${string_deps} |
---|
| 203 | if [ $? -ne 0 ]; then |
---|
[813f617] | 204 | errorAndLog "${FUNCNAME}(): error installing dependencies" |
---|
[a01156a] | 205 | return 1 |
---|
| 206 | fi |
---|
| 207 | |
---|
| 208 | DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND |
---|
[813f617] | 209 | echoAndLog "${FUNCNAME}(): dependencies installed" |
---|
[a01156a] | 210 | } |
---|
| 211 | |
---|
[13a01a7] | 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 | |
---|
[a01156a] | 242 | ##################################################################### |
---|
| 243 | ####### Funciones para el manejo de bases de datos |
---|
| 244 | ##################################################################### |
---|
| 245 | |
---|
| 246 | # This function set password to root |
---|
[13a01a7] | 247 | function mysqlSetRootPassword() |
---|
[a01156a] | 248 | { |
---|
| 249 | if [ $# -ne 1 ]; then |
---|
[813f617] | 250 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 251 | exit 1 |
---|
| 252 | fi |
---|
| 253 | |
---|
| 254 | local root_mysql=$1 |
---|
[813f617] | 255 | echoAndLog "${FUNCNAME}(): setting root password in MySQL server" |
---|
[a01156a] | 256 | /usr/bin/mysqladmin -u root password ${root_mysql} |
---|
| 257 | if [ $? -ne 0 ]; then |
---|
[813f617] | 258 | errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server" |
---|
[a01156a] | 259 | return 1 |
---|
| 260 | fi |
---|
[813f617] | 261 | echoAndLog "${FUNCNAME}(): root password saved!" |
---|
[a01156a] | 262 | return 0 |
---|
| 263 | } |
---|
| 264 | |
---|
[892606b9] | 265 | # Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente |
---|
[13a01a7] | 266 | function mysqlGetRootPassword(){ |
---|
[892606b9] | 267 | local pass_mysql |
---|
| 268 | local pass_mysql2 |
---|
[7c54b49] | 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 |
---|
[892606b9] | 289 | fi |
---|
| 290 | } |
---|
| 291 | |
---|
[a01156a] | 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 |
---|
[c5ce04c] | 363 | errorAndLog "${FNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 364 | exit 1 |
---|
| 365 | fi |
---|
| 366 | |
---|
[c4321ae] | 367 | local root_password="$1" |
---|
| 368 | local database="$2" |
---|
| 369 | local sqlfile="$3" |
---|
| 370 | local tmpfile=$(mktemp) |
---|
| 371 | local status |
---|
[a01156a] | 372 | |
---|
| 373 | if [ ! -f $sqlfile ]; then |
---|
[c5ce04c] | 374 | errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!" |
---|
[a01156a] | 375 | return 1 |
---|
| 376 | fi |
---|
| 377 | |
---|
[c5ce04c] | 378 | echoAndLog "${FUNCNAME}(): importing sql file to ${database}..." |
---|
[c4321ae] | 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 |
---|
[c5ce04c] | 386 | errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database" |
---|
[a01156a] | 387 | return 1 |
---|
| 388 | fi |
---|
[c5ce04c] | 389 | echoAndLog "${FUNCNAME}(): file imported to database $database" |
---|
[a01156a] | 390 | return 0 |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | # Crea la base de datos |
---|
| 394 | function mysqlCreateDb() |
---|
| 395 | { |
---|
| 396 | if [ $# -ne 2 ]; then |
---|
[a555f49] | 397 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 398 | exit 1 |
---|
| 399 | fi |
---|
| 400 | |
---|
| 401 | local root_password="${1}" |
---|
| 402 | local database=$2 |
---|
| 403 | |
---|
[a555f49] | 404 | echoAndLog "${FUNCNAME}(): creating database..." |
---|
[a01156a] | 405 | mysqladmin -u root --password="${root_password}" create $database |
---|
| 406 | if [ $? -ne 0 ]; then |
---|
[a555f49] | 407 | errorAndLog "${FUNCNAME}(): error while creating database $database" |
---|
[a01156a] | 408 | return 1 |
---|
| 409 | fi |
---|
[a555f49] | 410 | echoAndLog "${FUNCNAME}(): database $database created" |
---|
[a01156a] | 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 | |
---|
[13a01a7] | 474 | function svnExportCode() |
---|
| 475 | { |
---|
| 476 | if [ $# -ne 1 ]; then |
---|
| 477 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
| 478 | exit 1 |
---|
| 479 | fi |
---|
| 480 | |
---|
[6090a2d] | 481 | local url="$1" |
---|
[13a01a7] | 482 | |
---|
| 483 | echoAndLog "${FUNCNAME}(): downloading subversion code..." |
---|
| 484 | |
---|
[6090a2d] | 485 | svn export --force "$url" opengnsys |
---|
[13a01a7] | 486 | if [ $? -ne 0 ]; then |
---|
[6090a2d] | 487 | errorAndLog "${FUNCNAME}(): error getting OpenGnSys code from $url" |
---|
[13a01a7] | 488 | return 1 |
---|
| 489 | fi |
---|
| 490 | echoAndLog "${FUNCNAME}(): subversion code downloaded" |
---|
| 491 | return 0 |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | |
---|
[892606b9] | 495 | ############################################################ |
---|
[7586ca3] | 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 | |
---|
[62e3bcf] | 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)}') |
---|
[b94a1b2] | 520 | NETIP=$(netstat -nr | grep $MAINDEV | awk '$1!~/0\.0\.0\.0/ {if (n=="") n=$1} END {print n}') |
---|
[7586ca3] | 521 | ROUTERIP=$(netstat -nr | awk '$1~/0\.0\.0\.0/ {print $2}') |
---|
[a555f49] | 522 | DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1) |
---|
[7586ca3] | 523 | if [ -z "$NETIP" -o -z "$NETMASK" ]; then |
---|
[62e3bcf] | 524 | errorAndLog "${FUNCNAME}(): Network not detected." |
---|
[7586ca3] | 525 | exit 1 |
---|
| 526 | fi |
---|
[cc7eab7] | 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"} |
---|
[7586ca3] | 536 | } |
---|
| 537 | |
---|
| 538 | |
---|
| 539 | ############################################################ |
---|
[892606b9] | 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 |
---|
[8fc9552] | 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 |
---|
[892606b9] | 566 | EOF |
---|
| 567 | # comprobamos el servicio tftp |
---|
| 568 | sleep 1 |
---|
| 569 | testPxe |
---|
| 570 | ## damos perfimos de lectura a usuario web. |
---|
[cc7eab7] | 571 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP ${basetftp} |
---|
[892606b9] | 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 | |
---|
[8fc9552] | 581 | |
---|
[892606b9] | 582 | ######################################################################## |
---|
[b6906f7] | 583 | ## Configuracion servicio NFS |
---|
[892606b9] | 584 | ######################################################################## |
---|
| 585 | |
---|
[13a01a7] | 586 | # ADVERTENCIA: usa variables globales NETIP y NETMASK! |
---|
| 587 | function nfsConfigure() |
---|
[7586ca3] | 588 | { |
---|
[13a01a7] | 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 | |
---|
[8fc9552] | 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 | |
---|
[7586ca3] | 617 | /etc/init.d/nfs-kernel-server restart |
---|
[13a01a7] | 618 | |
---|
[b6906f7] | 619 | exportfs -va |
---|
[13a01a7] | 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 |
---|
[b6906f7] | 627 | } |
---|
[892606b9] | 628 | |
---|
[b6906f7] | 629 | |
---|
[13a01a7] | 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 | |
---|
[8fc9552] | 683 | |
---|
| 684 | ######################################################################## |
---|
[813f617] | 685 | ## Configuracion servicio Samba |
---|
[8fc9552] | 686 | ######################################################################## |
---|
| 687 | function smbConfigure() |
---|
| 688 | { |
---|
[813f617] | 689 | echoAndLog "${FUNCNAME}(): Configure Samba server." |
---|
[8fc9552] | 690 | |
---|
| 691 | backupFile /etc/samba/smb.conf |
---|
| 692 | |
---|
[813f617] | 693 | # Copiar plantailla de recursos para OpenGnSys |
---|
[c1e00e4] | 694 | sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ |
---|
[edac247] | 695 | $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > /etc/samba/smb-og.conf |
---|
[813f617] | 696 | # Configurar y recargar Samba" |
---|
[edac247] | 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 |
---|
[813f617] | 698 | /etc/init.d/smbd restart |
---|
[8fc9552] | 699 | if [ $? -ne 0 ]; then |
---|
[813f617] | 700 | errorAndLog "${FUNCNAME}(): error while configure Samba" |
---|
[8fc9552] | 701 | return 1 |
---|
| 702 | fi |
---|
[813f617] | 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} |
---|
[8fc9552] | 708 | |
---|
[813f617] | 709 | echoAndLog "${FUNCNAME}(): Added Samba configuration." |
---|
[8fc9552] | 710 | return 0 |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | |
---|
[b6906f7] | 714 | ######################################################################## |
---|
| 715 | ## Configuracion servicio DHCP |
---|
| 716 | ######################################################################## |
---|
| 717 | |
---|
[7586ca3] | 718 | function dhcpConfigure() |
---|
| 719 | { |
---|
[a555f49] | 720 | echoAndLog "${FUNCNAME}(): Sample DHCP Configuration." |
---|
| 721 | |
---|
| 722 | backupFile /etc/dhcp3/dhcpd.conf |
---|
| 723 | |
---|
[7586ca3] | 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" \ |
---|
[813f617] | 730 | $WORKDIR/opengnsys/server/etc/dhcpd.conf.tmpl > /etc/dhcp3/dhcpd.conf |
---|
[a555f49] | 731 | if [ $? -ne 0 ]; then |
---|
| 732 | errorAndLog "${FUNCNAME}(): error while configuring dhcp server" |
---|
| 733 | return 1 |
---|
| 734 | fi |
---|
| 735 | |
---|
[7586ca3] | 736 | /etc/init.d/dhcp3-server restart |
---|
[a555f49] | 737 | echoAndLog "${FUNCNAME}(): Sample DHCP Configured in file \"/etc/dhcp3/dhcpd.conf\"." |
---|
| 738 | return 0 |
---|
[892606b9] | 739 | } |
---|
| 740 | |
---|
| 741 | |
---|
[a01156a] | 742 | ##################################################################### |
---|
| 743 | ####### Funciones específicas de la instalación de Opengnsys |
---|
| 744 | ##################################################################### |
---|
| 745 | |
---|
[49c6891] | 746 | # Copiar ficheros del OpenGnSys Web Console. |
---|
[7586ca3] | 747 | function installWebFiles() |
---|
| 748 | { |
---|
[dce072b] | 749 | echoAndLog "${FUNCNAME}(): Installing web files..." |
---|
[7586ca3] | 750 | cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para doxigen |
---|
| 751 | if [ $? != 0 ]; then |
---|
[dce072b] | 752 | errorAndLog "${FUNCNAME}(): Error copying web files." |
---|
[7586ca3] | 753 | exit 1 |
---|
| 754 | fi |
---|
| 755 | find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
[813f617] | 756 | # Descomprimir XAJAX. |
---|
[edac247] | 757 | unzip $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax |
---|
[7586ca3] | 758 | # Cambiar permisos para ficheros especiales. |
---|
[3aaf91d] | 759 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/iconos |
---|
[dce072b] | 760 | echoAndLog "${FUNCNAME}(): Web files installed successfully." |
---|
[7586ca3] | 761 | } |
---|
| 762 | |
---|
| 763 | # Configuración específica de Apache. |
---|
[892606b9] | 764 | function openGnsysInstallWebConsoleApacheConf() |
---|
[a01156a] | 765 | { |
---|
| 766 | if [ $# -ne 2 ]; then |
---|
[dce072b] | 767 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 768 | exit 1 |
---|
| 769 | fi |
---|
| 770 | |
---|
| 771 | local path_opengnsys_base=$1 |
---|
| 772 | local path_apache2_confd=$2 |
---|
[892606b9] | 773 | local path_web_console=${path_opengnsys_base}/www |
---|
[a01156a] | 774 | |
---|
[892606b9] | 775 | if [ ! -d $path_apache2_confd ]; then |
---|
[dce072b] | 776 | errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation" |
---|
[892606b9] | 777 | return 1 |
---|
| 778 | fi |
---|
| 779 | |
---|
[7586ca3] | 780 | mkdir -p $path_apache2_confd/{sites-available,sites-enabled} |
---|
[892606b9] | 781 | |
---|
[dce072b] | 782 | echoAndLog "${FUNCNAME}(): creating apache2 config file.." |
---|
[a01156a] | 783 | |
---|
[d725a41] | 784 | |
---|
[a01156a] | 785 | # genera configuración |
---|
[892606b9] | 786 | cat > $path_opengnsys_base/etc/apache.conf <<EOF |
---|
[49c6891] | 787 | # OpenGnSys Web Console configuration for Apache |
---|
[a01156a] | 788 | |
---|
[892606b9] | 789 | Alias /opengnsys ${path_web_console} |
---|
[a01156a] | 790 | |
---|
[892606b9] | 791 | <Directory ${path_web_console}> |
---|
[a01156a] | 792 | Options -Indexes FollowSymLinks |
---|
| 793 | DirectoryIndex acceso.php |
---|
| 794 | </Directory> |
---|
| 795 | EOF |
---|
| 796 | |
---|
[7586ca3] | 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 |
---|
[a01156a] | 799 | if [ $? -ne 0 ]; then |
---|
[dce072b] | 800 | errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation" |
---|
[a01156a] | 801 | return 1 |
---|
| 802 | else |
---|
[dce072b] | 803 | echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon" |
---|
[077dd7c5] | 804 | /etc/init.d/apache2 restart |
---|
[a01156a] | 805 | return 0 |
---|
| 806 | fi |
---|
| 807 | } |
---|
| 808 | |
---|
[8fc9552] | 809 | |
---|
[5d6bf97] | 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." |
---|
[ead38fb] | 818 | return 1 |
---|
[5d6bf97] | 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 | |
---|
[a01156a] | 826 | # Crea la estructura base de la instalación de opengnsys |
---|
[318efac] | 827 | function openGnsysInstallCreateDirs() |
---|
[a01156a] | 828 | { |
---|
| 829 | if [ $# -ne 1 ]; then |
---|
[dce072b] | 830 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 831 | exit 1 |
---|
| 832 | fi |
---|
| 833 | |
---|
| 834 | local path_opengnsys_base=$1 |
---|
| 835 | |
---|
[dce072b] | 836 | echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base" |
---|
[a01156a] | 837 | |
---|
| 838 | mkdir -p $path_opengnsys_base |
---|
| 839 | mkdir -p $path_opengnsys_base/bin |
---|
[5c33840] | 840 | mkdir -p $path_opengnsys_base/client |
---|
[49c6891] | 841 | mkdir -p $path_opengnsys_base/doc |
---|
[5c33840] | 842 | mkdir -p $path_opengnsys_base/etc |
---|
[a01156a] | 843 | mkdir -p $path_opengnsys_base/lib |
---|
[1cc5697] | 844 | mkdir -p $path_opengnsys_base/log/clients |
---|
[7586ca3] | 845 | mkdir -p $path_opengnsys_base/sbin |
---|
[a01156a] | 846 | mkdir -p $path_opengnsys_base/www |
---|
[5c33840] | 847 | mkdir -p $path_opengnsys_base/images |
---|
[b6906f7] | 848 | ln -fs /var/lib/tftpboot $path_opengnsys_base |
---|
| 849 | ln -fs $path_opengnsys_base/log /var/log/opengnsys |
---|
[5c33840] | 850 | |
---|
[a01156a] | 851 | if [ $? -ne 0 ]; then |
---|
[dce072b] | 852 | errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" |
---|
[a01156a] | 853 | return 1 |
---|
| 854 | fi |
---|
| 855 | |
---|
[dce072b] | 856 | echoAndLog "${FUNCNAME}(): directory paths created" |
---|
[a01156a] | 857 | return 0 |
---|
| 858 | } |
---|
| 859 | |
---|
[463a1d49] | 860 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
[318efac] | 861 | function openGnsysCopyServerFiles () { |
---|
[463a1d49] | 862 | if [ $# -ne 1 ]; then |
---|
[879689f] | 863 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[463a1d49] | 864 | exit 1 |
---|
| 865 | fi |
---|
| 866 | |
---|
| 867 | local path_opengnsys_base=$1 |
---|
| 868 | |
---|
[2338c95f] | 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 \ |
---|
[b5aae72] | 878 | server/bin \ |
---|
[85b029f] | 879 | repoman/bin \ |
---|
[49c6891] | 880 | doc ) |
---|
[2338c95f] | 881 | local TARGETS=( tftpboot/pxelinux.cfg \ |
---|
[b5aae72] | 882 | bin \ |
---|
[85b029f] | 883 | bin \ |
---|
[49c6891] | 884 | doc ) |
---|
[463a1d49] | 885 | |
---|
| 886 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
[879689f] | 887 | errorAndLog "${FUNCNAME}(): inconsistent number of array items" |
---|
[463a1d49] | 888 | exit 1 |
---|
| 889 | fi |
---|
| 890 | |
---|
[879689f] | 891 | echoAndLog "${FUNCNAME}(): copying files to server directories" |
---|
[f2bb433] | 892 | |
---|
[8457092] | 893 | pushd $WORKDIR/opengnsys |
---|
[463a1d49] | 894 | local i |
---|
| 895 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
| 896 | if [ -f "${SOURCES[$i]}" ]; then |
---|
[879689f] | 897 | echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
[b5aae72] | 898 | cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
[8457092] | 899 | elif [ -d "${SOURCES[$i]}" ]; then |
---|
[879689f] | 900 | echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
[8457092] | 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]}" |
---|
[463a1d49] | 904 | fi |
---|
| 905 | done |
---|
[7586ca3] | 906 | popd |
---|
[892606b9] | 907 | } |
---|
| 908 | |
---|
[7586ca3] | 909 | #################################################################### |
---|
| 910 | ### Funciones de compilación de códifo fuente de servicios |
---|
| 911 | #################################################################### |
---|
| 912 | |
---|
[b6906f7] | 913 | # Compilar los servicios de OpenGNsys |
---|
[7586ca3] | 914 | function servicesCompilation () |
---|
| 915 | { |
---|
[13a01a7] | 916 | local hayErrores=0 |
---|
[0795938] | 917 | |
---|
[49c6891] | 918 | # Compilar OpenGnSys Server |
---|
| 919 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server" |
---|
[7b61735] | 920 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer |
---|
[b6906f7] | 921 | make && make install |
---|
[13a01a7] | 922 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 923 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server" |
---|
[13a01a7] | 924 | hayErrores=1 |
---|
| 925 | fi |
---|
[7586ca3] | 926 | popd |
---|
[49c6891] | 927 | # Compilar OpenGnSys Repository Manager |
---|
| 928 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager" |
---|
[7b61735] | 929 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo |
---|
[b6906f7] | 930 | make && make install |
---|
[13a01a7] | 931 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 932 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager" |
---|
[13a01a7] | 933 | hayErrores=1 |
---|
| 934 | fi |
---|
[8125e7c] | 935 | popd |
---|
[4984660] | 936 | # Compilar OpenGnSys Agent |
---|
| 937 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent" |
---|
[7b61735] | 938 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent |
---|
[4984660] | 939 | make && make install |
---|
| 940 | if [ $? -ne 0 ]; then |
---|
| 941 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent" |
---|
| 942 | hayErrores=1 |
---|
| 943 | fi |
---|
| 944 | popd |
---|
[49c6891] | 945 | # Compilar OpenGnSys Client |
---|
| 946 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client" |
---|
[7b61735] | 947 | pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient |
---|
[2338c95f] | 948 | make && mv ogAdmClient ../../../../client/shared/bin |
---|
[13a01a7] | 949 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 950 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client" |
---|
[13a01a7] | 951 | hayErrores=1 |
---|
| 952 | fi |
---|
[318efac] | 953 | popd |
---|
[13a01a7] | 954 | |
---|
| 955 | return $hayErrores |
---|
[b6906f7] | 956 | } |
---|
| 957 | |
---|
[7b61735] | 958 | #################################################################### |
---|
| 959 | ### Funciones de copia de la Interface de administración |
---|
| 960 | #################################################################### |
---|
| 961 | |
---|
| 962 | # Copiar carpeta de Interface |
---|
[c1e00e4] | 963 | function copyInterfaceAdm () |
---|
[7b61735] | 964 | { |
---|
| 965 | local hayErrores=0 |
---|
| 966 | |
---|
[fbd9bcc] | 967 | # Crear carpeta y copiar Interface |
---|
[7b61735] | 968 | echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" |
---|
[fbd9bcc] | 969 | cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm |
---|
[7b61735] | 970 | if [ $? -ne 0 ]; then |
---|
| 971 | echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder" |
---|
| 972 | hayErrores=1 |
---|
| 973 | fi |
---|
| 974 | |
---|
| 975 | return $hayErrores |
---|
| 976 | } |
---|
[b6906f7] | 977 | |
---|
[892606b9] | 978 | #################################################################### |
---|
| 979 | ### Funciones instalacion cliente opengnsys |
---|
| 980 | #################################################################### |
---|
| 981 | |
---|
[7cc6687] | 982 | function openGnsysCopyClientFiles() |
---|
[7586ca3] | 983 | { |
---|
[a555f49] | 984 | local hayErrores=0 |
---|
| 985 | |
---|
[49c6891] | 986 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files." |
---|
[d47d38d] | 987 | cp -ar $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client |
---|
| 988 | if [ $? -ne 0 ]; then |
---|
[9ef8920] | 989 | errorAndLog "${FUNCNAME}(): error while copying client estructure" |
---|
| 990 | hayErrores=1 |
---|
| 991 | fi |
---|
[d47d38d] | 992 | find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
[9ef8920] | 993 | |
---|
[49c6891] | 994 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files." |
---|
[d47d38d] | 995 | mkdir -p $INSTALL_TARGET/client/lib/engine/bin |
---|
| 996 | cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin |
---|
[a555f49] | 997 | if [ $? -ne 0 ]; then |
---|
| 998 | errorAndLog "${FUNCNAME}(): error while copying engine files" |
---|
| 999 | hayErrores=1 |
---|
| 1000 | fi |
---|
[9ef8920] | 1001 | |
---|
| 1002 | if [ $hayErrores -eq 0 ]; then |
---|
| 1003 | echoAndLog "${FUNCNAME}(): client copy files success." |
---|
| 1004 | else |
---|
| 1005 | errorAndLog "${FUNCNAME}(): client copy files with errors" |
---|
| 1006 | fi |
---|
| 1007 | |
---|
| 1008 | return $hayErrores |
---|
| 1009 | } |
---|
| 1010 | |
---|
| 1011 | |
---|
| 1012 | |
---|
| 1013 | |
---|
| 1014 | # Crear antiguo cliente initrd para OpenGnSys 0.10 |
---|
| 1015 | function openGnsysOldClientCreate() |
---|
| 1016 | { |
---|
| 1017 | local OSCODENAME |
---|
| 1018 | |
---|
| 1019 | local hayErrores=0 |
---|
| 1020 | |
---|
[cc7eab7] | 1021 | # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto). |
---|
[28c96b3] | 1022 | OSCODENAME=$(lsb_release -cs 2>/dev/null) |
---|
[7586ca3] | 1023 | if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then |
---|
[a555f49] | 1024 | echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME." |
---|
[da8db11] | 1025 | $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v $OSCODENAME 2>&1 | tee -a $LOG_FILE |
---|
[a555f49] | 1026 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1027 | errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client" |
---|
[a555f49] | 1028 | hayErrores=1 |
---|
| 1029 | fi |
---|
| 1030 | echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME." |
---|
[da8db11] | 1031 | $INSTALL_TARGET/bin/upgrade-clients-udeb.sh $OSCODENAME 2>&1 | tee -a $LOG_FILE |
---|
[a555f49] | 1032 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1033 | errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client" |
---|
[a555f49] | 1034 | hayErrores=1 |
---|
| 1035 | fi |
---|
[7586ca3] | 1036 | else |
---|
[a555f49] | 1037 | echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files." |
---|
[da8db11] | 1038 | $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot 2>&1 | tee -a $LOG_FILE |
---|
[a555f49] | 1039 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1040 | errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client" |
---|
[a555f49] | 1041 | hayErrores=1 |
---|
| 1042 | fi |
---|
| 1043 | echoAndLog "${FUNCNAME}(): Loading default udeb files." |
---|
[da8db11] | 1044 | $INSTALL_TARGET/bin/upgrade-clients-udeb.sh 2>&1 | tee -a $LOG_FILE |
---|
[a555f49] | 1045 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1046 | errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client" |
---|
[a555f49] | 1047 | hayErrores=1 |
---|
| 1048 | fi |
---|
| 1049 | fi |
---|
| 1050 | |
---|
| 1051 | if [ $hayErrores -eq 0 ]; then |
---|
[813f617] | 1052 | echoAndLog "${FUNCNAME}(): Old client generation success." |
---|
[a555f49] | 1053 | else |
---|
[813f617] | 1054 | errorAndLog "${FUNCNAME}(): Old client generation with errors" |
---|
[7586ca3] | 1055 | fi |
---|
[a555f49] | 1056 | |
---|
| 1057 | return $hayErrores |
---|
[463a1d49] | 1058 | } |
---|
| 1059 | |
---|
| 1060 | |
---|
[813f617] | 1061 | # Crear nuevo cliente OpenGnSys 1.0 |
---|
| 1062 | function openGnsysClientCreate() |
---|
| 1063 | { |
---|
| 1064 | local DOWNLOADURL=http://www.opengnsys.es/downloads |
---|
| 1065 | local tmpfile=/tmp/ogclient.tgz |
---|
| 1066 | |
---|
| 1067 | echoAndLog "${FUNCNAME}(): Loading Client" |
---|
| 1068 | # Descargar y descomprimir cliente ogclient |
---|
| 1069 | wget $DOWNLOADURL/20 -O $tmpfile |
---|
| 1070 | wget $DOWNLOADURL/21 -O - >> $tmpfile |
---|
| 1071 | wget $DOWNLOADURL/22 -O - >> $tmpfile |
---|
| 1072 | if [ ! -s $tmpfile ]; then |
---|
| 1073 | errorAndLog "${FUNCNAME}(): Error loading client files" |
---|
| 1074 | return 1 |
---|
| 1075 | fi |
---|
| 1076 | echoAndLog "${FUNCNAME}(): Extranting Client files" |
---|
| 1077 | tar xzvf $tmpfile -C $INSTALL_TARGET/tftpboot |
---|
| 1078 | rm -f $tmpfile |
---|
| 1079 | # Usar la versión más reciente del Kernel y del Initrd para el cliente. |
---|
| 1080 | ln $(ls $INSTALL_TARGET/tftpboot/ogclient/vmlinuz-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz |
---|
| 1081 | ln $(ls $INSTALL_TARGET/tftpboot/ogclient/initrd.img-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img |
---|
| 1082 | # Establecer los permisos. |
---|
| 1083 | chmod -R 755 $INSTALL_TARGET/tftpboot/ogclient |
---|
| 1084 | chown -R :$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/tftpboot/ogclient |
---|
| 1085 | echoAndLog "${FUNCNAME}(): Client generation success" |
---|
| 1086 | } |
---|
| 1087 | |
---|
| 1088 | |
---|
[49c6891] | 1089 | # Configuración básica de servicios de OpenGnSys |
---|
[cc7eab7] | 1090 | function openGnsysConfigure() |
---|
| 1091 | { |
---|
[9ee62ad] | 1092 | echoAndLog "${FUNCNAME}(): Copying init files." |
---|
[7b61735] | 1093 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys |
---|
| 1094 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys |
---|
[8fc9552] | 1095 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepoAux /opt/opengnsys/sbin/ |
---|
[cc7eab7] | 1096 | update-rc.d opengnsys defaults |
---|
[9ee62ad] | 1097 | echoAndLog "${FUNCNAME}(): Creating cron files." |
---|
| 1098 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator |
---|
[8fc9552] | 1099 | echo "5 * * * * root [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker |
---|
[9ee62ad] | 1100 | echoAndLog "${FUNCNAME}(): Creating OpenGnSys config file in \"$INSTALL_TARGET/etc\"." |
---|
[bf41d13] | 1101 | 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 |
---|
[1a22cd2] | 1102 | perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg |
---|
[4a3cd1f] | 1103 | 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 |
---|
[9de73019] | 1104 | chown root:root $INSTALL_TARGET/etc/{ogAdmServer.cfg,ogAdmAgent.cfg} |
---|
| 1105 | chmod 600 $INSTALL_TARGET/etc/{ogAdmServer.cfg,ogAdmAgent.cfg} |
---|
[ea7186c] | 1106 | echoAndLog "${FUNCNAME}(): Creating Web Console config file" |
---|
| 1107 | OPENGNSYS_CONSOLEURL="http://$SERVERIP/opengnsys" |
---|
[bf41d13] | 1108 | 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 |
---|
[9de73019] | 1109 | chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso.php |
---|
| 1110 | chmod 600 $INSTALL_TARGET/www/controlacceso.php |
---|
[7b61735] | 1111 | 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 |
---|
[9ee62ad] | 1112 | echoAndLog "${FUNCNAME}(): Starting OpenGnSys services." |
---|
[cc7eab7] | 1113 | /etc/init.d/opengnsys start |
---|
| 1114 | } |
---|
| 1115 | |
---|
[b6906f7] | 1116 | |
---|
[a01156a] | 1117 | ##################################################################### |
---|
[180a07dd] | 1118 | ####### Función de resumen informativo de la instalación |
---|
| 1119 | ##################################################################### |
---|
| 1120 | |
---|
[813f617] | 1121 | function installationSummary() |
---|
| 1122 | { |
---|
[180a07dd] | 1123 | echo |
---|
[49c6891] | 1124 | echoAndLog "OpenGnSys Installation Summary" |
---|
[180a07dd] | 1125 | echo "==============================" |
---|
[8457092] | 1126 | echoAndLog "Project version: $(cat $INSTALL_TARGET/doc/VERSION.txt 2>/dev/null)" |
---|
[49c6891] | 1127 | echoAndLog "Installation directory: $INSTALL_TARGET" |
---|
| 1128 | echoAndLog "Repository directory: $INSTALL_TARGET/images" |
---|
[d47d38d] | 1129 | echoAndLog "DHCP configuration file: /etc/dhcp3/dhcpd.conf" |
---|
| 1130 | echoAndLog "TFTP configuration directory: /var/lib/tftpboot" |
---|
| 1131 | echoAndLog "Samba configuration directory: /etc/samba" |
---|
[49c6891] | 1132 | echoAndLog "Web Console URL: $OPENGNSYS_CONSOLEURL" |
---|
[180a07dd] | 1133 | echoAndLog "Web Console admin user: $OPENGNSYS_DB_USER" |
---|
| 1134 | echoAndLog "Web Console admin password: $OPENGNSYS_DB_PASSWD" |
---|
| 1135 | echo |
---|
| 1136 | echoAndLog "Post-Installation Instructions:" |
---|
| 1137 | echo "===============================" |
---|
| 1138 | echoAndLog "Review or edit all configuration files." |
---|
[c5ce04c] | 1139 | echoAndLog "Insert DHCP configuration data and restart service." |
---|
[180a07dd] | 1140 | echoAndLog "Log-in as Web Console admin user." |
---|
[85fa51e] | 1141 | echoAndLog " - Review default Organization data and assign default user." |
---|
[180a07dd] | 1142 | echoAndLog "Log-in as Web Console organization user." |
---|
[85fa51e] | 1143 | echoAndLog " - Insert OpenGnSys data (rooms, computers, menus, etc)." |
---|
[180a07dd] | 1144 | echo |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | |
---|
| 1148 | |
---|
| 1149 | ##################################################################### |
---|
[49c6891] | 1150 | ####### Proceso de instalación de OpenGnSys |
---|
[a01156a] | 1151 | ##################################################################### |
---|
| 1152 | |
---|
[49c6891] | 1153 | echoAndLog "OpenGnSys installation begins at $(date)" |
---|
[6090a2d] | 1154 | pushd $WORKDIR |
---|
[cc7eab7] | 1155 | |
---|
[7c54b49] | 1156 | # Detener servicios de OpenGnSys, si están activos previamente. |
---|
| 1157 | [ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop |
---|
| 1158 | |
---|
[7586ca3] | 1159 | # Detectar parámetros de red por defecto |
---|
| 1160 | getNetworkSettings |
---|
| 1161 | if [ $? -ne 0 ]; then |
---|
| 1162 | errorAndLog "Error reading default network settings." |
---|
| 1163 | exit 1 |
---|
| 1164 | fi |
---|
| 1165 | |
---|
[318efac] | 1166 | # Actualizar repositorios |
---|
| 1167 | apt-get update |
---|
| 1168 | |
---|
[b6906f7] | 1169 | # Instalación de dependencias (paquetes de sistema operativo). |
---|
[a01156a] | 1170 | declare -a notinstalled |
---|
| 1171 | checkDependencies DEPENDENCIES notinstalled |
---|
| 1172 | if [ $? -ne 0 ]; then |
---|
| 1173 | installDependencies notinstalled |
---|
| 1174 | if [ $? -ne 0 ]; then |
---|
| 1175 | echoAndLog "Error while installing some dependeces, please verify your server installation before continue" |
---|
| 1176 | exit 1 |
---|
| 1177 | fi |
---|
| 1178 | fi |
---|
| 1179 | |
---|
[49c6891] | 1180 | # Arbol de directorios de OpenGnSys. |
---|
[a01156a] | 1181 | openGnsysInstallCreateDirs ${INSTALL_TARGET} |
---|
| 1182 | if [ $? -ne 0 ]; then |
---|
| 1183 | errorAndLog "Error while creating directory paths!" |
---|
| 1184 | exit 1 |
---|
| 1185 | fi |
---|
[b6906f7] | 1186 | |
---|
[1e7eaab] | 1187 | # Si es necesario, descarga el repositorio de código en directorio temporal |
---|
[49c6891] | 1188 | if [ $USESVN -eq 1 ]; then |
---|
[1e7eaab] | 1189 | svnExportCode $SVN_URL |
---|
| 1190 | if [ $? -ne 0 ]; then |
---|
| 1191 | errorAndLog "Error while getting code from svn" |
---|
| 1192 | exit 1 |
---|
| 1193 | fi |
---|
| 1194 | else |
---|
| 1195 | ln -fs "$(dirname $PROGRAMDIR)" opengnsys |
---|
[a01156a] | 1196 | fi |
---|
| 1197 | |
---|
[49c6891] | 1198 | # Compilar código fuente de los servicios de OpenGnSys. |
---|
[b6906f7] | 1199 | servicesCompilation |
---|
[13a01a7] | 1200 | if [ $? -ne 0 ]; then |
---|
| 1201 | errorAndLog "Error while compiling OpenGnsys services" |
---|
| 1202 | exit 1 |
---|
| 1203 | fi |
---|
[b6906f7] | 1204 | |
---|
[7b61735] | 1205 | # Copiar carpeta Interface entre administración y motor de clonación. |
---|
[c1e00e4] | 1206 | copyInterfaceAdm |
---|
[7b61735] | 1207 | if [ $? -ne 0 ]; then |
---|
[c1e00e4] | 1208 | errorAndLog "Error while copying Administration Interface" |
---|
[7b61735] | 1209 | exit 1 |
---|
| 1210 | fi |
---|
| 1211 | |
---|
[b6906f7] | 1212 | # Configurando tftp |
---|
[318efac] | 1213 | tftpConfigure |
---|
[b6906f7] | 1214 | |
---|
| 1215 | # Configuración NFS |
---|
[d47d38d] | 1216 | #### (descomentar las siguientes líneas para exportar servicios por NFS) |
---|
| 1217 | #nfsConfigure |
---|
| 1218 | #if [ $? -ne 0 ]; then |
---|
| 1219 | # errorAndLog "Error while configuring nfs server!" |
---|
| 1220 | # exit 1 |
---|
| 1221 | #fi |
---|
[b6906f7] | 1222 | |
---|
[c1e00e4] | 1223 | # Configuración Samba |
---|
[8fc9552] | 1224 | smbConfigure |
---|
| 1225 | if [ $? -ne 0 ]; then |
---|
[c1e00e4] | 1226 | errorAndLog "Error while configuring Samba server!" |
---|
[8fc9552] | 1227 | exit 1 |
---|
| 1228 | fi |
---|
| 1229 | |
---|
[b6906f7] | 1230 | # Configuración ejemplo DHCP |
---|
| 1231 | dhcpConfigure |
---|
[a555f49] | 1232 | if [ $? -ne 0 ]; then |
---|
| 1233 | errorAndLog "Error while copying your dhcp server files!" |
---|
| 1234 | exit 1 |
---|
| 1235 | fi |
---|
[b6906f7] | 1236 | |
---|
[49c6891] | 1237 | # Copiar ficheros de servicios OpenGnSys Server. |
---|
[463a1d49] | 1238 | openGnsysCopyServerFiles ${INSTALL_TARGET} |
---|
| 1239 | if [ $? -ne 0 ]; then |
---|
| 1240 | errorAndLog "Error while copying the server files!" |
---|
| 1241 | exit 1 |
---|
| 1242 | fi |
---|
| 1243 | |
---|
[49c6891] | 1244 | # Instalar Base de datos de OpenGnSys Admin. |
---|
[b6906f7] | 1245 | isInArray notinstalled "mysql-server" |
---|
| 1246 | if [ $? -eq 0 ]; then |
---|
| 1247 | mysqlSetRootPassword ${MYSQL_ROOT_PASSWORD} |
---|
| 1248 | else |
---|
| 1249 | mysqlGetRootPassword |
---|
| 1250 | fi |
---|
[463a1d49] | 1251 | |
---|
[a01156a] | 1252 | mysqlTestConnection ${MYSQL_ROOT_PASSWORD} |
---|
| 1253 | if [ $? -ne 0 ]; then |
---|
| 1254 | errorAndLog "Error while connection to mysql" |
---|
| 1255 | exit 1 |
---|
| 1256 | fi |
---|
[892606b9] | 1257 | mysqlDbExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
[a01156a] | 1258 | if [ $? -ne 0 ]; then |
---|
[cc7eab7] | 1259 | echoAndLog "Creating Web Console database" |
---|
[892606b9] | 1260 | mysqlCreateDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
[a01156a] | 1261 | if [ $? -ne 0 ]; then |
---|
[cc7eab7] | 1262 | errorAndLog "Error while creating Web Console database" |
---|
[a01156a] | 1263 | exit 1 |
---|
| 1264 | fi |
---|
| 1265 | else |
---|
[cc7eab7] | 1266 | echoAndLog "Web Console database exists, ommiting creation" |
---|
[a01156a] | 1267 | fi |
---|
| 1268 | |
---|
[892606b9] | 1269 | mysqlCheckUserExists ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DB_USER} |
---|
[a01156a] | 1270 | if [ $? -ne 0 ]; then |
---|
| 1271 | echoAndLog "Creating user in database" |
---|
[892606b9] | 1272 | mysqlCreateAdminUserToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}" |
---|
[a01156a] | 1273 | if [ $? -ne 0 ]; then |
---|
[cc7eab7] | 1274 | errorAndLog "Error while creating database user" |
---|
[a01156a] | 1275 | exit 1 |
---|
| 1276 | fi |
---|
| 1277 | |
---|
| 1278 | fi |
---|
| 1279 | |
---|
[892606b9] | 1280 | mysqlCheckDbIsEmpty ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} |
---|
[a01156a] | 1281 | if [ $? -eq 0 ]; then |
---|
| 1282 | echoAndLog "Creating tables..." |
---|
[892606b9] | 1283 | if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then |
---|
| 1284 | mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE |
---|
[a01156a] | 1285 | else |
---|
[892606b9] | 1286 | errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!" |
---|
[a01156a] | 1287 | exit 1 |
---|
| 1288 | fi |
---|
[bc7dfe7] | 1289 | else |
---|
| 1290 | # Si existe fichero ogBDAdmin-VersLocal-VersRepo.sql; aplicar cambios. |
---|
| 1291 | INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt) |
---|
| 1292 | REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt) |
---|
[3aaf91d] | 1293 | OPENGNSYS_DB_UPDADE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql" |
---|
[bc7dfe7] | 1294 | if [ -f $WORKDIR/$OPENGNSYS_DB_UPDADE_FILE ]; then |
---|
| 1295 | echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION" |
---|
| 1296 | mysqlImportSqlFileToDb ${MYSQL_ROOT_PASSWORD} ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDADE_FILE |
---|
| 1297 | else |
---|
| 1298 | echoAndLog "Database unchanged." |
---|
| 1299 | fi |
---|
[a01156a] | 1300 | fi |
---|
| 1301 | |
---|
| 1302 | # copiando paqinas web |
---|
[7586ca3] | 1303 | installWebFiles |
---|
[5d6bf97] | 1304 | # Generar páqinas web de documentación de la API |
---|
| 1305 | makeDoxygenFiles |
---|
[a01156a] | 1306 | |
---|
| 1307 | # creando configuracion de apache2 |
---|
[892606b9] | 1308 | openGnsysInstallWebConsoleApacheConf $INSTALL_TARGET /etc/apache2 |
---|
[a01156a] | 1309 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1310 | errorAndLog "Error configuring Apache for OpenGnSYS Admin" |
---|
[a01156a] | 1311 | exit 1 |
---|
| 1312 | fi |
---|
| 1313 | |
---|
| 1314 | popd |
---|
[892606b9] | 1315 | |
---|
[9ef8920] | 1316 | |
---|
| 1317 | # Crear la estructura de los accesos al servidor desde el cliente (shared) |
---|
[7cc6687] | 1318 | openGnsysCopyClientFiles |
---|
[9ef8920] | 1319 | if [ $? -ne 0 ]; then |
---|
| 1320 | errorAndLog "Error creating client structure" |
---|
| 1321 | fi |
---|
| 1322 | |
---|
[813f617] | 1323 | # Crear la estructura del antiguo cliente initrd de OpenGnSys 0.10 |
---|
[d47d38d] | 1324 | #### (descomentar las siguientes líneas para generar cliente initrd) |
---|
[2338c95f] | 1325 | #openGnsysOldClientCreate |
---|
| 1326 | #if [ $? -ne 0 ]; then |
---|
| 1327 | # errorAndLog "Warning: cannot create old initrd client" |
---|
| 1328 | #fi |
---|
[9ef8920] | 1329 | |
---|
[813f617] | 1330 | # Crear la estructura del cliente de OpenGnSys 1.0 |
---|
[892606b9] | 1331 | openGnsysClientCreate |
---|
[a555f49] | 1332 | if [ $? -ne 0 ]; then |
---|
[813f617] | 1333 | errorAndLog "Error creating client" |
---|
[a555f49] | 1334 | exit 1 |
---|
| 1335 | fi |
---|
[892606b9] | 1336 | |
---|
[65245d1] | 1337 | # Configuración de servicios de OpenGnSys |
---|
| 1338 | openGnsysConfigure |
---|
| 1339 | |
---|
[180a07dd] | 1340 | # Mostrar sumario de la instalación e instrucciones de post-instalación. |
---|
| 1341 | installationSummary |
---|
| 1342 | |
---|
[077dd7c5] | 1343 | #rm -rf $WORKDIR |
---|
[49c6891] | 1344 | echoAndLog "OpenGnSys installation finished at $(date)" |
---|
[2308fc7] | 1345 | |
---|