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