1 | #!/bin/bash |
---|
2 | #/** |
---|
3 | #@file opengnsys_update.sh |
---|
4 | #@brief Script actualización de OpenGnSys |
---|
5 | #@warning No se actualiza BD, ni ficheros de configuración. |
---|
6 | #@version 0.9 - basado en opengnsys_installer.sh |
---|
7 | #@author Ramón Gómez - ETSII Univ. Sevilla |
---|
8 | #@date 2010/01/27 |
---|
9 | #@version 1.0 - adaptación a OpenGnSys 1.0 |
---|
10 | #@author Ramón Gómez - ETSII Univ. Sevilla |
---|
11 | #@date 2011/03/02 |
---|
12 | #@version 1.0.1 - control de auto actualización del script |
---|
13 | #@author Ramón Gómez - ETSII Univ. Sevilla |
---|
14 | #@date 2011/05/17 |
---|
15 | #*/ |
---|
16 | |
---|
17 | |
---|
18 | #### AVISO: Editar configuración de acceso por defecto a la Base de Datos. |
---|
19 | OPENGNSYS_DATABASE="ogAdmBD" # Nombre de la base datos |
---|
20 | OPENGNSYS_DBUSER="usuog" # Usuario de acceso |
---|
21 | OPENGNSYS_DBPASSWORD="passusuog" # Clave del usuario |
---|
22 | |
---|
23 | #### AVISO: NO Editar variables de acceso desde el cliente |
---|
24 | OPENGNSYS_CLIENTUSER="opengnsys" # Usuario Samba |
---|
25 | |
---|
26 | |
---|
27 | # Sólo ejecutable por usuario root |
---|
28 | if [ "$(whoami)" != 'root' ]; then |
---|
29 | echo "ERROR: this program must run under root privileges!!" |
---|
30 | exit 1 |
---|
31 | fi |
---|
32 | # Error si OpenGnSys no está instalado (no existe el directorio del proyecto) |
---|
33 | INSTALL_TARGET=/opt/opengnsys |
---|
34 | if [ ! -d $INSTALL_TARGET ]; then |
---|
35 | echo "ERROR: OpenGnSys is not installed, cannot update!!" |
---|
36 | exit 1 |
---|
37 | fi |
---|
38 | |
---|
39 | # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). |
---|
40 | PROGRAMDIR=$(readlink -e $(dirname "$0")) |
---|
41 | PROGRAMNAME=$(basename "$0") |
---|
42 | DEPS="build-essential g++-multilib rsync ctorrent samba unzip netpipes debootstrap schroot squashfs-tools" |
---|
43 | OPENGNSYS_SERVER="www.opengnsys.es" |
---|
44 | if [ -d "$PROGRAMDIR/../installer" ]; then |
---|
45 | USESVN=0 |
---|
46 | else |
---|
47 | USESVN=1 |
---|
48 | DEPS="$DEPS subversion" |
---|
49 | fi |
---|
50 | SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/" |
---|
51 | |
---|
52 | WORKDIR=/tmp/opengnsys_update |
---|
53 | mkdir -p $WORKDIR |
---|
54 | |
---|
55 | LOG_FILE=/tmp/opengnsys_update.log |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | ##################################################################### |
---|
60 | ####### Algunas funciones útiles de propósito general: |
---|
61 | ##################################################################### |
---|
62 | |
---|
63 | # Comprobar auto-actualización. |
---|
64 | function checkAutoUpdate() |
---|
65 | { |
---|
66 | local update=0 |
---|
67 | |
---|
68 | # Actaulizar el script si ha cambiado o no existe el original. |
---|
69 | if [ $USESVN -eq 1 ]; then |
---|
70 | svn export $SVN_URL/installer/$PROGRAMNAME |
---|
71 | if ! diff --brief $PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME &>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then |
---|
72 | mv $PROGRAMNAME $INSTALL_TARGET/lib |
---|
73 | update=1 |
---|
74 | else |
---|
75 | rm -f $PROGRAMNAME |
---|
76 | fi |
---|
77 | else |
---|
78 | if ! diff --brief $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME &>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then |
---|
79 | cp -a $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib |
---|
80 | update=1 |
---|
81 | fi |
---|
82 | fi |
---|
83 | |
---|
84 | return $update |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | function getDateTime() |
---|
89 | { |
---|
90 | date "+%Y%m%d-%H%M%S" |
---|
91 | } |
---|
92 | |
---|
93 | # Escribe a fichero y muestra por pantalla |
---|
94 | function echoAndLog() |
---|
95 | { |
---|
96 | echo $1 |
---|
97 | DATETIME=`getDateTime` |
---|
98 | echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
99 | } |
---|
100 | |
---|
101 | function errorAndLog() |
---|
102 | { |
---|
103 | echo "ERROR: $1" |
---|
104 | DATETIME=`getDateTime` |
---|
105 | echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | ##################################################################### |
---|
110 | ####### Funciones de copia de seguridad y restauración de ficheros |
---|
111 | ##################################################################### |
---|
112 | |
---|
113 | # Hace un backup del fichero pasado por parámetro |
---|
114 | # deja un -last y uno para el día |
---|
115 | function backupFile() |
---|
116 | { |
---|
117 | if [ $# -ne 1 ]; then |
---|
118 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
119 | exit 1 |
---|
120 | fi |
---|
121 | |
---|
122 | local fichero=$1 |
---|
123 | local fecha=`date +%Y%m%d` |
---|
124 | |
---|
125 | if [ ! -f $fichero ]; then |
---|
126 | errorAndLog "${FUNCNAME}(): file $fichero doesn't exists" |
---|
127 | return 1 |
---|
128 | fi |
---|
129 | |
---|
130 | echoAndLog "${FUNCNAME}(): Making $fichero back-up" |
---|
131 | |
---|
132 | # realiza una copia de la última configuración como last |
---|
133 | cp -a $fichero "${fichero}-LAST" |
---|
134 | |
---|
135 | # si para el día no hay backup lo hace, sino no |
---|
136 | if [ ! -f "${fichero}-${fecha}" ]; then |
---|
137 | cp -a $fichero "${fichero}-${fecha}" |
---|
138 | fi |
---|
139 | } |
---|
140 | |
---|
141 | # Restaura un fichero desde su copia de seguridad |
---|
142 | function restoreFile() |
---|
143 | { |
---|
144 | if [ $# -ne 1 ]; then |
---|
145 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
146 | exit 1 |
---|
147 | fi |
---|
148 | |
---|
149 | local fichero=$1 |
---|
150 | |
---|
151 | echoAndLog "${FUNCNAME}(): restoring file $fichero" |
---|
152 | if [ -f "${fichero}-LAST" ]; then |
---|
153 | cp -a "$fichero-LAST" "$fichero" |
---|
154 | fi |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | ##################################################################### |
---|
159 | ####### Funciones de acceso a base de datos |
---|
160 | ##################################################################### |
---|
161 | |
---|
162 | # Actualizar la base datos |
---|
163 | function importSqlFile() |
---|
164 | { |
---|
165 | if [ $# -ne 4 ]; then |
---|
166 | errorAndLog "${FNCNAME}(): invalid number of parameters" |
---|
167 | exit 1 |
---|
168 | fi |
---|
169 | |
---|
170 | local dbuser="$1" |
---|
171 | local dbpassword="$2" |
---|
172 | local database="$3" |
---|
173 | local sqlfile="$4" |
---|
174 | local tmpfile=$(mktemp) |
---|
175 | local status |
---|
176 | |
---|
177 | if [ ! -r $sqlfile ]; then |
---|
178 | errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!" |
---|
179 | return 1 |
---|
180 | fi |
---|
181 | |
---|
182 | echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..." |
---|
183 | chmod 600 $tmpfile |
---|
184 | sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
185 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" $sqlfile > $tmpfile |
---|
186 | mysql -u$dbuser -p"$dbpassword" --default-character-set=utf8 "$database" < $tmpfile |
---|
187 | status=$? |
---|
188 | rm -f $tmpfile |
---|
189 | if [ $status -ne 0 ]; then |
---|
190 | errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database" |
---|
191 | return 1 |
---|
192 | fi |
---|
193 | echoAndLog "${FUNCNAME}(): file imported to database $database" |
---|
194 | return 0 |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | ##################################################################### |
---|
199 | ####### Funciones de instalación de paquetes |
---|
200 | ##################################################################### |
---|
201 | |
---|
202 | # Instalar las deependencias necesarias para el actualizador. |
---|
203 | function installDependencies() |
---|
204 | { |
---|
205 | if [ $# = 0 ]; then |
---|
206 | echoAndLog "${FUNCNAME}(): no deps needed." |
---|
207 | else |
---|
208 | while [ $# -gt 0 ]; do |
---|
209 | dpkg -s $1 2>/dev/null | grep -q "Status: install ok" |
---|
210 | if [ $? -ne 0 ]; then |
---|
211 | INSTALLDEPS="$INSTALLDEPS $1" |
---|
212 | fi |
---|
213 | shift |
---|
214 | done |
---|
215 | if [ -n "$INSTALLDEPS" ]; then |
---|
216 | apt-get update && apt-get -y install --force-yes $INSTALLDEPS |
---|
217 | if [ $? -ne 0 ]; then |
---|
218 | errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS." |
---|
219 | return 1 |
---|
220 | fi |
---|
221 | fi |
---|
222 | fi |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | ##################################################################### |
---|
227 | ####### Funciones para el manejo de Subversion |
---|
228 | ##################################################################### |
---|
229 | |
---|
230 | function svnExportCode() |
---|
231 | { |
---|
232 | if [ $# -ne 1 ]; then |
---|
233 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
234 | exit 1 |
---|
235 | fi |
---|
236 | |
---|
237 | local url="$1" |
---|
238 | |
---|
239 | echoAndLog "${FUNCNAME}(): downloading subversion code..." |
---|
240 | |
---|
241 | svn checkout "${url}" opengnsys |
---|
242 | if [ $? -ne 0 ]; then |
---|
243 | errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password" |
---|
244 | return 1 |
---|
245 | fi |
---|
246 | echoAndLog "${FUNCNAME}(): subversion code downloaded" |
---|
247 | return 0 |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | ############################################################ |
---|
252 | ### Detectar red |
---|
253 | ############################################################ |
---|
254 | |
---|
255 | # Comprobar si existe conexión. |
---|
256 | function checkNetworkConnection() |
---|
257 | { |
---|
258 | OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"} |
---|
259 | wget --spider -q $OPENGNSYS_SERVER |
---|
260 | } |
---|
261 | |
---|
262 | |
---|
263 | ##################################################################### |
---|
264 | ####### Funciones específicas de la instalación de Opengnsys |
---|
265 | ##################################################################### |
---|
266 | |
---|
267 | # Copiar ficheros de arranque de los servicios del sistema de OpenGnSys |
---|
268 | function updateServicesStart() |
---|
269 | { |
---|
270 | local initfile=/etc/init.d/opengnsyso |
---|
271 | |
---|
272 | if ! diff --quiet $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init $initfile 2>/dev/null; then |
---|
273 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys init file in $initfile.new" |
---|
274 | cp -a $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init $initfile.new |
---|
275 | if [ $? != 0 ]; then |
---|
276 | errorAndLog "${FUNCNAME}(): Error copying $initfile.new" |
---|
277 | exit 1 |
---|
278 | fi |
---|
279 | echoAndLog "${FUNCNAME}(): Check the new init files." |
---|
280 | fi |
---|
281 | } |
---|
282 | |
---|
283 | # Actualizar cliente OpenGnSys |
---|
284 | function updateClientFiles() |
---|
285 | { |
---|
286 | echoAndLog "${FUNCNAME}(): Updating OpenGnSys Client files." |
---|
287 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client |
---|
288 | if [ $? -ne 0 ]; then |
---|
289 | errorAndLog "${FUNCNAME}(): error while updating client structure" |
---|
290 | exit 1 |
---|
291 | fi |
---|
292 | find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
293 | |
---|
294 | echoAndLog "${FUNCNAME}(): Updating OpenGnSys Cloning Engine files." |
---|
295 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin |
---|
296 | if [ $? -ne 0 ]; then |
---|
297 | errorAndLog "${FUNCNAME}(): error while updating engine files" |
---|
298 | exit 1 |
---|
299 | fi |
---|
300 | |
---|
301 | echoAndLog "${FUNCNAME}(): client files update success." |
---|
302 | } |
---|
303 | |
---|
304 | # Configurar HTTPS y exportar usuario y grupo del servicio Apache. |
---|
305 | function apacheConfiguration () |
---|
306 | { |
---|
307 | local APACHECONF=/etc/apache2 |
---|
308 | |
---|
309 | # Activar HTTPS, si es necesario. |
---|
310 | if [ -e $APACHECONF/sites-available/opengnsys.conf ]; then |
---|
311 | echoAndLog "${FUNCNAME}(): Configuring HTTPS access..." |
---|
312 | mv $APACHECONF/sites-available/opengnsys.conf $APACHECONF/sites-available/opengnsys |
---|
313 | a2ensite default-ssl |
---|
314 | a2enmod ssl |
---|
315 | a2dissite opengnsys.conf |
---|
316 | a2ensite opengnsys |
---|
317 | /etc/init.d/apache2 restart |
---|
318 | fi |
---|
319 | |
---|
320 | # Variables de ejecución de Apache. |
---|
321 | # - APACHE_RUN_USER |
---|
322 | # - APACHE_RUN_GROUP |
---|
323 | if [ -f $APACHECONF/envvars ]; then |
---|
324 | source $APACHECONF/envvars |
---|
325 | fi |
---|
326 | APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"} |
---|
327 | APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"} |
---|
328 | } |
---|
329 | |
---|
330 | # Copiar ficheros del OpenGnSys Web Console. |
---|
331 | function updateWebFiles() |
---|
332 | { |
---|
333 | local ERRCODE |
---|
334 | echoAndLog "${FUNCNAME}(): Updating web files..." |
---|
335 | backupFile $INSTALL_TARGET/www/controlacceso.php |
---|
336 | mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole |
---|
337 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET |
---|
338 | ERRCODE=$? |
---|
339 | mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www |
---|
340 | unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax |
---|
341 | if [ $ERRCODE != 0 ]; then |
---|
342 | errorAndLog "${FUNCNAME}(): Error updating web files." |
---|
343 | exit 1 |
---|
344 | fi |
---|
345 | restoreFile $INSTALL_TARGET/www/controlacceso.php |
---|
346 | # Cambiar permisos para ficheros especiales. |
---|
347 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/includes $INSTALL_TARGET/www/images/iconos |
---|
348 | echoAndLog "${FUNCNAME}(): Web files updated successfully." |
---|
349 | } |
---|
350 | |
---|
351 | # Copiar carpeta de Interface |
---|
352 | function updateInterfaceAdm() |
---|
353 | { |
---|
354 | local errcode=0 |
---|
355 | |
---|
356 | # Crear carpeta y copiar Interface |
---|
357 | echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" |
---|
358 | mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface |
---|
359 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client |
---|
360 | errcoce=$? |
---|
361 | mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm |
---|
362 | if [ $errcode -ne 0 ]; then |
---|
363 | echoAndLog "${FUNCNAME}(): error while updating admin interface" |
---|
364 | exit 1 |
---|
365 | fi |
---|
366 | chmod -R +x $INSTALL_TARGET/client/interfaceAdm |
---|
367 | chown $OPENGNSYS_CLIENTUSER:$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
368 | chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
369 | echoAndLog "${FUNCNAME}(): Admin interface updated successfully." |
---|
370 | } |
---|
371 | |
---|
372 | # Crear documentación Doxygen para la consola web. |
---|
373 | function makeDoxygenFiles() |
---|
374 | { |
---|
375 | echoAndLog "${FUNCNAME}(): Making Doxygen web files..." |
---|
376 | $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \ |
---|
377 | $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www |
---|
378 | if [ ! -d "$INSTALL_TARGET/www/html" ]; then |
---|
379 | errorAndLog "${FUNCNAME}(): unable to create Doxygen web files." |
---|
380 | return 1 |
---|
381 | fi |
---|
382 | rm -fr "$INSTALL_TARGET/www/api" |
---|
383 | mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api" |
---|
384 | rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf} |
---|
385 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api |
---|
386 | echoAndLog "${FUNCNAME}(): Doxygen web files created successfully." |
---|
387 | } |
---|
388 | |
---|
389 | |
---|
390 | # Crea la estructura base de la instalación de opengnsys |
---|
391 | function createDirs() |
---|
392 | { |
---|
393 | # Crear estructura de directorios. |
---|
394 | echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}" |
---|
395 | mkdir -p ${INSTALL_TARGET}/{bin,doc,etc,lib,sbin,www} |
---|
396 | mkdir -p ${INSTALL_TARGET}/{client,images} |
---|
397 | mkdir -p ${INSTALL_TARGET}/log/clients |
---|
398 | ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys |
---|
399 | ln -fs /var/lib/tftpboot ${INSTALL_TARGET} |
---|
400 | mkdir -p ${INSTALL_TARGET}/tftpboot/{pxelinux.cfg,menu.lst} |
---|
401 | if [ $? -ne 0 ]; then |
---|
402 | errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" |
---|
403 | return 1 |
---|
404 | fi |
---|
405 | |
---|
406 | # Crear usuario ficticio. |
---|
407 | if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then |
---|
408 | echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created" |
---|
409 | else |
---|
410 | echoAndLog "${FUNCNAME}(): creating OpenGnSys user" |
---|
411 | useradd $OPENGNSYS_CLIENTUSER 2>/dev/null |
---|
412 | if [ $? -ne 0 ]; then |
---|
413 | errorAndLog "${FUNCNAME}(): error creating OpenGnSys user" |
---|
414 | return 1 |
---|
415 | fi |
---|
416 | fi |
---|
417 | |
---|
418 | # Establecer los permisos básicos. |
---|
419 | echoAndLog "${FUNCNAME}(): setting directory permissions" |
---|
420 | chmod -R 775 $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg,tftpboot/menu.lst} |
---|
421 | chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg,tftpboot/menu.lst} |
---|
422 | if [ $? -ne 0 ]; then |
---|
423 | errorAndLog "${FUNCNAME}(): error while setting permissions" |
---|
424 | return 1 |
---|
425 | fi |
---|
426 | |
---|
427 | echoAndLog "${FUNCNAME}(): directory paths created" |
---|
428 | return 0 |
---|
429 | } |
---|
430 | |
---|
431 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
432 | function updateServerFiles() |
---|
433 | { |
---|
434 | # No copiar ficheros del antiguo cliente Initrd |
---|
435 | local SOURCES=( repoman/bin \ |
---|
436 | server/bin \ |
---|
437 | server/tftpboot \ |
---|
438 | installer/opengnsys_uninstall.sh \ |
---|
439 | doc ) |
---|
440 | local TARGETS=( bin \ |
---|
441 | bin \ |
---|
442 | tftpboot \ |
---|
443 | lib/opengnsys_uninstall.sh \ |
---|
444 | doc ) |
---|
445 | |
---|
446 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
447 | errorAndLog "${FUNCNAME}(): inconsistent number of array items" |
---|
448 | exit 1 |
---|
449 | fi |
---|
450 | |
---|
451 | echoAndLog "${FUNCNAME}(): updating files in server directories" |
---|
452 | pushd $WORKDIR/opengnsys >/dev/null |
---|
453 | local i |
---|
454 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
455 | if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then |
---|
456 | rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}")) |
---|
457 | else |
---|
458 | rsync --exclude .svn -irplt "${SOURCES[i]}" $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}") |
---|
459 | fi |
---|
460 | done |
---|
461 | popd >/dev/null |
---|
462 | echoAndLog "${FUNCNAME}(): updating DHCP files" |
---|
463 | if grep -q 'pxelinux.0' /etc/dhcp*/dhcpd*.conf; then |
---|
464 | perl -pi -e 's/pxelinux.0/grldr/' /etc/dhcp*/dhcpd*.conf |
---|
465 | for i in isc-dhcp-server dhcpd3-server dhcpd; do |
---|
466 | [ -f /etc/init.d/$i ] && /etc/init.d/$i restart |
---|
467 | done |
---|
468 | fi |
---|
469 | echoAndLog "${FUNCNAME}(): updating cron files" |
---|
470 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/opengnsys.cron ] && $INSTALL_TARGET/bin/opengnsys.cron" > /etc/cron.d/opengnsys |
---|
471 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator |
---|
472 | echoAndLog "${FUNCNAME}(): server files updated successfully." |
---|
473 | } |
---|
474 | |
---|
475 | #################################################################### |
---|
476 | ### Funciones de compilación de código fuente de servicios |
---|
477 | #################################################################### |
---|
478 | |
---|
479 | # Recompilar y actualiza los serivicios y clientes. |
---|
480 | function compileServices() |
---|
481 | { |
---|
482 | local hayErrores=0 |
---|
483 | |
---|
484 | # Compilar OpenGnSys Server |
---|
485 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Admin Server" |
---|
486 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer |
---|
487 | make && mv ogAdmServer $INSTALL_TARGET/sbin |
---|
488 | if [ $? -ne 0 ]; then |
---|
489 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server" |
---|
490 | hayErrores=1 |
---|
491 | fi |
---|
492 | popd |
---|
493 | # Compilar OpenGnSys Repository Manager |
---|
494 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Repository Manager" |
---|
495 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo |
---|
496 | make && mv ogAdmRepo $INSTALL_TARGET/sbin |
---|
497 | if [ $? -ne 0 ]; then |
---|
498 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager" |
---|
499 | hayErrores=1 |
---|
500 | fi |
---|
501 | popd |
---|
502 | # Compilar OpenGnSys Agent |
---|
503 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Agent" |
---|
504 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent |
---|
505 | make && mv ogAdmAgent $INSTALL_TARGET/sbin |
---|
506 | if [ $? -ne 0 ]; then |
---|
507 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent" |
---|
508 | hayErrores=1 |
---|
509 | fi |
---|
510 | popd |
---|
511 | |
---|
512 | # Compilar OpenGnSys Client |
---|
513 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Client" |
---|
514 | pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient |
---|
515 | make && mv ogAdmClient $INSTALL_TARGET/client/bin |
---|
516 | if [ $? -ne 0 ]; then |
---|
517 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client" |
---|
518 | hayErrores=1 |
---|
519 | fi |
---|
520 | popd |
---|
521 | |
---|
522 | return $hayErrores |
---|
523 | } |
---|
524 | |
---|
525 | |
---|
526 | #################################################################### |
---|
527 | ### Funciones instalacion cliente OpenGnSys |
---|
528 | #################################################################### |
---|
529 | |
---|
530 | # Actualizar nuevo cliente para OpenGnSys 1.0 |
---|
531 | function updateClient() |
---|
532 | { |
---|
533 | local DOWNLOADURL="http://www.opengnsys.es/downloads" |
---|
534 | local FILENAME=ogLive-natty-2.6.38-8-generic-pae-r2303.iso |
---|
535 | local SOURCEFILE=$DOWNLOADURL/$FILENAME |
---|
536 | local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME |
---|
537 | local SOURCELENGTH |
---|
538 | local TARGETLENGTH |
---|
539 | local TMPDIR=/tmp/${FILENAME%.iso} |
---|
540 | local OGINITRD=$INSTALL_TARGET/tftpboot/ogclient/oginitrd.img |
---|
541 | local SAMBAPASS |
---|
542 | |
---|
543 | # Comprobar si debe actualizarse el cliente. |
---|
544 | SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}') |
---|
545 | TARGETLENGTH=$(ls -l $TARGETFILE 2>/dev/null | awk '{print $5}') |
---|
546 | [ -z $TARGETLENGTH ] && TARGETLENGTH=0 |
---|
547 | if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then |
---|
548 | echoAndLog "${FUNCNAME}(): Loading Client" |
---|
549 | wget $DOWNLOADURL/$FILENAME -O $TARGETFILE |
---|
550 | if [ ! -s $TARGETFILE ]; then |
---|
551 | errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client" |
---|
552 | return 1 |
---|
553 | fi |
---|
554 | # Obtener la clave actual de acceso a Samba para restaurarla. |
---|
555 | if [ -f $OGINITRD ]; then |
---|
556 | SAMBAPASS=$(gzip -dc $OGINITRD | \ |
---|
557 | cpio -i --to-stdout scripts/ogfunctions 2>&1 | \ |
---|
558 | grep "^[ ]*OPTIONS=" | \ |
---|
559 | sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/') |
---|
560 | fi |
---|
561 | # Montar la imagen ISO del ogclient, actualizar ficheros y desmontar. |
---|
562 | echoAndLog "${FUNCNAME}(): Updatting ogclient files" |
---|
563 | mkdir -p $TMPDIR |
---|
564 | mount -o loop,ro $TARGETFILE $TMPDIR |
---|
565 | rsync -irlt $TMPDIR/ogclient $INSTALL_TARGET/tftpboot |
---|
566 | umount $TMPDIR |
---|
567 | rmdir $TMPDIR |
---|
568 | # Recuperar la clave de acceso a Samba. |
---|
569 | if [ -n "$SAMBAPASS" ]; then |
---|
570 | echoAndLog "${FUNCNAME}(): Restoring client access key" |
---|
571 | echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | \ |
---|
572 | $INSTALL_TARGET/bin/setsmbpass |
---|
573 | fi |
---|
574 | # Establecer los permisos. |
---|
575 | find -L $INSTALL_TARGET/tftpboot -type d -exec chmod 755 {} \; |
---|
576 | find -L $INSTALL_TARGET/tftpboot -type f -exec chmod 644 {} \; |
---|
577 | chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient |
---|
578 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/tftpboot/{menu.lst,pxelinux.cfg} |
---|
579 | |
---|
580 | # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache |
---|
581 | cp -arv $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz* $INSTALL_TARGET/tftpboot |
---|
582 | cp -arv $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img* $INSTALL_TARGET/tftpboot |
---|
583 | |
---|
584 | echoAndLog "${FUNCNAME}(): Client update successfully" |
---|
585 | else |
---|
586 | echoAndLog "${FUNCNAME}(): Client is already updated" |
---|
587 | fi |
---|
588 | } |
---|
589 | |
---|
590 | # Resumen de actualización. |
---|
591 | function updateSummary() |
---|
592 | { |
---|
593 | # Actualizar fichero de versión y revisión. |
---|
594 | local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt" |
---|
595 | local REVISION=$(LANG=C svn info $SVN_URL|awk '/Revision:/ {print "r"$2}') |
---|
596 | |
---|
597 | [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE |
---|
598 | perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE |
---|
599 | |
---|
600 | echo |
---|
601 | echoAndLog "OpenGnSys Update Summary" |
---|
602 | echo "========================" |
---|
603 | echoAndLog "Project version: $(cat $VERSIONFILE)" |
---|
604 | echo |
---|
605 | } |
---|
606 | |
---|
607 | |
---|
608 | |
---|
609 | ##################################################################### |
---|
610 | ####### Proceso de actualización de OpenGnSys |
---|
611 | ##################################################################### |
---|
612 | |
---|
613 | |
---|
614 | echoAndLog "OpenGnSys update begins at $(date)" |
---|
615 | |
---|
616 | pushd $WORKDIR |
---|
617 | |
---|
618 | # Comprobar si hay conexión y detectar parámetros de red por defecto. |
---|
619 | checkNetworkConnection |
---|
620 | if [ $? -ne 0 ]; then |
---|
621 | errorAndLog "Error connecting to server. Causes:" |
---|
622 | errorAndLog " - Network is unreachable, review devices parameters." |
---|
623 | errorAndLog " - You are inside a private network, configure the proxy service." |
---|
624 | errorAndLog " - Server is temporally down, try agian later." |
---|
625 | exit 1 |
---|
626 | fi |
---|
627 | |
---|
628 | # Comprobar auto-actualización del programa. |
---|
629 | if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then |
---|
630 | checkAutoUpdate |
---|
631 | if [ $? -ne 0 ]; then |
---|
632 | echoAndLog "OpenGnSys updater has been overwritten." |
---|
633 | echoAndLog "Please, re-execute this script." |
---|
634 | exit |
---|
635 | fi |
---|
636 | fi |
---|
637 | |
---|
638 | # Instalar dependencias. |
---|
639 | installDependencies $DEPS |
---|
640 | if [ $? -ne 0 ]; then |
---|
641 | errorAndLog "Error: you may install all needed dependencies." |
---|
642 | exit 1 |
---|
643 | fi |
---|
644 | |
---|
645 | # Arbol de directorios de OpenGnSys. |
---|
646 | createDirs ${INSTALL_TARGET} |
---|
647 | if [ $? -ne 0 ]; then |
---|
648 | errorAndLog "Error while creating directory paths!" |
---|
649 | exit 1 |
---|
650 | fi |
---|
651 | |
---|
652 | # Si es necesario, descarga el repositorio de código en directorio temporal |
---|
653 | if [ $USESVN -eq 1 ]; then |
---|
654 | svnExportCode $SVN_URL |
---|
655 | if [ $? -ne 0 ]; then |
---|
656 | errorAndLog "Error while getting code from svn" |
---|
657 | exit 1 |
---|
658 | fi |
---|
659 | else |
---|
660 | ln -fs "$(dirname $PROGRAMDIR)" opengnsys |
---|
661 | fi |
---|
662 | |
---|
663 | # Si existe fichero de actualización de la base de datos; aplicar cambios. |
---|
664 | INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt) |
---|
665 | REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt) |
---|
666 | OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql" |
---|
667 | if [ -f $OPENGNSYS_DBUPDATEFILE ]; then |
---|
668 | echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION" |
---|
669 | importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE |
---|
670 | else |
---|
671 | echoAndLog "Database unchanged." |
---|
672 | fi |
---|
673 | |
---|
674 | # Actualizar ficheros complementarios del servidor |
---|
675 | updateServerFiles |
---|
676 | if [ $? -ne 0 ]; then |
---|
677 | errorAndLog "Error updating OpenGnSys Server files" |
---|
678 | exit 1 |
---|
679 | fi |
---|
680 | |
---|
681 | # Actualizar ficheros del cliente |
---|
682 | updateClientFiles |
---|
683 | updateInterfaceAdm |
---|
684 | |
---|
685 | # Actualizar páqinas web |
---|
686 | apacheConfiguration |
---|
687 | updateWebFiles |
---|
688 | if [ $? -ne 0 ]; then |
---|
689 | errorAndLog "Error updating OpenGnSys Web Admin files" |
---|
690 | exit 1 |
---|
691 | fi |
---|
692 | # Generar páginas Doxygen para instalar en el web |
---|
693 | makeDoxygenFiles |
---|
694 | |
---|
695 | # Recompilar y actualizar los servicios del sistema |
---|
696 | compileServices |
---|
697 | |
---|
698 | # Actaulizar ficheros auxiliares del cliente |
---|
699 | updateClient |
---|
700 | if [ $? -ne 0 ]; then |
---|
701 | errorAndLog "Error updating clients" |
---|
702 | exit 1 |
---|
703 | fi |
---|
704 | |
---|
705 | # Actualizamos el fichero que arranca los servicios de OpenGnSys |
---|
706 | updateServicesStart |
---|
707 | |
---|
708 | # Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes |
---|
709 | if [ -f /tmp/dstate ]; then |
---|
710 | rm -f /tmp/dstate |
---|
711 | fi |
---|
712 | |
---|
713 | # Mostrar resumen de actualización. |
---|
714 | updateSummary |
---|
715 | |
---|
716 | #rm -rf $WORKDIR |
---|
717 | echoAndLog "OpenGnSys update finished at $(date)" |
---|
718 | |
---|
719 | popd |
---|
720 | |
---|