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