[a01156a] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | ##################################################################### |
---|
[6ef01d9] | 4 | ####### Script instalador OpenGnSys |
---|
[a01156a] | 5 | ####### autor: Luis Guillén <lguillen@unizar.es> |
---|
| 6 | ##################################################################### |
---|
| 7 | |
---|
| 8 | |
---|
[9672640] | 9 | #### AVISO: Puede editar configuración de acceso por defecto. |
---|
| 10 | #### WARNING: Edit default access configuration if you wish. |
---|
| 11 | DEFAULT_MYSQL_ROOT_PASSWORD="passwordroot" # Clave por defecto root de MySQL |
---|
| 12 | DEFAULT_OPENGNSYS_DB_USER="usuog" # Usuario por defecto de acceso a la base de datos |
---|
| 13 | DEFAULT_OPENGNSYS_DB_PASSWD="passusuog" # Clave por defecto de acceso a la base de datos |
---|
| 14 | DEFAULT_OPENGNSYS_CLIENT_PASSWD="og" # Clave por defecto de acceso del cliente |
---|
[4a3cd1f] | 15 | |
---|
[1e7eaab] | 16 | # Sólo ejecutable por usuario root |
---|
[6ef01d9] | 17 | if [ "$(whoami)" != 'root' ]; then |
---|
[1e7eaab] | 18 | echo "ERROR: this program must run under root privileges!!" |
---|
| 19 | exit 1 |
---|
| 20 | fi |
---|
[9672640] | 21 | |
---|
| 22 | echo -e "\\nOpenGnSys Installation" |
---|
| 23 | echo "==============================" |
---|
| 24 | |
---|
| 25 | # Clave root de MySQL |
---|
| 26 | while : ; do |
---|
| 27 | echo -n -e "\\nEnter root password for MySQL (${DEFAULT_MYSQL_ROOT_PASSWORD}): "; |
---|
| 28 | read MYSQL_ROOT_PASSWORD |
---|
| 29 | if [ -n "${MYSQL_ROOT_PASSWORD//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico |
---|
| 30 | echo -e "\\aERROR: Must be alphanumeric, try again..." |
---|
| 31 | else |
---|
| 32 | if [ -z $MYSQL_ROOT_PASSWORD ]; then # Si esta vacio ponemos el valor por defecto |
---|
| 33 | MYSQL_ROOT_PASSWORD=$DEFAULT_MYSQL_ROOT_PASSWORD |
---|
| 34 | fi |
---|
| 35 | break |
---|
| 36 | fi |
---|
| 37 | done |
---|
| 38 | |
---|
| 39 | # Usuario de acceso a la base de datos |
---|
| 40 | while : ; do |
---|
| 41 | echo -n -e "\\nEnter username for OpenGnSys console (${DEFAULT_OPENGNSYS_DB_USER}): " |
---|
| 42 | read OPENGNSYS_DB_USER |
---|
| 43 | if [ -n "${OPENGNSYS_DB_USER//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico |
---|
| 44 | echo -e "\\aERROR: Must be alphanumeric, try again..." |
---|
| 45 | else |
---|
| 46 | if [ -z $OPENGNSYS_DB_USER ]; then # Si esta vacio ponemos el valor por defecto |
---|
| 47 | OPENGNSYS_DB_USER=$DEFAULT_OPENGNSYS_DB_USER |
---|
| 48 | fi |
---|
| 49 | break |
---|
| 50 | fi |
---|
| 51 | done |
---|
| 52 | |
---|
| 53 | # Clave de acceso a la base de datos |
---|
| 54 | while : ; do |
---|
| 55 | echo -n -e "\\nEnter password for OpenGnSys console (${DEFAULT_OPENGNSYS_DB_PASSWD}): " |
---|
| 56 | read OPENGNSYS_DB_PASSWD |
---|
| 57 | if [ -n "${OPENGNSYS_DB_PASSWD//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico |
---|
| 58 | echo -e "\\aERROR: Must be alphanumeric, try again..." |
---|
| 59 | else |
---|
| 60 | if [ -z $OPENGNSYS_DB_PASSWD ]; then # Si esta vacio ponemos el valor por defecto |
---|
| 61 | OPENGNSYS_DB_PASSWD=$DEFAULT_OPENGNSYS_DB_PASSWD |
---|
| 62 | fi |
---|
| 63 | break |
---|
| 64 | fi |
---|
| 65 | done |
---|
| 66 | |
---|
| 67 | # Clave de acceso del cliente |
---|
| 68 | while : ; do |
---|
| 69 | echo -n -e "\\nEnter root password for OpenGnSys client (${DEFAULT_OPENGNSYS_CLIENT_PASSWD}): " |
---|
| 70 | read OPENGNSYS_CLIENT_PASSWD |
---|
| 71 | if [ -n "${OPENGNSYS_CLIENT_PASSWD//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico |
---|
| 72 | echo -e "\\aERROR: Must be alphanumeric, try again..." |
---|
| 73 | else |
---|
| 74 | if [ -z $OPENGNSYS_CLIENT_PASSWD ]; then # Si esta vacio ponemos el valor por defecto |
---|
| 75 | OPENGNSYS_CLIENT_PASSWD=$DEFAULT_OPENGNSYS_CLIENT_PASSWD |
---|
| 76 | fi |
---|
| 77 | break |
---|
| 78 | fi |
---|
| 79 | done |
---|
| 80 | |
---|
| 81 | echo -e "\\n==============================" |
---|
[1e7eaab] | 82 | |
---|
| 83 | # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). |
---|
[49c6891] | 84 | PROGRAMDIR=$(readlink -e $(dirname "$0")) |
---|
[35b0ef1] | 85 | PROGRAMNAME=$(basename "$0") |
---|
[07c3a59] | 86 | OPENGNSYS_SERVER="www.opengnsys.es" |
---|
[1e7eaab] | 87 | if [ -d "$PROGRAMDIR/../installer" ]; then |
---|
[6ef01d9] | 88 | USESVN=0 |
---|
[1e7eaab] | 89 | else |
---|
[6ef01d9] | 90 | USESVN=1 |
---|
[1e7eaab] | 91 | fi |
---|
[eb9424f] | 92 | SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/" |
---|
[1e7eaab] | 93 | |
---|
[a01156a] | 94 | WORKDIR=/tmp/opengnsys_installer |
---|
[1e7eaab] | 95 | mkdir -p $WORKDIR |
---|
| 96 | |
---|
[42a0e41] | 97 | # Directorio destino de OpenGnSys. |
---|
[1e7eaab] | 98 | INSTALL_TARGET=/opt/opengnsys |
---|
[42a0e41] | 99 | |
---|
| 100 | # Registro de incidencias. |
---|
| 101 | OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log |
---|
[acfb07d] | 102 | LOG_FILE=/tmp/$(basename $OGLOGFILE) |
---|
[a01156a] | 103 | |
---|
[fd021b0] | 104 | # Usuario del cliente para acceso remoto. |
---|
| 105 | OPENGNSYS_CLIENT_USER="opengnsys" |
---|
| 106 | |
---|
| 107 | # Nombre de la base datos y fichero SQL para su creación. |
---|
| 108 | OPENGNSYS_DATABASE="ogAdmBD" |
---|
| 109 | OPENGNSYS_DB_CREATION_FILE=opengnsys/admin/Database/${OPENGNSYS_DATABASE}.sql |
---|
[3aaf91d] | 110 | |
---|
[a01156a] | 111 | |
---|
| 112 | ##################################################################### |
---|
[d168a46] | 113 | ####### Funciones de configuración |
---|
| 114 | ##################################################################### |
---|
| 115 | |
---|
| 116 | # Generar variables de configuración del instalador |
---|
| 117 | # Variables globales: |
---|
| 118 | # - OSDISTRIB, OSCODENAME - datos de la distribución Linux |
---|
| 119 | # - DEPENDENCIES - array de dependencias que deben estar instaladas |
---|
| 120 | # - UPDATEPKGLIST, INSTALLPKGS, CHECKPKGS - comandos para gestión de paquetes |
---|
[109e8b2] | 121 | # - INSTALLEXTRADEPS - instalar dependencias no incluidas en la distribución |
---|
[53fba30] | 122 | # - STARTSERVICE, ENABLESERVICE - iniciar y habilitar un servicio |
---|
[109e8b2] | 123 | # - STOPSERVICE, DISABLESERVICE - parar y deshabilitar un servicio |
---|
[53fba30] | 124 | # - APACHESERV, APACHECFGDIR, APACHESITESDIR, APACHEUSER, APACHEGROUP - servicio y configuración de Apache |
---|
[7825e9e] | 125 | # - APACHESSLMOD, APACHEENABLESSL, APACHEMAKECERT - habilitar módulo Apache y certificado SSL |
---|
[53fba30] | 126 | # - APACHEENABLEOG, APACHEOGSITE, - habilitar sitio web de OpenGnSys |
---|
| 127 | # - INETDSERV - servicio Inetd |
---|
[109e8b2] | 128 | # - IPTABLESSERV - servicio IPTables |
---|
[53fba30] | 129 | # - DHCPSERV, DHCPCFGDIR - servicio y configuración de DHCP |
---|
[09bf701] | 130 | # - MYSQLSERV, TMPMYCNF - servicio MySQL y fichero temporal con credenciales de acceso. |
---|
[e70925a] | 131 | # - RSYNCSERV, RSYNCCFGDIR - servicio y configuración de Rsync |
---|
[53fba30] | 132 | # - SAMBASERV, SAMBACFGDIR - servicio y configuración de Samba |
---|
[297df16] | 133 | # - TFTPSERV, TFTPCFGDIR, SYSLINUXDIR - servicio y configuración de TFTP/PXE |
---|
[d168a46] | 134 | function autoConfigure() |
---|
| 135 | { |
---|
| 136 | # Detectar sistema operativo del servidor (debe soportar LSB). |
---|
| 137 | OSDISTRIB=$(lsb_release -is 2>/dev/null) |
---|
| 138 | OSCODENAME=$(lsb_release -cs 2>/dev/null) |
---|
| 139 | |
---|
[684b3e6] | 140 | # Configuración según la distribución GNU/Linux. |
---|
[d168a46] | 141 | case "$OSDISTRIB" in |
---|
[0fe2488] | 142 | Ubuntu|Debian|LinuxMint) |
---|
[d70a45f] | 143 | DEPENDENCIES=( subversion apache2 php5 php5-ldap libapache2-mod-php5 mysql-server php5-mysql isc-dhcp-server bittorrent tftp-hpa tftpd-hpa syslinux xinetd build-essential g++-multilib libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent samba rsync unzip netpipes debootstrap schroot squashfs-tools btrfs-tools procps ) |
---|
[d168a46] | 144 | UPDATEPKGLIST="apt-get update" |
---|
| 145 | INSTALLPKG="apt-get -y install --force-yes" |
---|
| 146 | CHECKPKG="dpkg -s \$package 2>/dev/null | grep Status | grep -qw install" |
---|
[53fba30] | 147 | if which service &>/dev/null; then |
---|
[7ba85a4] | 148 | STARTSERVICE="eval service \$service restart" |
---|
[109e8b2] | 149 | STOPSERVICE="eval service \$service stop" |
---|
[53fba30] | 150 | else |
---|
[7ba85a4] | 151 | STARTSERVICE="eval /etc/init.d/\$service restart" |
---|
[109e8b2] | 152 | STOPSERVICE="eval /etc/init.d/\$service stop" |
---|
[53fba30] | 153 | fi |
---|
[7ba85a4] | 154 | ENABLESERVICE="eval update-rc.d \$service defaults" |
---|
[109e8b2] | 155 | DISABLESERVICE="eval update-rc.d \$service disable" |
---|
[53fba30] | 156 | APACHESERV=apache2 |
---|
[d168a46] | 157 | APACHECFGDIR=/etc/apache2 |
---|
[643ca8c] | 158 | APACHESITESDIR=sites-available |
---|
[53fba30] | 159 | APACHEOGSITE=opengnsys |
---|
[d168a46] | 160 | APACHEUSER="www-data" |
---|
| 161 | APACHEGROUP="www-data" |
---|
[7ba85a4] | 162 | APACHESSLMOD="a2enmod ssl" |
---|
| 163 | APACHEENABLESSL="a2ensite default-ssl" |
---|
[53fba30] | 164 | APACHEENABLEOG="a2ensite $APACHEOGSITE" |
---|
[643ca8c] | 165 | APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite" |
---|
[53fba30] | 166 | DHCPSERV=isc-dhcp-server |
---|
[83518d5] | 167 | DHCPCFGDIR=/etc/dhcp |
---|
[f243a47] | 168 | INETDSERV=xinetd |
---|
| 169 | INETDCFGDIR=/etc/xinetd.d |
---|
[53fba30] | 170 | MYSQLSERV=mysql |
---|
[e70925a] | 171 | RSYNCSERV=rsync |
---|
| 172 | RSYNCCFGDIR=/etc |
---|
[53fba30] | 173 | SAMBASERV=smbd |
---|
[d168a46] | 174 | SAMBACFGDIR=/etc/samba |
---|
[297df16] | 175 | SYSLINUXDIR=/usr/lib/syslinux |
---|
[d168a46] | 176 | TFTPCFGDIR=/var/lib/tftpboot |
---|
| 177 | ;; |
---|
[5fcf180] | 178 | Fedora|CentOS) |
---|
[d70a45f] | 179 | DEPENDENCIES=( subversion httpd mod_ssl php php-ldap mysql-server mysql-devel mysql-devel.i686 php-mysql dhcp tftp-server tftp syslinux xinetd binutils gcc gcc-c++ glibc-devel glibc-devel.i686 glibc-static glibc-static.i686 libstdc++ libstdc++.i686 libstdc++-static.i686 libstdc++-devel.i686 make wget doxygen graphviz ctorrent samba rsync unzip debootstrap schroot squashfs-tools btrfs-progs procps-ng ) |
---|
[109e8b2] | 180 | INSTALLEXTRADEPS=( 'rpm -Uv ftp://ftp.altlinux.org/pub/distributions/ALTLinux/5.1/branch/files/i586/RPMS/netpipes-4.2-alt1.i586.rpm' |
---|
[03cfd6e] | 181 | 'pushd /tmp; wget http://download.bittornado.com/download/BitTornado-0.3.18.tar.gz; tar xvzf BitTornado-0.3.18.tar.gz; cd BitTornado-CVS; python setup.py install; ln -fs btlaunchmany.py /usr/bin/btlaunchmany; ln -fs bttrack.py /usr/bin/bttrack; popd' ) |
---|
| 182 | if [ "$OSDISTRIB" == "CentOS" ]; then |
---|
| 183 | UPDATEPKGLIST='test rpm -q --quiet epel-release || echo -e "[epel]\nname=EPEL temporal\nmirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-\$releasever&arch=\$basearch\nenabled=1\ngpgcheck=0" >/etc/yum.repos.d/epel.repo' |
---|
| 184 | fi |
---|
[d168a46] | 185 | INSTALLPKG="yum install -y" |
---|
[c79a2b3] | 186 | CHECKPKG="rpm -q --quiet \$package" |
---|
[03cfd6e] | 187 | SYSTEMD=$(which systemctl 2>/dev/null) |
---|
| 188 | if [ -n "$SYSTEMD" ]; then |
---|
| 189 | STARTSERVICE="eval systemctl start \$service.service" |
---|
| 190 | STOPSERVICE="eval systemctl stop \$service.service" |
---|
| 191 | ENABLESERVICE="eval systemctl enable \$service.service" |
---|
| 192 | DISABLESERVICE="eval systemctl disable \$service.service" |
---|
| 193 | else |
---|
| 194 | STARTSERVICE="eval service \$service start" |
---|
| 195 | STOPSERVICE="eval service \$service stop" |
---|
| 196 | ENABLESERVICE="eval chkconfig \$service on" |
---|
| 197 | DISABLESERVICE="eval chkconfig \$service off" |
---|
| 198 | fi |
---|
[53fba30] | 199 | APACHESERV=httpd |
---|
[d168a46] | 200 | APACHECFGDIR=/etc/httpd/conf.d |
---|
[53fba30] | 201 | APACHEOGSITE=opengnsys.conf |
---|
[d168a46] | 202 | APACHEUSER="apache" |
---|
| 203 | APACHEGROUP="apache" |
---|
[53fba30] | 204 | DHCPSERV=dhcpd |
---|
[d168a46] | 205 | DHCPCFGDIR=/etc/dhcp |
---|
[53fba30] | 206 | INETDSERV=xinetd |
---|
[f243a47] | 207 | INETDCFGDIR=/etc/xinetd.d |
---|
[b83843c] | 208 | IPTABLESSERV=iptables |
---|
[53fba30] | 209 | MYSQLSERV=mysqld |
---|
[e70925a] | 210 | RSYNCSERV=rsync |
---|
| 211 | RSYNCCFGDIR=/etc |
---|
[53fba30] | 212 | SAMBASERV=smb |
---|
[d168a46] | 213 | SAMBACFGDIR=/etc/samba |
---|
[297df16] | 214 | SYSLINUXDIR=/usr/share/syslinux |
---|
[53fba30] | 215 | TFTPSERV=tftp |
---|
[d168a46] | 216 | TFTPCFGDIR=/var/lib/tftpboot |
---|
| 217 | ;; |
---|
| 218 | "") echo "ERROR: Unknown Linux distribution, please install \"lsb_release\" command." |
---|
| 219 | exit 1 ;; |
---|
| 220 | *) echo "ERROR: Distribution not supported by OpenGnSys." |
---|
| 221 | exit 1 ;; |
---|
| 222 | esac |
---|
[09bf701] | 223 | |
---|
| 224 | # Fichero de credenciales de acceso a MySQL. |
---|
| 225 | TMPMYCNF=/tmp/.my.cnf.$$ |
---|
[d168a46] | 226 | } |
---|
| 227 | |
---|
[ff6c349] | 228 | # Modificar variables de configuración tras instalar paquetes del sistema. |
---|
| 229 | function autoConfigurePost() |
---|
| 230 | { |
---|
[03cfd6e] | 231 | [ -z "$SYSTEMD" -a ! -e /etc/init.d/$SAMBASERV ] && SAMBASERV=samba # Debian 6 |
---|
| 232 | [ ! -e $TFTPCFGDIR ] && TFTPCFGDIR=/srv/tftp # Debian 6 |
---|
[ea60f41] | 233 | [ -f /selinux/enforce ] && echo 0 > /selinux/enforce # SELinux permisivo |
---|
[c972d5aa] | 234 | selinuxenabled && setenforce 0 2>/dev/null # SELinux permisivo (Fedora 17) |
---|
[ff6c349] | 235 | } |
---|
| 236 | |
---|
| 237 | |
---|
[83518d5] | 238 | # Cargar lista de paquetes del sistema y actualizar algunas variables de configuración |
---|
| 239 | # dependiendo de la versión instalada. |
---|
| 240 | function updatePackageList() |
---|
| 241 | { |
---|
| 242 | local DHCPVERSION |
---|
| 243 | |
---|
| 244 | # Si es necesario, actualizar la lista de paquetes disponibles. |
---|
| 245 | [ -n "$UPDATEPKGLIST" ] && eval $UPDATEPKGLIST |
---|
| 246 | |
---|
| 247 | # Configuración personallizada de algunos paquetes. |
---|
| 248 | case "$OSDISTRIB" in |
---|
[109e8b2] | 249 | Ubuntu|LinuxMint) # Postconfiguación personalizada para Ubuntu. |
---|
[83518d5] | 250 | # Configuración para DHCP v3. |
---|
[e4b1572] | 251 | DHCPVERSION=$(apt-cache show $(apt-cache pkgnames|egrep "dhcp.?-server$") | \ |
---|
[83518d5] | 252 | awk '/Version/ {print substr($2,1,1);}' | \ |
---|
| 253 | sort -n | tail -1) |
---|
| 254 | if [ $DHCPVERSION = 3 ]; then |
---|
[e4b1572] | 255 | DEPENDENCIES=( ${DEPENDENCIES[@]/isc-dhcp-server/dhcp3-server} ) |
---|
[53fba30] | 256 | DHCPSERV=dhcp3-server |
---|
[83518d5] | 257 | DHCPCFGDIR=/etc/dhcp3 |
---|
| 258 | fi |
---|
| 259 | ;; |
---|
[109e8b2] | 260 | CentOS) # Postconfiguación personalizada para CentOS. |
---|
| 261 | # Incluir repositorio de paquetes EPEL. |
---|
[c79a2b3] | 262 | DEPENDENCIES=( ${DEPENDENCIES[@]} epel-release ) |
---|
| 263 | ;; |
---|
[83518d5] | 264 | esac |
---|
| 265 | } |
---|
| 266 | |
---|
[d168a46] | 267 | |
---|
| 268 | ##################################################################### |
---|
[a01156a] | 269 | ####### Algunas funciones útiles de propósito general: |
---|
| 270 | ##################################################################### |
---|
[d168a46] | 271 | |
---|
[13a01a7] | 272 | function getDateTime() |
---|
[a01156a] | 273 | { |
---|
[d168a46] | 274 | date "+%Y%m%d-%H%M%S" |
---|
[a01156a] | 275 | } |
---|
| 276 | |
---|
| 277 | # Escribe a fichero y muestra por pantalla |
---|
[13a01a7] | 278 | function echoAndLog() |
---|
[a01156a] | 279 | { |
---|
[d168a46] | 280 | local DATETIME=`getDateTime` |
---|
[87c7b02] | 281 | echo "$1" |
---|
[d168a46] | 282 | echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
[a01156a] | 283 | } |
---|
| 284 | |
---|
[87c7b02] | 285 | # Escribe a fichero y muestra mensaje de error |
---|
[13a01a7] | 286 | function errorAndLog() |
---|
[a01156a] | 287 | { |
---|
[d168a46] | 288 | local DATETIME=`getDateTime` |
---|
[87c7b02] | 289 | echo "ERROR: $1" |
---|
[d168a46] | 290 | echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
[a01156a] | 291 | } |
---|
| 292 | |
---|
[87c7b02] | 293 | # Comprueba si el elemento pasado en $2 está en el array $1 |
---|
[13a01a7] | 294 | function isInArray() |
---|
[a01156a] | 295 | { |
---|
| 296 | if [ $# -ne 2 ]; then |
---|
[13a01a7] | 297 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 298 | exit 1 |
---|
| 299 | fi |
---|
| 300 | |
---|
| 301 | local deps |
---|
[87c7b02] | 302 | local is_in_array=1 |
---|
| 303 | local element="$2" |
---|
| 304 | |
---|
| 305 | echoAndLog "${FUNCNAME}(): checking if $2 is in $1" |
---|
[5c33840] | 306 | eval "deps=( \"\${$1[@]}\" )" |
---|
[a01156a] | 307 | |
---|
[87c7b02] | 308 | # Copia local del array del parámetro 1. |
---|
| 309 | for (( i = 0 ; i < ${#deps[@]} ; i++ )); do |
---|
| 310 | if [ "${deps[$i]}" = "${element}" ]; then |
---|
| 311 | echoAndLog "isInArray(): $element found in array" |
---|
[a01156a] | 312 | is_in_array=0 |
---|
| 313 | fi |
---|
| 314 | done |
---|
| 315 | |
---|
| 316 | if [ $is_in_array -ne 0 ]; then |
---|
[87c7b02] | 317 | echoAndLog "${FUNCNAME}(): $element NOT found in array" |
---|
[a01156a] | 318 | fi |
---|
| 319 | |
---|
| 320 | return $is_in_array |
---|
| 321 | } |
---|
| 322 | |
---|
[87c7b02] | 323 | |
---|
[a01156a] | 324 | ##################################################################### |
---|
| 325 | ####### Funciones de manejo de paquetes Debian |
---|
| 326 | ##################################################################### |
---|
| 327 | |
---|
[13a01a7] | 328 | function checkPackage() |
---|
[a01156a] | 329 | { |
---|
| 330 | package=$1 |
---|
| 331 | if [ -z $package ]; then |
---|
[73cfa0a] | 332 | errorAndLog "${FUNCNAME}(): parameter required" |
---|
[a01156a] | 333 | exit 1 |
---|
| 334 | fi |
---|
[73cfa0a] | 335 | echoAndLog "${FUNCNAME}(): checking if package $package exists" |
---|
[d168a46] | 336 | eval $CHECKPKG |
---|
[a01156a] | 337 | if [ $? -eq 0 ]; then |
---|
[73cfa0a] | 338 | echoAndLog "${FUNCNAME}(): package $package exists" |
---|
[a01156a] | 339 | return 0 |
---|
| 340 | else |
---|
[73cfa0a] | 341 | echoAndLog "${FUNCNAME}(): package $package doesn't exists" |
---|
[a01156a] | 342 | return 1 |
---|
| 343 | fi |
---|
| 344 | } |
---|
| 345 | |
---|
[87c7b02] | 346 | # Recibe array con dependencias |
---|
[a01156a] | 347 | # por referencia deja un array con las dependencias no resueltas |
---|
| 348 | # devuelve 1 si hay alguna dependencia no resuelta |
---|
[13a01a7] | 349 | function checkDependencies() |
---|
[a01156a] | 350 | { |
---|
| 351 | if [ $# -ne 2 ]; then |
---|
[73cfa0a] | 352 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 353 | exit 1 |
---|
| 354 | fi |
---|
| 355 | |
---|
[73cfa0a] | 356 | echoAndLog "${FUNCNAME}(): checking dependences" |
---|
[a01156a] | 357 | uncompletedeps=0 |
---|
| 358 | |
---|
| 359 | # copia local del array del parametro 1 |
---|
| 360 | local deps |
---|
[5c33840] | 361 | eval "deps=( \"\${$1[@]}\" )" |
---|
[a01156a] | 362 | |
---|
| 363 | declare -a local_notinstalled |
---|
[5c33840] | 364 | |
---|
[a01156a] | 365 | for (( i = 0 ; i < ${#deps[@]} ; i++ )) |
---|
| 366 | do |
---|
| 367 | checkPackage ${deps[$i]} |
---|
| 368 | if [ $? -ne 0 ]; then |
---|
| 369 | local_notinstalled[$uncompletedeps]=$package |
---|
| 370 | let uncompletedeps=uncompletedeps+1 |
---|
| 371 | fi |
---|
| 372 | done |
---|
| 373 | |
---|
| 374 | # relleno el array especificado en $2 por referencia |
---|
| 375 | for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ )) |
---|
| 376 | do |
---|
| 377 | eval "${2}[$i]=${local_notinstalled[$i]}" |
---|
| 378 | done |
---|
| 379 | |
---|
| 380 | # retorna el numero de paquetes no resueltos |
---|
[73cfa0a] | 381 | echoAndLog "${FUNCNAME}(): dependencies uncompleted: $uncompletedeps" |
---|
[a01156a] | 382 | return $uncompletedeps |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | # Recibe un array con las dependencias y lo instala |
---|
[13a01a7] | 386 | function installDependencies() |
---|
[a01156a] | 387 | { |
---|
| 388 | if [ $# -ne 1 ]; then |
---|
[813f617] | 389 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 390 | exit 1 |
---|
| 391 | fi |
---|
[813f617] | 392 | echoAndLog "${FUNCNAME}(): installing uncompleted dependencies" |
---|
[a01156a] | 393 | |
---|
| 394 | # copia local del array del parametro 1 |
---|
| 395 | local deps |
---|
[5c33840] | 396 | eval "deps=( \"\${$1[@]}\" )" |
---|
[a01156a] | 397 | |
---|
| 398 | local string_deps="" |
---|
| 399 | for (( i = 0 ; i < ${#deps[@]} ; i++ )) |
---|
| 400 | do |
---|
| 401 | string_deps="$string_deps ${deps[$i]}" |
---|
| 402 | done |
---|
| 403 | |
---|
| 404 | if [ -z "${string_deps}" ]; then |
---|
[813f617] | 405 | errorAndLog "${FUNCNAME}(): array of dependeces is empty" |
---|
[a01156a] | 406 | exit 1 |
---|
| 407 | fi |
---|
| 408 | |
---|
[c79a2b3] | 409 | OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND # Debian/Ubuntu |
---|
[a01156a] | 410 | export DEBIAN_FRONTEND=noninteractive |
---|
| 411 | |
---|
[d168a46] | 412 | echoAndLog "${FUNCNAME}(): now $string_deps will be installed" |
---|
| 413 | eval $INSTALLPKG $string_deps |
---|
[a01156a] | 414 | if [ $? -ne 0 ]; then |
---|
[813f617] | 415 | errorAndLog "${FUNCNAME}(): error installing dependencies" |
---|
[a01156a] | 416 | return 1 |
---|
| 417 | fi |
---|
| 418 | |
---|
[c79a2b3] | 419 | DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND # Debian/Ubuntu |
---|
[8244351] | 420 | test grep -q "EPEL temporal" /etc/yum.repos.d/epel.repo 2>/dev/null ] || mv -f /etc/yum.repos.d/epel.repo.rpmnew /etc/yum.repos.d/epel.repo 2>/dev/null # CentOS/RedHat EPEL |
---|
[c79a2b3] | 421 | |
---|
[813f617] | 422 | echoAndLog "${FUNCNAME}(): dependencies installed" |
---|
[a01156a] | 423 | } |
---|
| 424 | |
---|
[13a01a7] | 425 | # Hace un backup del fichero pasado por parámetro |
---|
| 426 | # deja un -last y uno para el día |
---|
| 427 | function backupFile() |
---|
| 428 | { |
---|
| 429 | if [ $# -ne 1 ]; then |
---|
| 430 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
| 431 | exit 1 |
---|
| 432 | fi |
---|
| 433 | |
---|
[d168a46] | 434 | local file="$1" |
---|
| 435 | local dateymd=`date +%Y%m%d` |
---|
[13a01a7] | 436 | |
---|
[d168a46] | 437 | if [ ! -f "$file" ]; then |
---|
| 438 | errorAndLog "${FUNCNAME}(): file $file doesn't exists" |
---|
[13a01a7] | 439 | return 1 |
---|
| 440 | fi |
---|
| 441 | |
---|
[d168a46] | 442 | echoAndLog "${FUNCNAME}(): making $file backup" |
---|
[13a01a7] | 443 | |
---|
| 444 | # realiza una copia de la última configuración como last |
---|
[d168a46] | 445 | cp -a "$file" "${file}-LAST" |
---|
[13a01a7] | 446 | |
---|
| 447 | # si para el día no hay backup lo hace, sino no |
---|
[d168a46] | 448 | if [ ! -f "${file}-${dateymd}" ]; then |
---|
| 449 | cp -a "$file" "${file}-${dateymd}" |
---|
[13a01a7] | 450 | fi |
---|
| 451 | |
---|
[d168a46] | 452 | echoAndLog "${FUNCNAME}(): $file backup success" |
---|
[13a01a7] | 453 | } |
---|
| 454 | |
---|
[a01156a] | 455 | ##################################################################### |
---|
| 456 | ####### Funciones para el manejo de bases de datos |
---|
| 457 | ##################################################################### |
---|
| 458 | |
---|
| 459 | # This function set password to root |
---|
[13a01a7] | 460 | function mysqlSetRootPassword() |
---|
[a01156a] | 461 | { |
---|
| 462 | if [ $# -ne 1 ]; then |
---|
[813f617] | 463 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 464 | exit 1 |
---|
| 465 | fi |
---|
| 466 | |
---|
[e0edc14] | 467 | local root_mysql="$1" |
---|
[813f617] | 468 | echoAndLog "${FUNCNAME}(): setting root password in MySQL server" |
---|
[e0edc14] | 469 | mysqladmin -u root password "$root_mysql" |
---|
[a01156a] | 470 | if [ $? -ne 0 ]; then |
---|
[813f617] | 471 | errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server" |
---|
[a01156a] | 472 | return 1 |
---|
| 473 | fi |
---|
[813f617] | 474 | echoAndLog "${FUNCNAME}(): root password saved!" |
---|
[a01156a] | 475 | return 0 |
---|
| 476 | } |
---|
| 477 | |
---|
[892606b9] | 478 | # Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente |
---|
[e0edc14] | 479 | function mysqlGetRootPassword() |
---|
| 480 | { |
---|
[892606b9] | 481 | local pass_mysql |
---|
| 482 | local pass_mysql2 |
---|
[7c54b49] | 483 | # Comprobar si MySQL está instalado con la clave de root por defecto. |
---|
| 484 | if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then |
---|
| 485 | echoAndLog "${FUNCNAME}(): Using default mysql root password." |
---|
| 486 | else |
---|
| 487 | stty -echo |
---|
[e0edc14] | 488 | echo "There is a MySQL service already installed." |
---|
| 489 | read -p "Enter MySQL root password: " pass_mysql |
---|
[7c54b49] | 490 | echo "" |
---|
[e0edc14] | 491 | read -p "Confrim password:" pass_mysql2 |
---|
[7c54b49] | 492 | echo "" |
---|
| 493 | stty echo |
---|
| 494 | if [ "$pass_mysql" == "$pass_mysql2" ] ;then |
---|
[e0edc14] | 495 | MYSQL_ROOT_PASSWORD="$pass_mysql" |
---|
[7c54b49] | 496 | return 0 |
---|
| 497 | else |
---|
[e0edc14] | 498 | echo "The keys don't match. Do not configure the server's key," |
---|
| 499 | echo "transactions in the database will give error." |
---|
[7c54b49] | 500 | return 1 |
---|
| 501 | fi |
---|
[892606b9] | 502 | fi |
---|
| 503 | } |
---|
| 504 | |
---|
[a01156a] | 505 | # comprueba si puede conectar con mysql con el usuario root |
---|
| 506 | function mysqlTestConnection() |
---|
| 507 | { |
---|
| 508 | if [ $# -ne 1 ]; then |
---|
[e0edc14] | 509 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 510 | exit 1 |
---|
| 511 | fi |
---|
| 512 | |
---|
[09bf701] | 513 | local root_password="$1" |
---|
[e0edc14] | 514 | echoAndLog "${FUNCNAME}(): checking connection to mysql..." |
---|
[09bf701] | 515 | # Componer fichero con credenciales de conexión a MySQL. |
---|
| 516 | touch $TMPMYCNF |
---|
| 517 | chmod 600 $TMPMYCNF |
---|
| 518 | cat << EOT > $TMPMYCNF |
---|
[c073224] | 519 | [client] |
---|
[09bf701] | 520 | user=root |
---|
| 521 | password=$root_password |
---|
| 522 | EOT |
---|
| 523 | # Borrar el fichero temporal si termina el proceso de instalación. |
---|
| 524 | trap "rm -f $TMPMYCNF" 0 1 2 3 6 9 15 |
---|
| 525 | # Comprobar conexión a MySQL. |
---|
| 526 | echo "" | mysql --defaults-extra-file=$TMPMYCNF |
---|
[a01156a] | 527 | if [ $? -ne 0 ]; then |
---|
[e0edc14] | 528 | errorAndLog "${FUNCNAME}(): connection to mysql failed, check root password and if daemon is running!" |
---|
[a01156a] | 529 | return 1 |
---|
| 530 | else |
---|
[e0edc14] | 531 | echoAndLog "${FUNCNAME}(): connection success" |
---|
[a01156a] | 532 | return 0 |
---|
| 533 | fi |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | # comprueba si la base de datos existe |
---|
| 537 | function mysqlDbExists() |
---|
| 538 | { |
---|
[09bf701] | 539 | if [ $# -ne 1 ]; then |
---|
[e0edc14] | 540 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 541 | exit 1 |
---|
| 542 | fi |
---|
| 543 | |
---|
[09bf701] | 544 | local database="$1" |
---|
[e0edc14] | 545 | echoAndLog "${FUNCNAME}(): checking if $database exists..." |
---|
[09bf701] | 546 | echo "show databases" | mysql --defaults-extra-file=$TMPMYCNF | grep "^${database}$" |
---|
[a01156a] | 547 | if [ $? -ne 0 ]; then |
---|
[e0edc14] | 548 | echoAndLog "${FUNCNAME}():database $database doesn't exists" |
---|
[a01156a] | 549 | return 1 |
---|
| 550 | else |
---|
[e0edc14] | 551 | echoAndLog "${FUNCNAME}():database $database exists" |
---|
[a01156a] | 552 | return 0 |
---|
| 553 | fi |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | function mysqlCheckDbIsEmpty() |
---|
| 557 | { |
---|
[09bf701] | 558 | if [ $# -ne 1 ]; then |
---|
[e0edc14] | 559 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 560 | exit 1 |
---|
| 561 | fi |
---|
| 562 | |
---|
[09bf701] | 563 | local database="$1" |
---|
[e0edc14] | 564 | echoAndLog "${FUNCNAME}(): checking if $database is empty..." |
---|
[09bf701] | 565 | num_tablas=`echo "show tables" | mysql --defaults-extra-file=$TMPMYCNF "${database}" | wc -l` |
---|
[a01156a] | 566 | if [ $? -ne 0 ]; then |
---|
[e0edc14] | 567 | errorAndLog "${FUNCNAME}(): error executing query, check database and root password" |
---|
[a01156a] | 568 | exit 1 |
---|
| 569 | fi |
---|
| 570 | |
---|
| 571 | if [ $num_tablas -eq 0 ]; then |
---|
[e0edc14] | 572 | echoAndLog "${FUNCNAME}():database $database is empty" |
---|
[a01156a] | 573 | return 0 |
---|
| 574 | else |
---|
[e0edc14] | 575 | echoAndLog "${FUNCNAME}():database $database has tables" |
---|
[a01156a] | 576 | return 1 |
---|
| 577 | fi |
---|
| 578 | |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | |
---|
| 582 | function mysqlImportSqlFileToDb() |
---|
| 583 | { |
---|
[09bf701] | 584 | if [ $# -ne 2 ]; then |
---|
[c5ce04c] | 585 | errorAndLog "${FNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 586 | exit 1 |
---|
| 587 | fi |
---|
| 588 | |
---|
[09bf701] | 589 | local database="$1" |
---|
| 590 | local sqlfile="$2" |
---|
[c4321ae] | 591 | local tmpfile=$(mktemp) |
---|
[d168a46] | 592 | local i=0 |
---|
| 593 | local dev="" |
---|
[c4321ae] | 594 | local status |
---|
[a01156a] | 595 | |
---|
| 596 | if [ ! -f $sqlfile ]; then |
---|
[c5ce04c] | 597 | errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!" |
---|
[a01156a] | 598 | return 1 |
---|
| 599 | fi |
---|
| 600 | |
---|
[d168a46] | 601 | echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..." |
---|
[c4321ae] | 602 | chmod 600 $tmpfile |
---|
[d168a46] | 603 | for dev in ${DEVICE[*]}; do |
---|
[73a1bd6] | 604 | if [ "${DEVICE[i]}" == "$DEFAULTDEV" ]; then |
---|
[d168a46] | 605 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
| 606 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
| 607 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
| 608 | $sqlfile > $tmpfile |
---|
| 609 | fi |
---|
| 610 | let i++ |
---|
| 611 | done |
---|
[09bf701] | 612 | mysql --defaults-extra-file=$TMPMYCNF --default-character-set=utf8 "${database}" < $tmpfile |
---|
[c4321ae] | 613 | status=$? |
---|
| 614 | rm -f $tmpfile |
---|
| 615 | if [ $status -ne 0 ]; then |
---|
[c5ce04c] | 616 | errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database" |
---|
[a01156a] | 617 | return 1 |
---|
| 618 | fi |
---|
[c5ce04c] | 619 | echoAndLog "${FUNCNAME}(): file imported to database $database" |
---|
[a01156a] | 620 | return 0 |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | # Crea la base de datos |
---|
| 624 | function mysqlCreateDb() |
---|
| 625 | { |
---|
[09bf701] | 626 | if [ $# -ne 1 ]; then |
---|
[a555f49] | 627 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 628 | exit 1 |
---|
| 629 | fi |
---|
| 630 | |
---|
[09bf701] | 631 | local database="$1" |
---|
[a01156a] | 632 | |
---|
[a555f49] | 633 | echoAndLog "${FUNCNAME}(): creating database..." |
---|
[09bf701] | 634 | mysqladmin --defaults-extra-file=$TMPMYCNF create $database |
---|
[a01156a] | 635 | if [ $? -ne 0 ]; then |
---|
[a555f49] | 636 | errorAndLog "${FUNCNAME}(): error while creating database $database" |
---|
[a01156a] | 637 | return 1 |
---|
| 638 | fi |
---|
[a555f49] | 639 | echoAndLog "${FUNCNAME}(): database $database created" |
---|
[a01156a] | 640 | return 0 |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | |
---|
| 644 | function mysqlCheckUserExists() |
---|
| 645 | { |
---|
[09bf701] | 646 | if [ $# -ne 1 ]; then |
---|
[e0edc14] | 647 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 648 | exit 1 |
---|
| 649 | fi |
---|
| 650 | |
---|
[09bf701] | 651 | local userdb="$1" |
---|
[a01156a] | 652 | |
---|
[e0edc14] | 653 | echoAndLog "${FUNCNAME}(): checking if $userdb exists..." |
---|
[09bf701] | 654 | echo "select user from user where user='${userdb}'\\G" |mysql --defaults-extra-file=$TMPMYCNF mysql | grep user |
---|
[a01156a] | 655 | if [ $? -ne 0 ]; then |
---|
[e0edc14] | 656 | echoAndLog "${FUNCNAME}(): user doesn't exists" |
---|
[a01156a] | 657 | return 1 |
---|
| 658 | else |
---|
[e0edc14] | 659 | echoAndLog "${FUNCNAME}(): user already exists" |
---|
[a01156a] | 660 | return 0 |
---|
| 661 | fi |
---|
| 662 | |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | # Crea un usuario administrativo para la base de datos |
---|
| 666 | function mysqlCreateAdminUserToDb() |
---|
| 667 | { |
---|
[09bf701] | 668 | if [ $# -ne 3 ]; then |
---|
[e0edc14] | 669 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 670 | exit 1 |
---|
| 671 | fi |
---|
| 672 | |
---|
[09bf701] | 673 | local database="$1" |
---|
| 674 | local userdb="$2" |
---|
| 675 | local passdb="$3" |
---|
[a01156a] | 676 | |
---|
[e0edc14] | 677 | echoAndLog "${FUNCNAME}(): creating admin user ${userdb} to database ${database}" |
---|
[a01156a] | 678 | |
---|
| 679 | cat > $WORKDIR/create_${database}.sql <<EOF |
---|
| 680 | GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ; |
---|
| 681 | GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ; |
---|
| 682 | FLUSH PRIVILEGES ; |
---|
| 683 | EOF |
---|
[09bf701] | 684 | mysql --defaults-extra-file=$TMPMYCNF < $WORKDIR/create_${database}.sql |
---|
[a01156a] | 685 | if [ $? -ne 0 ]; then |
---|
[e0edc14] | 686 | errorAndLog "${FUNCNAME}(): error while creating user in mysql" |
---|
[a01156a] | 687 | rm -f $WORKDIR/create_${database}.sql |
---|
| 688 | return 1 |
---|
| 689 | else |
---|
[e0edc14] | 690 | echoAndLog "${FUNCNAME}(): user created ok" |
---|
[a01156a] | 691 | rm -f $WORKDIR/create_${database}.sql |
---|
| 692 | return 0 |
---|
| 693 | fi |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | |
---|
| 697 | ##################################################################### |
---|
| 698 | ####### Funciones para el manejo de Subversion |
---|
| 699 | ##################################################################### |
---|
| 700 | |
---|
[13a01a7] | 701 | function svnExportCode() |
---|
| 702 | { |
---|
| 703 | if [ $# -ne 1 ]; then |
---|
| 704 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
| 705 | exit 1 |
---|
| 706 | fi |
---|
| 707 | |
---|
[6090a2d] | 708 | local url="$1" |
---|
[13a01a7] | 709 | |
---|
| 710 | echoAndLog "${FUNCNAME}(): downloading subversion code..." |
---|
| 711 | |
---|
[6090a2d] | 712 | svn export --force "$url" opengnsys |
---|
[13a01a7] | 713 | if [ $? -ne 0 ]; then |
---|
[6090a2d] | 714 | errorAndLog "${FUNCNAME}(): error getting OpenGnSys code from $url" |
---|
[13a01a7] | 715 | return 1 |
---|
| 716 | fi |
---|
| 717 | echoAndLog "${FUNCNAME}(): subversion code downloaded" |
---|
| 718 | return 0 |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | |
---|
[892606b9] | 722 | ############################################################ |
---|
[7586ca3] | 723 | ### Detectar red |
---|
| 724 | ############################################################ |
---|
| 725 | |
---|
[07c3a59] | 726 | # Comprobar si existe conexión. |
---|
| 727 | function checkNetworkConnection() |
---|
| 728 | { |
---|
[109e8b2] | 729 | echoAndLog "${FUNCNAME}(): Disabling IPTables." |
---|
[8244351] | 730 | if [ -n "$IPTABLESSERV" ]; then |
---|
| 731 | service=$IPTABLESSERV |
---|
[b83843c] | 732 | $STOPSERVICE; $DISABLESERVICE |
---|
| 733 | fi |
---|
[109e8b2] | 734 | |
---|
| 735 | echoAndLog "${FUNCNAME}(): Checking OpenGnSys server conectivity." |
---|
[07c3a59] | 736 | OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"} |
---|
| 737 | wget --spider -q $OPENGNSYS_SERVER |
---|
| 738 | } |
---|
| 739 | |
---|
| 740 | # Obtener los parámetros de red de la interfaz por defecto. |
---|
[7586ca3] | 741 | function getNetworkSettings() |
---|
| 742 | { |
---|
[d168a46] | 743 | # Arrays globales definidas: |
---|
| 744 | # - DEVICE: nombres de dispositivos de red activos. |
---|
| 745 | # - SERVERIP: IPs locales del servidor. |
---|
| 746 | # - NETIP: IPs de redes. |
---|
| 747 | # - NETMASK: máscaras de red. |
---|
| 748 | # - NETBROAD: IPs de difusión de redes. |
---|
| 749 | # - ROUTERIP: IPs de routers. |
---|
| 750 | # Otras variables globales: |
---|
| 751 | # - DEFAULTDEV: dispositivo de red por defecto. |
---|
| 752 | # - DNSIP: IP del servidor DNS principal. |
---|
| 753 | |
---|
| 754 | local i=0 |
---|
| 755 | local dev="" |
---|
| 756 | |
---|
[109e8b2] | 757 | echoAndLog "${FUNCNAME}(): Detecting network parameters." |
---|
[d168a46] | 758 | DEVICE=( $(ip -o link show up | awk '!/loopback/ {sub(/:.*/,"",$2); print $2}') ) |
---|
| 759 | if [ -z "$DEVICE" ]; then |
---|
| 760 | errorAndLog "${FUNCNAME}(): Network devices not detected." |
---|
[62e3bcf] | 761 | exit 1 |
---|
| 762 | fi |
---|
[d168a46] | 763 | for dev in ${DEVICE[*]}; do |
---|
| 764 | SERVERIP[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}') |
---|
| 765 | if [ -n "${SERVERIP[i]}" ]; then |
---|
[03cfd6e] | 766 | NETMASK[i]=$(LANG=C ifconfig $dev | \ |
---|
| 767 | awk '/Mask/ {sub(/.*:/,"",$4); print $4} |
---|
| 768 | /netmask/ {print $4}') |
---|
[d168a46] | 769 | NETBROAD[i]=$(ip -o addr show dev $dev | awk '$3~/inet$/ {print ($6)}') |
---|
| 770 | NETIP[i]=$(netstat -nr | awk -v d="$dev" '$1!~/0\.0\.0\.0/&&$8==d {if (n=="") n=$1} END {print n}') |
---|
| 771 | ROUTERIP[i]=$(netstat -nr | awk -v d="$dev" '$1~/0\.0\.0\.0/&&$8==d {print $2}') |
---|
| 772 | DEFAULTDEV=${DEFAULTDEV:-"$dev"} |
---|
| 773 | fi |
---|
[ce85ae8] | 774 | let i++ |
---|
[d168a46] | 775 | done |
---|
[a555f49] | 776 | DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1) |
---|
[03cfd6e] | 777 | if [ -z "${NETIP[*]}" -o -z "${NETMASK[*]}" ]; then |
---|
[62e3bcf] | 778 | errorAndLog "${FUNCNAME}(): Network not detected." |
---|
[7586ca3] | 779 | exit 1 |
---|
| 780 | fi |
---|
[cc7eab7] | 781 | |
---|
| 782 | # Variables de ejecución de Apache |
---|
| 783 | # - APACHE_RUN_USER |
---|
| 784 | # - APACHE_RUN_GROUP |
---|
[d168a46] | 785 | if [ -f $APACHECFGDIR/envvars ]; then |
---|
| 786 | source $APACHECFGDIR/envvars |
---|
[cc7eab7] | 787 | fi |
---|
[d168a46] | 788 | APACHE_RUN_USER=${APACHE_RUN_USER:-"$APACHEUSER"} |
---|
| 789 | APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"$APACHEGROUP"} |
---|
[73a1bd6] | 790 | |
---|
| 791 | echoAndLog "${FUNCNAME}(): Default network device: $DEFAULTDEV." |
---|
[7586ca3] | 792 | } |
---|
| 793 | |
---|
| 794 | |
---|
| 795 | ############################################################ |
---|
[892606b9] | 796 | ### Esqueleto para el Servicio pxe y contenedor tftpboot ### |
---|
| 797 | ############################################################ |
---|
| 798 | |
---|
[e0edc14] | 799 | function tftpConfigure() |
---|
| 800 | { |
---|
[109e8b2] | 801 | echoAndLog "${FUNCNAME}(): Configuring TFTP service." |
---|
| 802 | # Habilitar TFTP y reiniciar Inetd. |
---|
[8244351] | 803 | if [ -n "$TFTPSERV" ]; then |
---|
| 804 | service=$TFTPSERV |
---|
| 805 | $ENABLESERVICE |
---|
| 806 | fi |
---|
[53fba30] | 807 | service=$INETDSERV |
---|
| 808 | $ENABLESERVICE; $STARTSERVICE |
---|
[892606b9] | 809 | |
---|
[297df16] | 810 | # preparacion contenedor tftpboot |
---|
| 811 | cp -a $SYSLINUXDIR $TFTPCFGDIR/syslinux |
---|
| 812 | cp -a $SYSLINUXDIR/pxelinux.0 $TFTPCFGDIR |
---|
| 813 | # prepamos el directorio de la configuracion de pxe |
---|
| 814 | mkdir -p $TFTPCFGDIR/pxelinux.cfg |
---|
| 815 | cat > $TFTPCFGDIR/pxelinux.cfg/default <<EOF |
---|
[8fc9552] | 816 | DEFAULT syslinux/vesamenu.c32 |
---|
| 817 | MENU TITLE Aplicacion GNSYS |
---|
| 818 | |
---|
| 819 | LABEL 1 |
---|
| 820 | MENU LABEL 1 |
---|
| 821 | KERNEL syslinux/chain.c32 |
---|
| 822 | APPEND hd0 |
---|
| 823 | |
---|
| 824 | PROMPT 0 |
---|
| 825 | TIMEOUT 10 |
---|
[892606b9] | 826 | EOF |
---|
[297df16] | 827 | # comprobamos el servicio tftp |
---|
| 828 | sleep 1 |
---|
| 829 | testPxe |
---|
[892606b9] | 830 | } |
---|
| 831 | |
---|
[e0edc14] | 832 | function testPxe () |
---|
| 833 | { |
---|
[297df16] | 834 | echoAndLog "${FUNCNAME}(): Checking TFTP service... please wait." |
---|
| 835 | pushd /tmp |
---|
| 836 | tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echoAndLog "TFTP service is OK." || errorAndLog "TFTP service is down." |
---|
| 837 | popd |
---|
[892606b9] | 838 | } |
---|
| 839 | |
---|
[8fc9552] | 840 | |
---|
[892606b9] | 841 | ######################################################################## |
---|
[e4b1572] | 842 | ## Configuracion servicio NFS |
---|
| 843 | ######################################################################## |
---|
| 844 | |
---|
| 845 | # Configurar servicio NFS. |
---|
| 846 | # ADVERTENCIA: usa variables globales NETIP y NETMASK! |
---|
| 847 | function nfsConfigure() |
---|
| 848 | { |
---|
| 849 | echoAndLog "${FUNCNAME}(): Config nfs server." |
---|
| 850 | backupFile /etc/exports |
---|
| 851 | |
---|
| 852 | nfsAddExport $INSTALL_TARGET/client ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync |
---|
| 853 | if [ $? -ne 0 ]; then |
---|
| 854 | errorAndLog "${FUNCNAME}(): error while adding NFS client config" |
---|
| 855 | return 1 |
---|
| 856 | fi |
---|
| 857 | |
---|
| 858 | nfsAddExport $INSTALL_TARGET/images ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync,crossmnt |
---|
| 859 | if [ $? -ne 0 ]; then |
---|
| 860 | errorAndLog "${FUNCNAME}(): error while adding NFS images config" |
---|
| 861 | return 1 |
---|
| 862 | fi |
---|
| 863 | |
---|
| 864 | nfsAddExport $INSTALL_TARGET/log/clients ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync |
---|
| 865 | if [ $? -ne 0 ]; then |
---|
| 866 | errorAndLog "${FUNCNAME}(): error while adding logging client config" |
---|
| 867 | return 1 |
---|
| 868 | fi |
---|
| 869 | |
---|
| 870 | nfsAddExport $INSTALL_TARGET/tftpboot ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync |
---|
| 871 | if [ $? -ne 0 ]; then |
---|
| 872 | errorAndLog "${FUNCNAME}(): error while adding second filesystem for the PXE ogclient" |
---|
| 873 | return 1 |
---|
| 874 | fi |
---|
| 875 | |
---|
| 876 | /etc/init.d/nfs-kernel-server restart |
---|
| 877 | exportfs -va |
---|
| 878 | if [ $? -ne 0 ]; then |
---|
| 879 | errorAndLog "${FUNCNAME}(): error while configure exports" |
---|
| 880 | return 1 |
---|
| 881 | fi |
---|
| 882 | |
---|
| 883 | echoAndLog "${FUNCNAME}(): Added NFS configuration to file \"/etc/exports\"." |
---|
| 884 | return 0 |
---|
| 885 | } |
---|
| 886 | |
---|
| 887 | |
---|
| 888 | # Añadir entrada en fichero de configuración del servidor NFS. |
---|
| 889 | # Ejemplos: |
---|
| 890 | #nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0:ro,no_subtree_check,no_root_squash,sync |
---|
| 891 | #nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0 |
---|
| 892 | #nfsAddExport /opt/opengnsys 80.20.2.1:ro 192.123.32.2:rw |
---|
| 893 | function nfsAddExport() |
---|
| 894 | { |
---|
| 895 | if [ $# -lt 2 ]; then |
---|
| 896 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
| 897 | exit 1 |
---|
| 898 | fi |
---|
| 899 | if [ ! -f /etc/exports ]; then |
---|
| 900 | errorAndLog "${FUNCNAME}(): /etc/exports don't exists" |
---|
| 901 | return 1 |
---|
| 902 | fi |
---|
| 903 | |
---|
| 904 | local export="$1" |
---|
| 905 | local contador=0 |
---|
| 906 | local cadenaexport |
---|
| 907 | |
---|
| 908 | grep "^$export" /etc/exports > /dev/null |
---|
| 909 | if [ $? -eq 0 ]; then |
---|
| 910 | echoAndLog "${FUNCNAME}(): $export exists in /etc/exports, omiting" |
---|
| 911 | return 0 |
---|
| 912 | fi |
---|
| 913 | |
---|
| 914 | cadenaexport="${export}" |
---|
| 915 | for parametro in $*; do |
---|
| 916 | if [ $contador -gt 0 ]; then |
---|
| 917 | host=`echo $parametro | awk -F: '{print $1}'` |
---|
| 918 | options=`echo $parametro | awk -F: '{print $2}'` |
---|
| 919 | if [ "${host}" == "" ]; then |
---|
| 920 | errorAndLog "${FUNCNAME}(): host can't be empty" |
---|
| 921 | return 1 |
---|
| 922 | fi |
---|
| 923 | cadenaexport="${cadenaexport}\t${host}" |
---|
| 924 | |
---|
| 925 | if [ "${options}" != "" ]; then |
---|
| 926 | cadenaexport="${cadenaexport}(${options})" |
---|
| 927 | fi |
---|
| 928 | fi |
---|
| 929 | let contador=contador+1 |
---|
| 930 | done |
---|
| 931 | |
---|
| 932 | echo -en "$cadenaexport\n" >> /etc/exports |
---|
| 933 | |
---|
| 934 | echoAndLog "${FUNCNAME}(): add $export to /etc/exports" |
---|
| 935 | return 0 |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | |
---|
| 939 | ######################################################################## |
---|
[813f617] | 940 | ## Configuracion servicio Samba |
---|
[8fc9552] | 941 | ######################################################################## |
---|
[e4b1572] | 942 | |
---|
| 943 | # Configurar servicios Samba. |
---|
[8fc9552] | 944 | function smbConfigure() |
---|
| 945 | { |
---|
[e0edc14] | 946 | echoAndLog "${FUNCNAME}(): Configuring Samba service." |
---|
[8fc9552] | 947 | |
---|
[d168a46] | 948 | backupFile $SAMBACFGDIR/smb.conf |
---|
[8fc9552] | 949 | |
---|
[813f617] | 950 | # Copiar plantailla de recursos para OpenGnSys |
---|
[c1e00e4] | 951 | sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ |
---|
[d168a46] | 952 | $WORKDIR/opengnsys/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf |
---|
[813f617] | 953 | # Configurar y recargar Samba" |
---|
[6addf73] | 954 | perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnSys Samba Server/" $SAMBACFGDIR/smb.conf |
---|
[03cfd6e] | 955 | if ! grep -q "smb-og" $SAMBACFGDIR/smb.conf; then |
---|
| 956 | echo "include = $SAMBACFGDIR/smb-og.conf" >> $SAMBACFGDIR/smb.conf |
---|
| 957 | fi |
---|
[53fba30] | 958 | service=$SAMBASERV |
---|
| 959 | $ENABLESERVICE; $STARTSERVICE |
---|
[8fc9552] | 960 | if [ $? -ne 0 ]; then |
---|
[813f617] | 961 | errorAndLog "${FUNCNAME}(): error while configure Samba" |
---|
[8fc9552] | 962 | return 1 |
---|
| 963 | fi |
---|
[eb9424f] | 964 | # Crear clave para usuario de acceso a los recursos. |
---|
[813f617] | 965 | echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | smbpasswd -a -s $OPENGNSYS_CLIENT_USER |
---|
[8fc9552] | 966 | |
---|
[813f617] | 967 | echoAndLog "${FUNCNAME}(): Added Samba configuration." |
---|
[8fc9552] | 968 | return 0 |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | |
---|
[b6906f7] | 972 | ######################################################################## |
---|
[e70925a] | 973 | ## Configuracion servicio Rsync |
---|
| 974 | ######################################################################## |
---|
| 975 | |
---|
| 976 | # Configurar servicio Rsync. |
---|
| 977 | function rsyncConfigure() |
---|
| 978 | { |
---|
| 979 | echoAndLog "${FUNCNAME}(): Configuring Rsync service." |
---|
| 980 | |
---|
| 981 | backupFile $RSYNCCFGDIR/rsyncd.conf |
---|
| 982 | |
---|
| 983 | # Configurar acceso a Rsync. |
---|
| 984 | sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENT_USER/g" \ |
---|
| 985 | $WORKDIR/opengnsys/repoman/etc/rsyncd.conf.tmpl > $RSYNCCFGDIR/rsyncd.conf |
---|
| 986 | sed -e "s/CLIENTUSER/$OPENGNSYS_CLIENT_USER/g" \ |
---|
| 987 | -e "s/CLIENTPASSWORD/$OPENGNSYS_CLIENT_PASSWD/g" \ |
---|
| 988 | $WORKDIR/opengnsys/repoman/etc/rsyncd.secrets.tmpl > $RSYNCCFGDIR/rsyncd.secrets |
---|
| 989 | chown root.root $RSYNCCFGDIR/rsyncd.secrets |
---|
| 990 | chmod 600 $RSYNCCFGDIR/rsyncd.secrets |
---|
| 991 | |
---|
| 992 | # Habilitar Rsync y reiniciar Inetd. |
---|
| 993 | if [ -n "$RSYNCSERV" ]; then |
---|
[4666588] | 994 | if [ -f /etc/default/rsync ]; then |
---|
| 995 | perl -pi -e 's/RSYNC_ENABLE=.*/RSYNC_ENABLE=inetd/' /etc/default/rsync |
---|
| 996 | fi |
---|
[f243a47] | 997 | if [ -f $INETDCFGDIR/rsync ]; then |
---|
| 998 | perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/rsync |
---|
| 999 | else |
---|
| 1000 | cat << EOT > $INETDCFGDIR/rsync |
---|
| 1001 | service rsync |
---|
| 1002 | { |
---|
| 1003 | disable = no |
---|
| 1004 | socket_type = stream |
---|
| 1005 | wait = no |
---|
| 1006 | user = root |
---|
| 1007 | server = $(which rsync) |
---|
| 1008 | server_args = --daemon |
---|
| 1009 | log_on_failure += USERID |
---|
| 1010 | flags = IPv6 |
---|
| 1011 | } |
---|
| 1012 | EOT |
---|
| 1013 | fi |
---|
[e70925a] | 1014 | service=$RSYNCSERV $ENABLESERVICE |
---|
| 1015 | service=$INETDSERV $STARTSERVICE |
---|
| 1016 | fi |
---|
| 1017 | |
---|
| 1018 | echoAndLog "${FUNCNAME}(): Added Rsync configuration." |
---|
| 1019 | return 0 |
---|
| 1020 | } |
---|
| 1021 | |
---|
| 1022 | |
---|
| 1023 | ######################################################################## |
---|
[b6906f7] | 1024 | ## Configuracion servicio DHCP |
---|
| 1025 | ######################################################################## |
---|
| 1026 | |
---|
[e4b1572] | 1027 | # Configurar servicios DHCP. |
---|
[7586ca3] | 1028 | function dhcpConfigure() |
---|
| 1029 | { |
---|
[836a7597] | 1030 | echoAndLog "${FUNCNAME}(): Sample DHCP configuration." |
---|
[a555f49] | 1031 | |
---|
[d168a46] | 1032 | local errcode=0 |
---|
| 1033 | local i=0 |
---|
| 1034 | local dev="" |
---|
| 1035 | |
---|
| 1036 | backupFile $DHCPCFGDIR/dhcpd.conf |
---|
| 1037 | for dev in ${DEVICE[*]}; do |
---|
[01a9904] | 1038 | if [ -n "${SERVERIP[i]}" ]; then |
---|
[d168a46] | 1039 | backupFile $DHCPCFGDIR/dhcpd-$dev.conf |
---|
[e4b1572] | 1040 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
| 1041 | -e "s/NETIP/${NETIP[i]}/g" \ |
---|
| 1042 | -e "s/NETMASK/${NETMASK[i]}/g" \ |
---|
| 1043 | -e "s/NETBROAD/${NETBROAD[i]}/g" \ |
---|
| 1044 | -e "s/ROUTERIP/${ROUTERIP[i]}/g" \ |
---|
[d168a46] | 1045 | -e "s/DNSIP/$DNSIP/g" \ |
---|
| 1046 | $WORKDIR/opengnsys/server/etc/dhcpd.conf.tmpl > $DHCPCFGDIR/dhcpd-$dev.conf || errcode=1 |
---|
| 1047 | fi |
---|
| 1048 | let i++ |
---|
| 1049 | done |
---|
| 1050 | if [ $errcode -ne 0 ]; then |
---|
[b25fc47] | 1051 | errorAndLog "${FUNCNAME}(): error while configuring DHCP server" |
---|
[a555f49] | 1052 | return 1 |
---|
| 1053 | fi |
---|
[d168a46] | 1054 | ln -f $DHCPCFGDIR/dhcpd-$DEFAULTDEV.conf $DHCPCFGDIR/dhcpd.conf |
---|
[53fba30] | 1055 | service=$DHCPSERV |
---|
| 1056 | $ENABLESERVICE; $STARTSERVICE |
---|
[d168a46] | 1057 | echoAndLog "${FUNCNAME}(): Sample DHCP configured in \"$DHCPCFGDIR\"." |
---|
[a555f49] | 1058 | return 0 |
---|
[892606b9] | 1059 | } |
---|
| 1060 | |
---|
| 1061 | |
---|
[a01156a] | 1062 | ##################################################################### |
---|
| 1063 | ####### Funciones específicas de la instalación de Opengnsys |
---|
| 1064 | ##################################################################### |
---|
| 1065 | |
---|
[49c6891] | 1066 | # Copiar ficheros del OpenGnSys Web Console. |
---|
[7586ca3] | 1067 | function installWebFiles() |
---|
| 1068 | { |
---|
[2b793a8] | 1069 | local COMPATDIR f |
---|
| 1070 | |
---|
[dce072b] | 1071 | echoAndLog "${FUNCNAME}(): Installing web files..." |
---|
[2b793a8] | 1072 | # Copiar ficheros. |
---|
| 1073 | cp -a $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para Doxygen. |
---|
[7586ca3] | 1074 | if [ $? != 0 ]; then |
---|
[dce072b] | 1075 | errorAndLog "${FUNCNAME}(): Error copying web files." |
---|
[7586ca3] | 1076 | exit 1 |
---|
| 1077 | fi |
---|
| 1078 | find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
[813f617] | 1079 | # Descomprimir XAJAX. |
---|
[b83843c] | 1080 | unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax |
---|
[2b793a8] | 1081 | # Compatibilidad con dispositivos móviles. |
---|
| 1082 | COMPATDIR="$INSTALL_TARGET/www/principal" |
---|
| 1083 | for f in acciones administracion aula aulas hardwares imagenes menus repositorios softwares; do |
---|
| 1084 | sed 's/clickcontextualnodo/clicksupnodo/g' $COMPATDIR/$f.php > $COMPATDIR/$f.device.php |
---|
| 1085 | done |
---|
| 1086 | cp -a $COMPATDIR/imagenes.device.php $COMPATDIR/imagenes.device4.php |
---|
[7586ca3] | 1087 | # Cambiar permisos para ficheros especiales. |
---|
[e6d22c6] | 1088 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/{fotos,iconos} |
---|
[b7bd0df] | 1089 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/tmp/ |
---|
[2b793a8] | 1090 | |
---|
[dce072b] | 1091 | echoAndLog "${FUNCNAME}(): Web files installed successfully." |
---|
[7586ca3] | 1092 | } |
---|
| 1093 | |
---|
| 1094 | # Configuración específica de Apache. |
---|
[73a1bd6] | 1095 | function installWebConsoleApacheConf() |
---|
[a01156a] | 1096 | { |
---|
| 1097 | if [ $# -ne 2 ]; then |
---|
[dce072b] | 1098 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 1099 | exit 1 |
---|
| 1100 | fi |
---|
| 1101 | |
---|
[f9e3393] | 1102 | local path_opengnsys_base="$1" |
---|
| 1103 | local path_apache2_confd="$2" |
---|
[30837bb] | 1104 | local CONSOLEDIR=${path_opengnsys_base}/www |
---|
[a01156a] | 1105 | |
---|
[892606b9] | 1106 | if [ ! -d $path_apache2_confd ]; then |
---|
[dce072b] | 1107 | errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation" |
---|
[892606b9] | 1108 | return 1 |
---|
| 1109 | fi |
---|
| 1110 | |
---|
[7586ca3] | 1111 | mkdir -p $path_apache2_confd/{sites-available,sites-enabled} |
---|
[892606b9] | 1112 | |
---|
[dce072b] | 1113 | echoAndLog "${FUNCNAME}(): creating apache2 config file.." |
---|
[a01156a] | 1114 | |
---|
[3ce53a7] | 1115 | # Activar HTTPS. |
---|
[7825e9e] | 1116 | $APACHESSLMOD |
---|
[643ca8c] | 1117 | $APACHEENABLESSL |
---|
| 1118 | $APACHEMAKECERT |
---|
[d725a41] | 1119 | |
---|
[30837bb] | 1120 | # Genera configuración de consola web a partir del fichero plantilla. |
---|
[f9e3393] | 1121 | if [ -n "$(apachectl -v | grep "2\.[0-2]")" ]; then |
---|
| 1122 | # Configuración para versiones anteriores de Apache. |
---|
| 1123 | sed -e "s/CONSOLEDIR/${CONSOLEDIR//\//\\/}/g" \ |
---|
| 1124 | $WORKDIR/opengnsys/server/etc/apache-prev2.4.conf.tmpl > $path_opengnsys_base/etc/apache.conf |
---|
| 1125 | ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE} |
---|
| 1126 | else |
---|
| 1127 | # Configuración específica a partir de Apache 2.4 |
---|
| 1128 | sed -e "s/CONSOLEDIR/${CONSOLEDIR//\//\\/}/g" \ |
---|
| 1129 | $WORKDIR/opengnsys/server/etc/apache.conf.tmpl > $path_opengnsys_base/etc/apache.conf |
---|
| 1130 | ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf |
---|
| 1131 | fi |
---|
[643ca8c] | 1132 | $APACHEENABLEOG |
---|
[a01156a] | 1133 | if [ $? -ne 0 ]; then |
---|
[dce072b] | 1134 | errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation" |
---|
[a01156a] | 1135 | return 1 |
---|
| 1136 | else |
---|
[dce072b] | 1137 | echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon" |
---|
[53fba30] | 1138 | service=$APACHESERV |
---|
| 1139 | $ENABLESERVICE; $STARTSERVICE |
---|
[a01156a] | 1140 | return 0 |
---|
| 1141 | fi |
---|
| 1142 | } |
---|
| 1143 | |
---|
[8fc9552] | 1144 | |
---|
[5d6bf97] | 1145 | # Crear documentación Doxygen para la consola web. |
---|
| 1146 | function makeDoxygenFiles() |
---|
| 1147 | { |
---|
| 1148 | echoAndLog "${FUNCNAME}(): Making Doxygen web files..." |
---|
| 1149 | $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \ |
---|
| 1150 | $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www |
---|
| 1151 | if [ ! -d "$INSTALL_TARGET/www/html" ]; then |
---|
| 1152 | errorAndLog "${FUNCNAME}(): unable to create Doxygen web files." |
---|
[ead38fb] | 1153 | return 1 |
---|
[5d6bf97] | 1154 | fi |
---|
| 1155 | mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api" |
---|
| 1156 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api |
---|
| 1157 | echoAndLog "${FUNCNAME}(): Doxygen web files created successfully." |
---|
| 1158 | } |
---|
| 1159 | |
---|
| 1160 | |
---|
[a01156a] | 1161 | # Crea la estructura base de la instalación de opengnsys |
---|
[eb9424f] | 1162 | function createDirs() |
---|
[a01156a] | 1163 | { |
---|
| 1164 | if [ $# -ne 1 ]; then |
---|
[dce072b] | 1165 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[a01156a] | 1166 | exit 1 |
---|
| 1167 | fi |
---|
| 1168 | |
---|
[eb9424f] | 1169 | local path_opengnsys_base="$1" |
---|
[a01156a] | 1170 | |
---|
[eb9424f] | 1171 | # Crear estructura de directorios. |
---|
[dce072b] | 1172 | echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base" |
---|
[a01156a] | 1173 | mkdir -p $path_opengnsys_base |
---|
| 1174 | mkdir -p $path_opengnsys_base/bin |
---|
[5c33840] | 1175 | mkdir -p $path_opengnsys_base/client |
---|
[49c6891] | 1176 | mkdir -p $path_opengnsys_base/doc |
---|
[5c33840] | 1177 | mkdir -p $path_opengnsys_base/etc |
---|
[a01156a] | 1178 | mkdir -p $path_opengnsys_base/lib |
---|
[1cc5697] | 1179 | mkdir -p $path_opengnsys_base/log/clients |
---|
[eb9424f] | 1180 | ln -fs $path_opengnsys_base/log /var/log/opengnsys |
---|
[7586ca3] | 1181 | mkdir -p $path_opengnsys_base/sbin |
---|
[a01156a] | 1182 | mkdir -p $path_opengnsys_base/www |
---|
[5c33840] | 1183 | mkdir -p $path_opengnsys_base/images |
---|
[87c7b02] | 1184 | mkdir -p $TFTPCFGDIR |
---|
[63fd1ba] | 1185 | ln -fs $TFTPCFGDIR $path_opengnsys_base/tftpboot |
---|
[eb9424f] | 1186 | mkdir -p $path_opengnsys_base/tftpboot/pxelinux.cfg |
---|
[cfad47b] | 1187 | mkdir -p $path_opengnsys_base/tftpboot/menu.lst |
---|
[a01156a] | 1188 | if [ $? -ne 0 ]; then |
---|
[dce072b] | 1189 | errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" |
---|
[a01156a] | 1190 | return 1 |
---|
| 1191 | fi |
---|
| 1192 | |
---|
[eb9424f] | 1193 | # Crear usuario ficticio. |
---|
| 1194 | if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then |
---|
| 1195 | echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created" |
---|
| 1196 | else |
---|
| 1197 | echoAndLog "${FUNCNAME}(): creating OpenGnSys user" |
---|
| 1198 | useradd $OPENGNSYS_CLIENT_USER 2>/dev/null |
---|
| 1199 | if [ $? -ne 0 ]; then |
---|
| 1200 | errorAndLog "${FUNCNAME}(): error creating OpenGnSys user" |
---|
| 1201 | return 1 |
---|
| 1202 | fi |
---|
| 1203 | fi |
---|
| 1204 | |
---|
| 1205 | # Establecer los permisos básicos. |
---|
| 1206 | echoAndLog "${FUNCNAME}(): setting directory permissions" |
---|
[5eb61a6] | 1207 | chmod -R 775 $path_opengnsys_base/{log/clients,images} |
---|
| 1208 | chown -R :$OPENGNSYS_CLIENT_USER $path_opengnsys_base/{log/clients,images} |
---|
[eb9424f] | 1209 | if [ $? -ne 0 ]; then |
---|
| 1210 | errorAndLog "${FUNCNAME}(): error while setting permissions" |
---|
| 1211 | return 1 |
---|
| 1212 | fi |
---|
| 1213 | |
---|
[7669bca] | 1214 | # Mover el fichero de registro de instalación al directorio de logs. |
---|
[acfb07d] | 1215 | echoAndLog "${FUNCNAME}(): moving installation log file" |
---|
| 1216 | mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE |
---|
[7669bca] | 1217 | chmod 600 $LOG_FILE |
---|
[acfb07d] | 1218 | |
---|
[dce072b] | 1219 | echoAndLog "${FUNCNAME}(): directory paths created" |
---|
[a01156a] | 1220 | return 0 |
---|
| 1221 | } |
---|
| 1222 | |
---|
[463a1d49] | 1223 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
[73a1bd6] | 1224 | function copyServerFiles () |
---|
[e0edc14] | 1225 | { |
---|
[463a1d49] | 1226 | if [ $# -ne 1 ]; then |
---|
[879689f] | 1227 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
[463a1d49] | 1228 | exit 1 |
---|
| 1229 | fi |
---|
| 1230 | |
---|
[7caf5a7c] | 1231 | local path_opengnsys_base="$1" |
---|
[463a1d49] | 1232 | |
---|
[cfad47b] | 1233 | local SOURCES=( server/tftpboot \ |
---|
[7caf5a7c] | 1234 | server/bin \ |
---|
| 1235 | repoman/bin \ |
---|
[42a0e41] | 1236 | admin/Sources/Services/ogAdmServerAux |
---|
| 1237 | admin/Sources/Services/ogAdmRepoAux |
---|
[7caf5a7c] | 1238 | installer/opengnsys_uninstall.sh \ |
---|
| 1239 | installer/opengnsys_update.sh \ |
---|
[79c26a8] | 1240 | installer/install_ticket_wolunicast.sh \ |
---|
[7caf5a7c] | 1241 | doc ) |
---|
[cfad47b] | 1242 | local TARGETS=( tftpboot \ |
---|
[7caf5a7c] | 1243 | bin \ |
---|
| 1244 | bin \ |
---|
[42a0e41] | 1245 | sbin \ |
---|
| 1246 | sbin \ |
---|
[7caf5a7c] | 1247 | lib \ |
---|
| 1248 | lib \ |
---|
[4f38050] | 1249 | lib \ |
---|
[7caf5a7c] | 1250 | doc ) |
---|
[463a1d49] | 1251 | |
---|
| 1252 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
[879689f] | 1253 | errorAndLog "${FUNCNAME}(): inconsistent number of array items" |
---|
[463a1d49] | 1254 | exit 1 |
---|
| 1255 | fi |
---|
| 1256 | |
---|
[879689f] | 1257 | echoAndLog "${FUNCNAME}(): copying files to server directories" |
---|
[f2bb433] | 1258 | |
---|
[8457092] | 1259 | pushd $WORKDIR/opengnsys |
---|
[463a1d49] | 1260 | local i |
---|
| 1261 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
| 1262 | if [ -f "${SOURCES[$i]}" ]; then |
---|
[879689f] | 1263 | echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
[b5aae72] | 1264 | cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
[8457092] | 1265 | elif [ -d "${SOURCES[$i]}" ]; then |
---|
[879689f] | 1266 | echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
[8457092] | 1267 | cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}" |
---|
| 1268 | else |
---|
| 1269 | echoAndLog "Warning: Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" |
---|
[463a1d49] | 1270 | fi |
---|
| 1271 | done |
---|
[7586ca3] | 1272 | popd |
---|
[892606b9] | 1273 | } |
---|
| 1274 | |
---|
[7586ca3] | 1275 | #################################################################### |
---|
[5eb61a6] | 1276 | ### Funciones de compilación de código fuente de servicios |
---|
[7586ca3] | 1277 | #################################################################### |
---|
| 1278 | |
---|
[5eb61a6] | 1279 | # Compilar los servicios de OpenGnSys |
---|
[7586ca3] | 1280 | function servicesCompilation () |
---|
| 1281 | { |
---|
[13a01a7] | 1282 | local hayErrores=0 |
---|
[0795938] | 1283 | |
---|
[49c6891] | 1284 | # Compilar OpenGnSys Server |
---|
| 1285 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server" |
---|
[7b61735] | 1286 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer |
---|
[d168a46] | 1287 | make && mv ogAdmServer $INSTALL_TARGET/sbin |
---|
[13a01a7] | 1288 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1289 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server" |
---|
[13a01a7] | 1290 | hayErrores=1 |
---|
| 1291 | fi |
---|
[7586ca3] | 1292 | popd |
---|
[49c6891] | 1293 | # Compilar OpenGnSys Repository Manager |
---|
| 1294 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager" |
---|
[7b61735] | 1295 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo |
---|
[d168a46] | 1296 | make && mv ogAdmRepo $INSTALL_TARGET/sbin |
---|
[13a01a7] | 1297 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1298 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager" |
---|
[13a01a7] | 1299 | hayErrores=1 |
---|
| 1300 | fi |
---|
[8125e7c] | 1301 | popd |
---|
[4984660] | 1302 | # Compilar OpenGnSys Agent |
---|
| 1303 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Agent" |
---|
[7b61735] | 1304 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent |
---|
[d168a46] | 1305 | make && mv ogAdmAgent $INSTALL_TARGET/sbin |
---|
[4984660] | 1306 | if [ $? -ne 0 ]; then |
---|
| 1307 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent" |
---|
| 1308 | hayErrores=1 |
---|
| 1309 | fi |
---|
| 1310 | popd |
---|
[49c6891] | 1311 | # Compilar OpenGnSys Client |
---|
| 1312 | echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client" |
---|
[7b61735] | 1313 | pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient |
---|
[2338c95f] | 1314 | make && mv ogAdmClient ../../../../client/shared/bin |
---|
[13a01a7] | 1315 | if [ $? -ne 0 ]; then |
---|
[49c6891] | 1316 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client" |
---|
[13a01a7] | 1317 | hayErrores=1 |
---|
| 1318 | fi |
---|
[318efac] | 1319 | popd |
---|
[13a01a7] | 1320 | |
---|
| 1321 | return $hayErrores |
---|
[b6906f7] | 1322 | } |
---|
| 1323 | |
---|
[7b61735] | 1324 | #################################################################### |
---|
| 1325 | ### Funciones de copia de la Interface de administración |
---|
| 1326 | #################################################################### |
---|
| 1327 | |
---|
| 1328 | # Copiar carpeta de Interface |
---|
[c1e00e4] | 1329 | function copyInterfaceAdm () |
---|
[7b61735] | 1330 | { |
---|
| 1331 | local hayErrores=0 |
---|
| 1332 | |
---|
[fbd9bcc] | 1333 | # Crear carpeta y copiar Interface |
---|
[7b61735] | 1334 | echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" |
---|
[fbd9bcc] | 1335 | cp -ar $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client/interfaceAdm |
---|
[7b61735] | 1336 | if [ $? -ne 0 ]; then |
---|
| 1337 | echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder" |
---|
| 1338 | hayErrores=1 |
---|
| 1339 | fi |
---|
[b6f1726] | 1340 | chown $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
[f6c1d2b] | 1341 | chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
[7b61735] | 1342 | |
---|
| 1343 | return $hayErrores |
---|
| 1344 | } |
---|
[b6906f7] | 1345 | |
---|
[892606b9] | 1346 | #################################################################### |
---|
| 1347 | ### Funciones instalacion cliente opengnsys |
---|
| 1348 | #################################################################### |
---|
| 1349 | |
---|
[73a1bd6] | 1350 | function copyClientFiles() |
---|
[7586ca3] | 1351 | { |
---|
[d168a46] | 1352 | local errstatus=0 |
---|
[a555f49] | 1353 | |
---|
[49c6891] | 1354 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files." |
---|
[73a1bd6] | 1355 | cp -a $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client |
---|
[d47d38d] | 1356 | if [ $? -ne 0 ]; then |
---|
[9ef8920] | 1357 | errorAndLog "${FUNCNAME}(): error while copying client estructure" |
---|
[d168a46] | 1358 | errstatus=1 |
---|
[9ef8920] | 1359 | fi |
---|
[d47d38d] | 1360 | find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
[9ef8920] | 1361 | |
---|
[49c6891] | 1362 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files." |
---|
[d47d38d] | 1363 | mkdir -p $INSTALL_TARGET/client/lib/engine/bin |
---|
[73a1bd6] | 1364 | cp -a $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin |
---|
[a555f49] | 1365 | if [ $? -ne 0 ]; then |
---|
| 1366 | errorAndLog "${FUNCNAME}(): error while copying engine files" |
---|
[d168a46] | 1367 | errstatus=1 |
---|
[a555f49] | 1368 | fi |
---|
[9ef8920] | 1369 | |
---|
[d168a46] | 1370 | if [ $errstatus -eq 0 ]; then |
---|
[9ef8920] | 1371 | echoAndLog "${FUNCNAME}(): client copy files success." |
---|
| 1372 | else |
---|
| 1373 | errorAndLog "${FUNCNAME}(): client copy files with errors" |
---|
| 1374 | fi |
---|
| 1375 | |
---|
[d168a46] | 1376 | return $errstatus |
---|
[463a1d49] | 1377 | } |
---|
| 1378 | |
---|
| 1379 | |
---|
[e70925a] | 1380 | # Crear cliente OpenGnSys 1.0.2 y posteriores. |
---|
[5ad5dcc] | 1381 | function clientCreate() |
---|
[813f617] | 1382 | { |
---|
[89179ff] | 1383 | local DOWNLOADURL="http://$OPENGNSYS_SERVER/downloads" |
---|
[de1220c] | 1384 | local FILENAME=ogLive-precise-3.2.0-23-generic-r3257.iso # 1.0.4-rc2 |
---|
| 1385 | #local FILENAME=ogLive-raring-3.8.0-22-generic-r3836.iso # 1.0.5-rc3 |
---|
[0b85cc93] | 1386 | local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME |
---|
| 1387 | local TMPDIR=/tmp/${FILENAME%.iso} |
---|
[d168a46] | 1388 | |
---|
[79c26a8] | 1389 | # Descargar cliente, si es necesario. |
---|
| 1390 | if [ -s $PROGRAMDIR/$FILENAME ]; then |
---|
| 1391 | echoAndLog "${FUNCNAME}(): Moving $PROGRAMDIR/$FILENAME file to $(dirname $TARGETFILE)" |
---|
| 1392 | mv $PROGRAMDIR/$FILENAME $TARGETFILE |
---|
| 1393 | else |
---|
| 1394 | echoAndLog "${FUNCNAME}(): Loading Client" |
---|
| 1395 | wget $DOWNLOADURL/$FILENAME -O $TARGETFILE |
---|
| 1396 | fi |
---|
[0b85cc93] | 1397 | if [ ! -s $TARGETFILE ]; then |
---|
[6ef9f23] | 1398 | errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client" |
---|
[813f617] | 1399 | return 1 |
---|
| 1400 | fi |
---|
[79c26a8] | 1401 | # Montar imagen, copiar cliente ogclient y desmontar. |
---|
[5ad5dcc] | 1402 | echoAndLog "${FUNCNAME}(): Copying Client files" |
---|
[d168a46] | 1403 | mkdir -p $TMPDIR |
---|
[0b85cc93] | 1404 | mount -o loop,ro $TARGETFILE $TMPDIR |
---|
[73a1bd6] | 1405 | cp -av $TMPDIR/ogclient $INSTALL_TARGET/tftpboot |
---|
[5ad5dcc] | 1406 | umount $TMPDIR |
---|
| 1407 | rmdir $TMPDIR |
---|
[6ef01d9] | 1408 | # Asignar la clave cliente para acceso a Samba. |
---|
| 1409 | echoAndLog "${FUNCNAME}(): Set client access key" |
---|
| 1410 | echo -ne "$OPENGNSYS_CLIENT_PASSWD\n$OPENGNSYS_CLIENT_PASSWD\n" | \ |
---|
| 1411 | $INSTALL_TARGET/bin/setsmbpass |
---|
[0b85cc93] | 1412 | |
---|
[813f617] | 1413 | # Establecer los permisos. |
---|
[19fdf38] | 1414 | find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \; |
---|
| 1415 | find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \; |
---|
[813f617] | 1416 | chown -R :$OPENGNSYS_CLIENT_USER $INSTALL_TARGET/tftpboot/ogclient |
---|
[5eb61a6] | 1417 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg} |
---|
[6ef01d9] | 1418 | |
---|
[e8963d0] | 1419 | # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache |
---|
[73a1bd6] | 1420 | cp -av $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot |
---|
| 1421 | cp -av $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot |
---|
[6ef01d9] | 1422 | |
---|
[813f617] | 1423 | echoAndLog "${FUNCNAME}(): Client generation success" |
---|
| 1424 | } |
---|
| 1425 | |
---|
| 1426 | |
---|
[49c6891] | 1427 | # Configuración básica de servicios de OpenGnSys |
---|
[cc7eab7] | 1428 | function openGnsysConfigure() |
---|
| 1429 | { |
---|
[d168a46] | 1430 | local i=0 |
---|
| 1431 | local dev="" |
---|
[7d4ce64] | 1432 | local CONSOLEURL |
---|
[d168a46] | 1433 | |
---|
[9ee62ad] | 1434 | echoAndLog "${FUNCNAME}(): Copying init files." |
---|
[42a0e41] | 1435 | cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys |
---|
| 1436 | cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.default /etc/default/opengnsys |
---|
[9ee62ad] | 1437 | echoAndLog "${FUNCNAME}(): Creating cron files." |
---|
[57cf15b] | 1438 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys |
---|
[9ee62ad] | 1439 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator |
---|
[8fc9552] | 1440 | echo "5 * * * * root [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker |
---|
[dc762088] | 1441 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete |
---|
[d168a46] | 1442 | |
---|
[700299b] | 1443 | echoAndLog "${FUNCNAME}(): Creating logrotate configuration file." |
---|
| 1444 | sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ |
---|
| 1445 | $WORKDIR/opengnsys/server/etc/logrotate.tmpl > /etc/logrotate.d/opengnsys |
---|
| 1446 | |
---|
[d168a46] | 1447 | echoAndLog "${FUNCNAME}(): Creating OpenGnSys config files." |
---|
| 1448 | for dev in ${DEVICE[*]}; do |
---|
| 1449 | if [ -n "${SERVERIP[i]}" ]; then |
---|
| 1450 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
| 1451 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
| 1452 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
| 1453 | -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ |
---|
| 1454 | $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer/ogAdmServer.cfg > $INSTALL_TARGET/etc/ogAdmServer-$dev.cfg |
---|
| 1455 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
| 1456 | $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo/ogAdmRepo.cfg > $INSTALL_TARGET/etc/ogAdmRepo-$dev.cfg |
---|
| 1457 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
| 1458 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
| 1459 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
| 1460 | -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ |
---|
| 1461 | $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent/ogAdmAgent.cfg > $INSTALL_TARGET/etc/ogAdmAgent-$dev.cfg |
---|
[7d4ce64] | 1462 | CONSOLEURL="http://${SERVERIP[i]}/opengnsys" |
---|
[d168a46] | 1463 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
| 1464 | -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
| 1465 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \ |
---|
| 1466 | -e "s/DATABASE/$OPENGNSYS_DATABASE/g" \ |
---|
[b22305e] | 1467 | -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \ |
---|
[d168a46] | 1468 | $INSTALL_TARGET/www/controlacceso.php > $INSTALL_TARGET/www/controlacceso-$dev.php |
---|
| 1469 | sed -e "s/SERVERIP/${SERVERIP[i]}/g" \ |
---|
[d7f8305] | 1470 | -e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \ |
---|
[d168a46] | 1471 | $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient-$dev.cfg |
---|
[7d4ce64] | 1472 | if [ "$dev" == "$DEFAULTDEV" ]; then |
---|
[03cfd6e] | 1473 | OPENGNSYS_CONSOLEURL="${CONSOLEURL/http:/https:}" |
---|
[7d4ce64] | 1474 | fi |
---|
[d168a46] | 1475 | fi |
---|
| 1476 | let i++ |
---|
| 1477 | done |
---|
| 1478 | ln -f $INSTALL_TARGET/etc/ogAdmServer-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmServer.cfg |
---|
| 1479 | ln -f $INSTALL_TARGET/etc/ogAdmRepo-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmRepo.cfg |
---|
| 1480 | ln -f $INSTALL_TARGET/etc/ogAdmAgent-$DEFAULTDEV.cfg $INSTALL_TARGET/etc/ogAdmAgent.cfg |
---|
| 1481 | ln -f $INSTALL_TARGET/client/etc/ogAdmClient-$DEFAULTDEV.cfg $INSTALL_TARGET/client/etc/ogAdmClient.cfg |
---|
| 1482 | ln -f $INSTALL_TARGET/www/controlacceso-$DEFAULTDEV.php $INSTALL_TARGET/www/controlacceso.php |
---|
| 1483 | chown root:root $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg |
---|
| 1484 | chmod 600 $INSTALL_TARGET/etc/{ogAdmServer,ogAdmAgent}*.cfg |
---|
| 1485 | chown $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/controlacceso*.php |
---|
| 1486 | chmod 600 $INSTALL_TARGET/www/controlacceso*.php |
---|
[9ee62ad] | 1487 | echoAndLog "${FUNCNAME}(): Starting OpenGnSys services." |
---|
[53fba30] | 1488 | service="opengnsys" |
---|
| 1489 | $ENABLESERVICE; $STARTSERVICE |
---|
[cc7eab7] | 1490 | } |
---|
| 1491 | |
---|
[b6906f7] | 1492 | |
---|
[a01156a] | 1493 | ##################################################################### |
---|
[180a07dd] | 1494 | ####### Función de resumen informativo de la instalación |
---|
| 1495 | ##################################################################### |
---|
| 1496 | |
---|
[813f617] | 1497 | function installationSummary() |
---|
| 1498 | { |
---|
[eb9424f] | 1499 | # Crear fichero de versión y revisión, si no existe. |
---|
| 1500 | local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt" |
---|
[0b85cc93] | 1501 | local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}') |
---|
[eb9424f] | 1502 | [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE |
---|
| 1503 | perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE |
---|
| 1504 | |
---|
| 1505 | # Mostrar información. |
---|
[180a07dd] | 1506 | echo |
---|
[49c6891] | 1507 | echoAndLog "OpenGnSys Installation Summary" |
---|
[180a07dd] | 1508 | echo "==============================" |
---|
[eb9424f] | 1509 | echoAndLog "Project version: $(cat $VERSIONFILE 2>/dev/null)" |
---|
[49c6891] | 1510 | echoAndLog "Installation directory: $INSTALL_TARGET" |
---|
[acfb07d] | 1511 | echoAndLog "Installation log file: $LOG_FILE" |
---|
[49c6891] | 1512 | echoAndLog "Repository directory: $INSTALL_TARGET/images" |
---|
[d168a46] | 1513 | echoAndLog "DHCP configuration directory: $DHCPCFGDIR" |
---|
[87c7b02] | 1514 | echoAndLog "TFTP configuration directory: $TFTPCFGDIR" |
---|
| 1515 | echoAndLog "Samba configuration directory: $SAMBACFGDIR" |
---|
[49c6891] | 1516 | echoAndLog "Web Console URL: $OPENGNSYS_CONSOLEURL" |
---|
[35b0ef1] | 1517 | echoAndLog "Web Console access data: specified in installer script" |
---|
[180a07dd] | 1518 | echo |
---|
| 1519 | echoAndLog "Post-Installation Instructions:" |
---|
| 1520 | echo "===============================" |
---|
[0ad88eb] | 1521 | echoAndLog "Change IPTables and SELinux system configuration, if needed." |
---|
[180a07dd] | 1522 | echoAndLog "Review or edit all configuration files." |
---|
[c5ce04c] | 1523 | echoAndLog "Insert DHCP configuration data and restart service." |
---|
[af5efd6] | 1524 | echoAndLog "Optional: Log-in as Web Console admin user." |
---|
| 1525 | echoAndLog " - Review default Organization data and assign access to users." |
---|
[180a07dd] | 1526 | echoAndLog "Log-in as Web Console organization user." |
---|
[e4b1572] | 1527 | echoAndLog " - Insert OpenGnSys data (labs, computers, menus, etc)." |
---|
[180a07dd] | 1528 | echo |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | |
---|
| 1532 | |
---|
| 1533 | ##################################################################### |
---|
[49c6891] | 1534 | ####### Proceso de instalación de OpenGnSys |
---|
[a01156a] | 1535 | ##################################################################### |
---|
| 1536 | |
---|
[49c6891] | 1537 | echoAndLog "OpenGnSys installation begins at $(date)" |
---|
[6090a2d] | 1538 | pushd $WORKDIR |
---|
[cc7eab7] | 1539 | |
---|
[af5efd6] | 1540 | # Detectar datos iniciales de auto-configuración del instalador. |
---|
[d168a46] | 1541 | autoConfigure |
---|
| 1542 | |
---|
| 1543 | # Detectar parámetros de red y comprobar si hay conexión. |
---|
| 1544 | getNetworkSettings |
---|
| 1545 | if [ $? -ne 0 ]; then |
---|
| 1546 | errorAndLog "Error reading default network settings." |
---|
| 1547 | exit 1 |
---|
| 1548 | fi |
---|
[07c3a59] | 1549 | checkNetworkConnection |
---|
| 1550 | if [ $? -ne 0 ]; then |
---|
| 1551 | errorAndLog "Error connecting to server. Causes:" |
---|
| 1552 | errorAndLog " - Network is unreachable, review devices parameters." |
---|
| 1553 | errorAndLog " - You are inside a private network, configure the proxy service." |
---|
| 1554 | errorAndLog " - Server is temporally down, try agian later." |
---|
| 1555 | exit 1 |
---|
| 1556 | fi |
---|
[7586ca3] | 1557 | |
---|
[e0edc14] | 1558 | # Detener servicios de OpenGnSys, si están activos previamente. |
---|
| 1559 | [ -f /etc/init.d/opengnsys ] && /etc/init.d/opengnsys stop |
---|
| 1560 | |
---|
[318efac] | 1561 | # Actualizar repositorios |
---|
[83518d5] | 1562 | updatePackageList |
---|
[318efac] | 1563 | |
---|
[b6906f7] | 1564 | # Instalación de dependencias (paquetes de sistema operativo). |
---|
[a01156a] | 1565 | declare -a notinstalled |
---|
| 1566 | checkDependencies DEPENDENCIES notinstalled |
---|
| 1567 | if [ $? -ne 0 ]; then |
---|
| 1568 | installDependencies notinstalled |
---|
| 1569 | if [ $? -ne 0 ]; then |
---|
| 1570 | echoAndLog "Error while installing some dependeces, please verify your server installation before continue" |
---|
| 1571 | exit 1 |
---|
| 1572 | fi |
---|
| 1573 | fi |
---|
[109e8b2] | 1574 | if [ -n "$INSTALLEXTRADEPS" ]; then |
---|
| 1575 | echoAndLog "Installing extra dependencies" |
---|
| 1576 | for (( i=0; i<${#INSTALLEXTRADEPS[*]}; i++ )); do |
---|
| 1577 | eval ${INSTALLEXTRADEPS[i]} |
---|
| 1578 | done |
---|
| 1579 | fi |
---|
[a01156a] | 1580 | |
---|
[ff6c349] | 1581 | # Detectar datos de auto-configuración después de instalar paquetes. |
---|
| 1582 | autoConfigurePost |
---|
| 1583 | |
---|
[49c6891] | 1584 | # Arbol de directorios de OpenGnSys. |
---|
[eb9424f] | 1585 | createDirs ${INSTALL_TARGET} |
---|
[a01156a] | 1586 | if [ $? -ne 0 ]; then |
---|
| 1587 | errorAndLog "Error while creating directory paths!" |
---|
| 1588 | exit 1 |
---|
| 1589 | fi |
---|
[b6906f7] | 1590 | |
---|
[1e7eaab] | 1591 | # Si es necesario, descarga el repositorio de código en directorio temporal |
---|
[49c6891] | 1592 | if [ $USESVN -eq 1 ]; then |
---|
[1e7eaab] | 1593 | svnExportCode $SVN_URL |
---|
| 1594 | if [ $? -ne 0 ]; then |
---|
| 1595 | errorAndLog "Error while getting code from svn" |
---|
| 1596 | exit 1 |
---|
| 1597 | fi |
---|
| 1598 | else |
---|
| 1599 | ln -fs "$(dirname $PROGRAMDIR)" opengnsys |
---|
[a01156a] | 1600 | fi |
---|
| 1601 | |
---|
[49c6891] | 1602 | # Compilar código fuente de los servicios de OpenGnSys. |
---|
[b6906f7] | 1603 | servicesCompilation |
---|
[13a01a7] | 1604 | if [ $? -ne 0 ]; then |
---|
| 1605 | errorAndLog "Error while compiling OpenGnsys services" |
---|
| 1606 | exit 1 |
---|
| 1607 | fi |
---|
[b6906f7] | 1608 | |
---|
[7b61735] | 1609 | # Copiar carpeta Interface entre administración y motor de clonación. |
---|
[c1e00e4] | 1610 | copyInterfaceAdm |
---|
[7b61735] | 1611 | if [ $? -ne 0 ]; then |
---|
[c1e00e4] | 1612 | errorAndLog "Error while copying Administration Interface" |
---|
[7b61735] | 1613 | exit 1 |
---|
| 1614 | fi |
---|
| 1615 | |
---|
[e70925a] | 1616 | # Configuración de TFTP. |
---|
[318efac] | 1617 | tftpConfigure |
---|
[b6906f7] | 1618 | |
---|
[e70925a] | 1619 | # Configuración de Samba. |
---|
[8fc9552] | 1620 | smbConfigure |
---|
| 1621 | if [ $? -ne 0 ]; then |
---|
[c1e00e4] | 1622 | errorAndLog "Error while configuring Samba server!" |
---|
[8fc9552] | 1623 | exit 1 |
---|
| 1624 | fi |
---|
| 1625 | |
---|
[e70925a] | 1626 | # Configuración de Rsync. |
---|
| 1627 | rsyncConfigure |
---|
| 1628 | |
---|
| 1629 | # Configuración ejemplo DHCP. |
---|
[b6906f7] | 1630 | dhcpConfigure |
---|
[a555f49] | 1631 | if [ $? -ne 0 ]; then |
---|
| 1632 | errorAndLog "Error while copying your dhcp server files!" |
---|
| 1633 | exit 1 |
---|
| 1634 | fi |
---|
[b6906f7] | 1635 | |
---|
[49c6891] | 1636 | # Copiar ficheros de servicios OpenGnSys Server. |
---|
[73a1bd6] | 1637 | copyServerFiles ${INSTALL_TARGET} |
---|
[463a1d49] | 1638 | if [ $? -ne 0 ]; then |
---|
| 1639 | errorAndLog "Error while copying the server files!" |
---|
| 1640 | exit 1 |
---|
| 1641 | fi |
---|
| 1642 | |
---|
[49c6891] | 1643 | # Instalar Base de datos de OpenGnSys Admin. |
---|
[b6906f7] | 1644 | isInArray notinstalled "mysql-server" |
---|
| 1645 | if [ $? -eq 0 ]; then |
---|
[53fba30] | 1646 | service=$MYSQLSERV |
---|
| 1647 | $ENABLESERVICE; $STARTSERVICE |
---|
[09bf701] | 1648 | mysqlSetRootPassword "${MYSQL_ROOT_PASSWORD}" |
---|
[b6906f7] | 1649 | else |
---|
| 1650 | mysqlGetRootPassword |
---|
| 1651 | fi |
---|
[463a1d49] | 1652 | |
---|
[09bf701] | 1653 | mysqlTestConnection "${MYSQL_ROOT_PASSWORD}" |
---|
[a01156a] | 1654 | if [ $? -ne 0 ]; then |
---|
| 1655 | errorAndLog "Error while connection to mysql" |
---|
| 1656 | exit 1 |
---|
| 1657 | fi |
---|
[09bf701] | 1658 | mysqlDbExists ${OPENGNSYS_DATABASE} |
---|
[a01156a] | 1659 | if [ $? -ne 0 ]; then |
---|
[cc7eab7] | 1660 | echoAndLog "Creating Web Console database" |
---|
[09bf701] | 1661 | mysqlCreateDb ${OPENGNSYS_DATABASE} |
---|
[a01156a] | 1662 | if [ $? -ne 0 ]; then |
---|
[cc7eab7] | 1663 | errorAndLog "Error while creating Web Console database" |
---|
[a01156a] | 1664 | exit 1 |
---|
| 1665 | fi |
---|
| 1666 | else |
---|
[cc7eab7] | 1667 | echoAndLog "Web Console database exists, ommiting creation" |
---|
[a01156a] | 1668 | fi |
---|
| 1669 | |
---|
[09bf701] | 1670 | mysqlCheckUserExists ${OPENGNSYS_DB_USER} |
---|
[a01156a] | 1671 | if [ $? -ne 0 ]; then |
---|
| 1672 | echoAndLog "Creating user in database" |
---|
[09bf701] | 1673 | mysqlCreateAdminUserToDb ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}" |
---|
[a01156a] | 1674 | if [ $? -ne 0 ]; then |
---|
[cc7eab7] | 1675 | errorAndLog "Error while creating database user" |
---|
[a01156a] | 1676 | exit 1 |
---|
| 1677 | fi |
---|
| 1678 | |
---|
| 1679 | fi |
---|
| 1680 | |
---|
[09bf701] | 1681 | mysqlCheckDbIsEmpty ${OPENGNSYS_DATABASE} |
---|
[a01156a] | 1682 | if [ $? -eq 0 ]; then |
---|
| 1683 | echoAndLog "Creating tables..." |
---|
[892606b9] | 1684 | if [ -f $WORKDIR/$OPENGNSYS_DB_CREATION_FILE ]; then |
---|
[09bf701] | 1685 | mysqlImportSqlFileToDb ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_CREATION_FILE |
---|
[a01156a] | 1686 | else |
---|
[892606b9] | 1687 | errorAndLog "Unable to locate $WORKDIR/$OPENGNSYS_DB_CREATION_FILE!!" |
---|
[a01156a] | 1688 | exit 1 |
---|
| 1689 | fi |
---|
[bc7dfe7] | 1690 | else |
---|
| 1691 | # Si existe fichero ogBDAdmin-VersLocal-VersRepo.sql; aplicar cambios. |
---|
| 1692 | INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt) |
---|
| 1693 | REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt) |
---|
[295b4ab] | 1694 | OPENGNSYS_DB_UPDATE_FILE="opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql" |
---|
| 1695 | if [ -f $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE ]; then |
---|
[bc7dfe7] | 1696 | echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION" |
---|
[09bf701] | 1697 | mysqlImportSqlFileToDb ${OPENGNSYS_DATABASE} $WORKDIR/$OPENGNSYS_DB_UPDATE_FILE |
---|
[bc7dfe7] | 1698 | else |
---|
| 1699 | echoAndLog "Database unchanged." |
---|
| 1700 | fi |
---|
[a01156a] | 1701 | fi |
---|
[09bf701] | 1702 | # Eliminar fichero temporal con credenciales de acceso a MySQL. |
---|
| 1703 | rm -f $TMPMYCNF |
---|
[a01156a] | 1704 | |
---|
| 1705 | # copiando paqinas web |
---|
[7586ca3] | 1706 | installWebFiles |
---|
[5d6bf97] | 1707 | # Generar páqinas web de documentación de la API |
---|
| 1708 | makeDoxygenFiles |
---|
[a01156a] | 1709 | |
---|
| 1710 | # creando configuracion de apache2 |
---|
[5fcf180] | 1711 | installWebConsoleApacheConf $INSTALL_TARGET $APACHECFGDIR |
---|
[a01156a] | 1712 | if [ $? -ne 0 ]; then |
---|
[87c7b02] | 1713 | errorAndLog "Error configuring Apache for OpenGnSys Admin" |
---|
[a01156a] | 1714 | exit 1 |
---|
| 1715 | fi |
---|
| 1716 | |
---|
| 1717 | popd |
---|
[892606b9] | 1718 | |
---|
[9ef8920] | 1719 | # Crear la estructura de los accesos al servidor desde el cliente (shared) |
---|
[73a1bd6] | 1720 | copyClientFiles |
---|
[9ef8920] | 1721 | if [ $? -ne 0 ]; then |
---|
| 1722 | errorAndLog "Error creating client structure" |
---|
| 1723 | fi |
---|
| 1724 | |
---|
[d168a46] | 1725 | # Crear la estructura del cliente de OpenGnSys |
---|
[5ad5dcc] | 1726 | clientCreate |
---|
[a555f49] | 1727 | if [ $? -ne 0 ]; then |
---|
[813f617] | 1728 | errorAndLog "Error creating client" |
---|
[a555f49] | 1729 | exit 1 |
---|
| 1730 | fi |
---|
[892606b9] | 1731 | |
---|
[65245d1] | 1732 | # Configuración de servicios de OpenGnSys |
---|
| 1733 | openGnsysConfigure |
---|
| 1734 | |
---|
[180a07dd] | 1735 | # Mostrar sumario de la instalación e instrucciones de post-instalación. |
---|
| 1736 | installationSummary |
---|
| 1737 | |
---|
[077dd7c5] | 1738 | #rm -rf $WORKDIR |
---|
[49c6891] | 1739 | echoAndLog "OpenGnSys installation finished at $(date)" |
---|
[05d2e03] | 1740 | exit 0 |
---|
[2308fc7] | 1741 | |
---|