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