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