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