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 | #*/ |
---|
13 | |
---|
14 | |
---|
15 | #### AVISO: Editar configuración de acceso por defecto a la Base de Datos. |
---|
16 | OPENGNSYS_DATABASE="ogAdmBD" # Nombre de la base datos |
---|
17 | OPENGNSYS_DBUSER="usuog" # Usuario de acceso |
---|
18 | OPENGNSYS_DBPASSWORD="passusuog" # Clave del usuario |
---|
19 | |
---|
20 | #### AVISO: NO Editar variables de acceso desde el cliente |
---|
21 | OPENGNSYS_CLIENTUSER="opengnsys" # Usuario Samba |
---|
22 | |
---|
23 | |
---|
24 | # Sólo ejecutable por usuario root |
---|
25 | if [ "$(whoami)" != 'root' ] |
---|
26 | then |
---|
27 | echo "ERROR: this program must run under root privileges!!" |
---|
28 | exit 1 |
---|
29 | fi |
---|
30 | |
---|
31 | # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). |
---|
32 | PROGRAMDIR=$(readlink -e $(dirname "$0")) |
---|
33 | DEPS="build-essential g++-multilib rsync ctorrent samba unzip netpipes debootstrap schroot squashfs-tools" |
---|
34 | if [ -d "$PROGRAMDIR/../installer" ]; then |
---|
35 | USESVN=0 |
---|
36 | else |
---|
37 | USESVN=1 |
---|
38 | SVN_URL=http://www.opengnsys.es/svn/branches/version1.0 |
---|
39 | DEPS="$DEPS subversion" |
---|
40 | fi |
---|
41 | |
---|
42 | WORKDIR=/tmp/opengnsys_update |
---|
43 | mkdir -p $WORKDIR |
---|
44 | |
---|
45 | INSTALL_TARGET=/opt/opengnsys |
---|
46 | LOG_FILE=/tmp/opengnsys_update.log |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | ##################################################################### |
---|
51 | ####### Algunas funciones útiles de propósito general: |
---|
52 | ##################################################################### |
---|
53 | |
---|
54 | function getDateTime() |
---|
55 | { |
---|
56 | date "+%Y%m%d-%H%M%S" |
---|
57 | } |
---|
58 | |
---|
59 | # Escribe a fichero y muestra por pantalla |
---|
60 | function echoAndLog() |
---|
61 | { |
---|
62 | echo $1 |
---|
63 | FECHAHORA=`getDateTime` |
---|
64 | echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
65 | } |
---|
66 | |
---|
67 | function errorAndLog() |
---|
68 | { |
---|
69 | echo "ERROR: $1" |
---|
70 | FECHAHORA=`getDateTime` |
---|
71 | echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | ##################################################################### |
---|
76 | ####### Funciones de copia de seguridad y restauración de ficheros |
---|
77 | ##################################################################### |
---|
78 | |
---|
79 | # Hace un backup del fichero pasado por parámetro |
---|
80 | # deja un -last y uno para el día |
---|
81 | function backupFile() |
---|
82 | { |
---|
83 | if [ $# -ne 1 ]; then |
---|
84 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
85 | exit 1 |
---|
86 | fi |
---|
87 | |
---|
88 | local fichero=$1 |
---|
89 | local fecha=`date +%Y%m%d` |
---|
90 | |
---|
91 | if [ ! -f $fichero ]; then |
---|
92 | errorAndLog "${FUNCNAME}(): file $fichero doesn't exists" |
---|
93 | return 1 |
---|
94 | fi |
---|
95 | |
---|
96 | echoAndLog "${FUNCNAME}(): Making $fichero back-up" |
---|
97 | |
---|
98 | # realiza una copia de la última configuración como last |
---|
99 | cp -p $fichero "${fichero}-LAST" |
---|
100 | |
---|
101 | # si para el día no hay backup lo hace, sino no |
---|
102 | if [ ! -f "${fichero}-${fecha}" ]; then |
---|
103 | cp -p $fichero "${fichero}-${fecha}" |
---|
104 | fi |
---|
105 | } |
---|
106 | |
---|
107 | # Restaura un fichero desde su copia de seguridad |
---|
108 | function restoreFile() |
---|
109 | { |
---|
110 | if [ $# -ne 1 ]; then |
---|
111 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
112 | exit 1 |
---|
113 | fi |
---|
114 | |
---|
115 | local fichero=$1 |
---|
116 | |
---|
117 | echoAndLog "${FUNCNAME}(): restoring file $fichero" |
---|
118 | if [ -f "${fichero}-LAST" ]; then |
---|
119 | cp -p "$fichero-LAST" "$fichero" |
---|
120 | fi |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | ##################################################################### |
---|
125 | ####### Funciones de acceso a base de datos |
---|
126 | ##################################################################### |
---|
127 | |
---|
128 | # Actualizar la base datos |
---|
129 | function importSqlFile() |
---|
130 | { |
---|
131 | if [ $# -ne 4 ]; then |
---|
132 | errorAndLog "${FNCNAME}(): invalid number of parameters" |
---|
133 | exit 1 |
---|
134 | fi |
---|
135 | |
---|
136 | local dbuser="$1" |
---|
137 | local dbpassword="$2" |
---|
138 | local database="$3" |
---|
139 | local sqlfile="$4" |
---|
140 | local tmpfile=$(mktemp) |
---|
141 | local status |
---|
142 | |
---|
143 | if [ ! -r $sqlfile ]; then |
---|
144 | errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!" |
---|
145 | return 1 |
---|
146 | fi |
---|
147 | |
---|
148 | echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..." |
---|
149 | chmod 600 $tmpfile |
---|
150 | sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
151 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" $sqlfile > $tmpfile |
---|
152 | mysql -u$dbuser -p"$dbpassword" --default-character-set=utf8 "$database" < $tmpfile |
---|
153 | status=$? |
---|
154 | rm -f $tmpfile |
---|
155 | if [ $status -ne 0 ]; then |
---|
156 | errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database" |
---|
157 | return 1 |
---|
158 | fi |
---|
159 | echoAndLog "${FUNCNAME}(): file imported to database $database" |
---|
160 | return 0 |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | ##################################################################### |
---|
165 | ####### Funciones de instalación de paquetes |
---|
166 | ##################################################################### |
---|
167 | |
---|
168 | # Instalar las deependencias necesarias para el actualizador. |
---|
169 | function installDependencies () |
---|
170 | { |
---|
171 | if [ $# = 0 ]; then |
---|
172 | echoAndLog "${FUNCNAME}(): no deps needed." |
---|
173 | else |
---|
174 | while [ $# -gt 0 ]; do |
---|
175 | dpkg -s $1 2>/dev/null | grep -q "Status: install ok" |
---|
176 | if [ $? -ne 0 ]; then |
---|
177 | INSTALLDEPS="$INSTALLDEPS $1" |
---|
178 | fi |
---|
179 | shift |
---|
180 | done |
---|
181 | if [ -n "$INSTALLDEPS" ]; then |
---|
182 | apt-get update && apt-get -y install --force-yes $INSTALLDEPS |
---|
183 | if [ $? -ne 0 ]; then |
---|
184 | errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS." |
---|
185 | return 1 |
---|
186 | fi |
---|
187 | fi |
---|
188 | fi |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | ##################################################################### |
---|
193 | ####### Funciones para el manejo de Subversion |
---|
194 | ##################################################################### |
---|
195 | |
---|
196 | function svnExportCode() |
---|
197 | { |
---|
198 | if [ $# -ne 1 ]; then |
---|
199 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
200 | exit 1 |
---|
201 | fi |
---|
202 | |
---|
203 | local url=$1 |
---|
204 | |
---|
205 | echoAndLog "${FUNCNAME}(): downloading subversion code..." |
---|
206 | |
---|
207 | svn checkout "${url}" opengnsys |
---|
208 | if [ $? -ne 0 ]; then |
---|
209 | errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password" |
---|
210 | return 1 |
---|
211 | fi |
---|
212 | echoAndLog "${FUNCNAME}(): subversion code downloaded" |
---|
213 | return 0 |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | ############################################################ |
---|
218 | ### Detectar red |
---|
219 | ############################################################ |
---|
220 | |
---|
221 | function getNetworkSettings() |
---|
222 | { |
---|
223 | local MAINDEV |
---|
224 | |
---|
225 | echoAndLog "getNetworkSettings(): Detecting default network parameters." |
---|
226 | MAINDEV=$(ip -o link show up | awk '!/loopback/ {d=d$2} END {sub(/:.*/,"",d); print d}') |
---|
227 | if [ -z "$MAINDEV" ]; then |
---|
228 | errorAndLog "${FUNCNAME}(): Network device not detected." |
---|
229 | return 1 |
---|
230 | fi |
---|
231 | |
---|
232 | # Variables de ejecución de Apache |
---|
233 | # - APACHE_RUN_USER |
---|
234 | # - APACHE_RUN_GROUP |
---|
235 | if [ -f /etc/apache2/envvars ]; then |
---|
236 | source /etc/apache2/envvars |
---|
237 | fi |
---|
238 | APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"} |
---|
239 | APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"} |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | ##################################################################### |
---|
244 | ####### Funciones específicas de la instalación de Opengnsys |
---|
245 | ##################################################################### |
---|
246 | |
---|
247 | # Copiar ficheros de arranque de los servicios del sistema de OpenGnSys |
---|
248 | |
---|
249 | function updateServicesStart(){ |
---|
250 | echoAndLog "${FUNCNAME}(): Updating /etc/init.d/opengnsys ..." |
---|
251 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys |
---|
252 | if [ $? != 0 ]; then |
---|
253 | errorAndLog "${FUNCNAME}(): Error updating /etc/init.d/opengnsys" |
---|
254 | exit 1 |
---|
255 | fi |
---|
256 | echoAndLog "${FUNCNAME}(): /etc/init.d/opengnsys updated successfully." |
---|
257 | } |
---|
258 | |
---|
259 | # Actualizar cliente OpenGnSys |
---|
260 | function updateClientFiles() |
---|
261 | { |
---|
262 | local hayErrores=0 |
---|
263 | |
---|
264 | echoAndLog "${FUNCNAME}(): Updating OpenGnSys Client files." |
---|
265 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client |
---|
266 | if [ $? -ne 0 ]; then |
---|
267 | errorAndLog "${FUNCNAME}(): error while updating client structure" |
---|
268 | hayErrores=1 |
---|
269 | fi |
---|
270 | find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
271 | |
---|
272 | echoAndLog "${FUNCNAME}(): Updating OpenGnSys Cloning Engine files." |
---|
273 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin |
---|
274 | if [ $? -ne 0 ]; then |
---|
275 | errorAndLog "${FUNCNAME}(): error while updating engine files" |
---|
276 | hayErrores=1 |
---|
277 | fi |
---|
278 | |
---|
279 | if [ $hayErrores -eq 0 ]; then |
---|
280 | echoAndLog "${FUNCNAME}(): client files update success." |
---|
281 | else |
---|
282 | errorAndLog "${FUNCNAME}(): client files update with errors" |
---|
283 | fi |
---|
284 | |
---|
285 | return $hayErrores |
---|
286 | } |
---|
287 | # Copiar ficheros del OpenGnSys Web Console. |
---|
288 | function updateWebFiles() |
---|
289 | { |
---|
290 | local ERRCODE |
---|
291 | echoAndLog "${FUNCNAME}(): Updating web files..." |
---|
292 | backupFile $INSTALL_TARGET/www/controlacceso.php |
---|
293 | mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole |
---|
294 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET |
---|
295 | ERRCODE=$? |
---|
296 | mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www |
---|
297 | unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax |
---|
298 | if [ $ERRCODE != 0 ]; then |
---|
299 | errorAndLog "${FUNCNAME}(): Error updating web files." |
---|
300 | exit 1 |
---|
301 | fi |
---|
302 | restoreFile $INSTALL_TARGET/www/controlacceso.php |
---|
303 | # Cambiar permisos para ficheros especiales. |
---|
304 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/includes $INSTALL_TARGET/www/images/iconos |
---|
305 | echoAndLog "${FUNCNAME}(): Web files updated successfully." |
---|
306 | |
---|
307 | } |
---|
308 | |
---|
309 | # Copiar carpeta de Interface |
---|
310 | function updateInterfaceAdm () |
---|
311 | { |
---|
312 | local hayErrores=0 |
---|
313 | |
---|
314 | # Crear carpeta y copiar Interface |
---|
315 | echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" |
---|
316 | mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface |
---|
317 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client |
---|
318 | ERRCODE=$? |
---|
319 | mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm |
---|
320 | if [ $? -ne 0 ]; then |
---|
321 | echoAndLog "${FUNCNAME}(): error while updating admin interface" |
---|
322 | exit 1 |
---|
323 | fi |
---|
324 | chmod -R +x $INSTALL_TARGET/client/interfaceAdm |
---|
325 | chown :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
326 | chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
327 | echoAndLog "${FUNCNAME}(): Admin interface updated successfully." |
---|
328 | } |
---|
329 | |
---|
330 | # Crear documentación Doxygen para la consola web. |
---|
331 | function makeDoxygenFiles() |
---|
332 | { |
---|
333 | echoAndLog "${FUNCNAME}(): Making Doxygen web files..." |
---|
334 | $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \ |
---|
335 | $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www |
---|
336 | if [ ! -d "$INSTALL_TARGET/www/html" ]; then |
---|
337 | errorAndLog "${FUNCNAME}(): unable to create Doxygen web files." |
---|
338 | return 1 |
---|
339 | fi |
---|
340 | rm -fr "$INSTALL_TARGET/www/api" |
---|
341 | mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api" |
---|
342 | rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf} |
---|
343 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api |
---|
344 | echoAndLog "${FUNCNAME}(): Doxygen web files created successfully." |
---|
345 | } |
---|
346 | |
---|
347 | |
---|
348 | # Crea la estructura base de la instalación de opengnsys |
---|
349 | function createDirs() |
---|
350 | { |
---|
351 | echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}" |
---|
352 | |
---|
353 | mkdir -p ${INSTALL_TARGET} |
---|
354 | mkdir -p ${INSTALL_TARGET}/bin |
---|
355 | mkdir -p ${INSTALL_TARGET}/client |
---|
356 | mkdir -p ${INSTALL_TARGET}/doc |
---|
357 | mkdir -p ${INSTALL_TARGET}/etc |
---|
358 | mkdir -p ${INSTALL_TARGET}/lib |
---|
359 | mkdir -p ${INSTALL_TARGET}/log/clients |
---|
360 | mkdir -p ${INSTALL_TARGET}/sbin |
---|
361 | mkdir -p ${INSTALL_TARGET}/www |
---|
362 | mkdir -p ${INSTALL_TARGET}/images |
---|
363 | ln -fs /var/lib/tftpboot ${INSTALL_TARGET} |
---|
364 | ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys |
---|
365 | |
---|
366 | if [ $? -ne 0 ]; then |
---|
367 | errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" |
---|
368 | return 1 |
---|
369 | fi |
---|
370 | |
---|
371 | echoAndLog "${FUNCNAME}(): directory paths created" |
---|
372 | return 0 |
---|
373 | } |
---|
374 | |
---|
375 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
376 | function updateServerFiles () { |
---|
377 | |
---|
378 | # No copiar ficheros del antiguo cliente Initrd |
---|
379 | local SOURCES=( repoman/bin \ |
---|
380 | server/bin \ |
---|
381 | doc ) |
---|
382 | local TARGETS=( bin \ |
---|
383 | bin \ |
---|
384 | doc ) |
---|
385 | |
---|
386 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
387 | errorAndLog "${FUNCNAME}(): inconsistent number of array items" |
---|
388 | exit 1 |
---|
389 | fi |
---|
390 | |
---|
391 | echoAndLog "${FUNCNAME}(): updating files in server directories" |
---|
392 | pushd $WORKDIR/opengnsys >/dev/null |
---|
393 | local i |
---|
394 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
395 | rsync --exclude .svn -irplt "${SOURCES[$i]}" $(dirname "${INSTALL_TARGET}/${TARGETS[$i]}") |
---|
396 | done |
---|
397 | popd >/dev/null |
---|
398 | echoAndLog "${FUNCNAME}(): updating cron files" |
---|
399 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator |
---|
400 | echoAndLog "${FUNCNAME}(): server files updated successfully." |
---|
401 | } |
---|
402 | |
---|
403 | #################################################################### |
---|
404 | ### Funciones de compilación de código fuente de servicios |
---|
405 | #################################################################### |
---|
406 | |
---|
407 | # Recompilar y actualiza el binario del clinete |
---|
408 | function recompileClient () |
---|
409 | { |
---|
410 | # Compilar OpenGnSys Client |
---|
411 | echoAndLog "${FUNCNAME}(): recompiling OpenGnSys Client" |
---|
412 | pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient |
---|
413 | make && mv ogAdmClient $INSTALL_TARGET/client/bin |
---|
414 | if [ $? -ne 0 ]; then |
---|
415 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client" |
---|
416 | hayErrores=1 |
---|
417 | fi |
---|
418 | popd |
---|
419 | |
---|
420 | return $hayErrores |
---|
421 | } |
---|
422 | |
---|
423 | |
---|
424 | #################################################################### |
---|
425 | ### Funciones instalacion cliente opengnsys |
---|
426 | #################################################################### |
---|
427 | |
---|
428 | # Actualizar antiguo cliente Initrd. |
---|
429 | function updateOldClient() |
---|
430 | { |
---|
431 | local OSDISTRIB OSCODENAME |
---|
432 | |
---|
433 | local hayErrores=0 |
---|
434 | |
---|
435 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files." |
---|
436 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client |
---|
437 | echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files." |
---|
438 | mkdir -p $INSTALL_TARGET/client/lib/engine/bin |
---|
439 | rsync -iplt $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin |
---|
440 | if [ $? -ne 0 ]; then |
---|
441 | errorAndLog "${FUNCNAME}(): error while copying engine files" |
---|
442 | hayErrores=1 |
---|
443 | fi |
---|
444 | |
---|
445 | # Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto). |
---|
446 | OSDISTRIB=$(lsb_release -is) 2>/dev/null |
---|
447 | OSCODENAME=$(lsb_release -cs) 2>/dev/null |
---|
448 | if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then |
---|
449 | echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME." |
---|
450 | $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v $OSCODENAME 2>&1 | tee -a $LOG_FILE |
---|
451 | if [ $? -ne 0 ]; then |
---|
452 | errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client" |
---|
453 | hayErrores=1 |
---|
454 | fi |
---|
455 | echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME." |
---|
456 | $INSTALL_TARGET/bin/upgrade-clients-udeb.sh $OSCODENAME 2>&1 | tee -a $LOG_FILE |
---|
457 | if [ $? -ne 0 ]; then |
---|
458 | errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client" |
---|
459 | hayErrores=1 |
---|
460 | fi |
---|
461 | else |
---|
462 | echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files." |
---|
463 | $INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot 2>&1 | tee -a $LOG_FILE |
---|
464 | if [ $? -ne 0 ]; then |
---|
465 | errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client" |
---|
466 | hayErrores=1 |
---|
467 | fi |
---|
468 | echoAndLog "${FUNCNAME}(): Loading default udeb files." |
---|
469 | $INSTALL_TARGET/bin/upgrade-clients-udeb.sh 2>&1 | tee -a $LOG_FILE |
---|
470 | if [ $? -ne 0 ]; then |
---|
471 | errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client" |
---|
472 | hayErrores=1 |
---|
473 | fi |
---|
474 | fi |
---|
475 | |
---|
476 | if [ $hayErrores -eq 0 ]; then |
---|
477 | echoAndLog "${FUNCNAME}(): Client generation success." |
---|
478 | else |
---|
479 | errorAndLog "${FUNCNAME}(): Client generation with errors" |
---|
480 | fi |
---|
481 | |
---|
482 | return $hayErrores |
---|
483 | } |
---|
484 | |
---|
485 | # Actualizar nuevo cliente para OpenGnSys 1.0 |
---|
486 | function updateClient() |
---|
487 | { |
---|
488 | local DOWNLOADURL=http://www.opengnsys.es/downloads |
---|
489 | local FILENAME=ogclient-1.0-lucid-32bit.tar.gz |
---|
490 | local TMPFILE=/tmp/$FILENAME |
---|
491 | |
---|
492 | echoAndLog "${FUNCNAME}(): Loading Client" |
---|
493 | # Descargar y descomprimir cliente ogclient |
---|
494 | wget $DOWNLOADURL/$FILENAME -O $TMPFILE |
---|
495 | if [ ! -s $TMPFILE ]; then |
---|
496 | errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client" |
---|
497 | return 1 |
---|
498 | fi |
---|
499 | echoAndLog "${FUNCNAME}(): Extracting Client files" |
---|
500 | tar xzvf $TMPFILE -C $INSTALL_TARGET/tftpboot |
---|
501 | rm -f $TMPFILE |
---|
502 | # Usar la versión más reciente del Kernel y del Initrd para el cliente. |
---|
503 | ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/vmlinuz-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz |
---|
504 | ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/initrd.img-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img |
---|
505 | # Establecer los permisos. |
---|
506 | chmod -R 755 $INSTALL_TARGET/tftpboot/ogclient |
---|
507 | chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient |
---|
508 | echoAndLog "${FUNCNAME}(): Client update successfully" |
---|
509 | } |
---|
510 | |
---|
511 | |
---|
512 | ##################################################################### |
---|
513 | ####### Proceso de actualización de OpenGnSys |
---|
514 | ##################################################################### |
---|
515 | |
---|
516 | |
---|
517 | echoAndLog "OpenGnSys update begins at $(date)" |
---|
518 | |
---|
519 | # Instalar dependencia. |
---|
520 | installDependencies $DEPS |
---|
521 | if [ $? -ne 0 ]; then |
---|
522 | errorAndLog "Error: you may install all needed dependencies." |
---|
523 | exit 1 |
---|
524 | fi |
---|
525 | |
---|
526 | pushd $WORKDIR |
---|
527 | |
---|
528 | # Detectar parámetros de red por defecto |
---|
529 | getNetworkSettings |
---|
530 | if [ $? -ne 0 ]; then |
---|
531 | errorAndLog "Error reading default network settings." |
---|
532 | exit 1 |
---|
533 | fi |
---|
534 | |
---|
535 | # Arbol de directorios de OpenGnSys. |
---|
536 | createDirs ${INSTALL_TARGET} |
---|
537 | if [ $? -ne 0 ]; then |
---|
538 | errorAndLog "Error while creating directory paths!" |
---|
539 | exit 1 |
---|
540 | fi |
---|
541 | |
---|
542 | # Si es necesario, descarga el repositorio de código en directorio temporal |
---|
543 | if [ $USESVN -eq 1 ]; then |
---|
544 | svnExportCode $SVN_URL |
---|
545 | if [ $? -ne 0 ]; then |
---|
546 | errorAndLog "Error while getting code from svn" |
---|
547 | exit 1 |
---|
548 | fi |
---|
549 | else |
---|
550 | ln -fs "$(dirname $PROGRAMDIR)" opengnsys |
---|
551 | fi |
---|
552 | |
---|
553 | # Si existe fichero de actualización de la base de datos; aplicar cambios. |
---|
554 | INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt) |
---|
555 | REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt) |
---|
556 | OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql" |
---|
557 | if [ -f $OPENGNSYS_DBUPDATEFILE ]; then |
---|
558 | echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION" |
---|
559 | importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE |
---|
560 | else |
---|
561 | echoAndLog "Database unchanged." |
---|
562 | fi |
---|
563 | |
---|
564 | # Actualizar ficheros complementarios del servidor |
---|
565 | updateServerFiles |
---|
566 | if [ $? -ne 0 ]; then |
---|
567 | errorAndLog "Error updating OpenGnSys Server files" |
---|
568 | exit 1 |
---|
569 | fi |
---|
570 | |
---|
571 | # Actualizar ficheros del cliente |
---|
572 | updateClientFiles |
---|
573 | updateInterfaceAdm |
---|
574 | |
---|
575 | # Actualizar páqinas web |
---|
576 | updateWebFiles |
---|
577 | if [ $? -ne 0 ]; then |
---|
578 | errorAndLog "Error updating OpenGnSys Web Admin files" |
---|
579 | exit 1 |
---|
580 | fi |
---|
581 | # Generar páginas Doxygen para instalar en el web |
---|
582 | makeDoxygenFiles |
---|
583 | |
---|
584 | # Creando la estructura del cliente |
---|
585 | recompileClient |
---|
586 | # NO se actualiza el antiguo cliente Initrd |
---|
587 | #updateOldClient |
---|
588 | updateClient |
---|
589 | if [ $? -ne 0 ]; then |
---|
590 | errorAndLog "Error updating clients" |
---|
591 | exit 1 |
---|
592 | fi |
---|
593 | |
---|
594 | # Actualizamos el fichero que arranca los servicios de OpenGnSys |
---|
595 | updateServicesStart |
---|
596 | |
---|
597 | # Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes |
---|
598 | if [ -f /tmp/dstate ]; then |
---|
599 | rm -f /tmp/dstate |
---|
600 | fi |
---|
601 | |
---|
602 | #rm -rf $WORKDIR |
---|
603 | echoAndLog "OpenGnSys update finished at $(date)" |
---|
604 | |
---|
605 | popd |
---|
606 | |
---|