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