[914d834] | 1 | #!/bin/bash |
---|
[841ce50] | 2 | #/** |
---|
[d2f28cf] | 3 | #@file deployImage |
---|
| 4 | #@brief Proceso completo de despliegue de imagen, incluyendo actualización de la caché, restauración y post-configuración (este script es llamado por la interfaz RestaurarImagen). |
---|
[96d7f3f] | 5 | #@param $1 Repositorio (CACHE, REPO o dirección IP) |
---|
| 6 | #@param $2 Nombre canónico de la imagen (sin extensión) |
---|
| 7 | #@param $3 Número de disco |
---|
| 8 | #@param $4 Número de particion |
---|
[d2f28cf] | 9 | #@param $5 Protocolo (UNICAST, por defecto, MULTICAST o TORRENT) |
---|
| 10 | #@param $6 Opciones del protocolo |
---|
| 11 | #@exception OG_ERR_FORMAT 1 formato incorrecto. |
---|
| 12 | #@exception OG_ERR_NOTFOUND 2 fichero de imagen o partición no detectados. |
---|
| 13 | #@exception OG_ERR_PARTITION 3 # Error en partición de disco. |
---|
| 14 | #@exception OG_ERR_LOCKED 4 partición bloqueada por otra operación. |
---|
| 15 | #@exception OG_ERR_IMAGE 5 error al restaurar la imagen del sistema. |
---|
| 16 | #@exception OG_ERR_IMGSIZEPARTITION 30 Tamaño de la particion es menor al tamaño de la imagen. |
---|
[1a2fa9d8] | 17 | #@exception OG_ERR_NOTCACHE No existe cache -15- |
---|
| 18 | #@exception OG_ERR_CACHESIZE Tamaño de la paticion menor al archivo a descargar -16- |
---|
[d2f28cf] | 19 | #@version 1.0.1 - Separación en protocolos de transferencia y postconfiguracion |
---|
| 20 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 21 | #@date 2011-05-11 |
---|
| 22 | #@version 1.0.1 - Separación de los ficheros-log para ser gestionado por el httpd-log |
---|
| 23 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 24 | #@date 2011-05-11 |
---|
| 25 | #@version 1.0.2 - Logica basada en fichero de configuracion engine.cfg |
---|
| 26 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 27 | #@date 2012-01-11 |
---|
| 28 | #@version 1.0.5 - Renominación del script como "deployImage". |
---|
| 29 | #@author Antonio J. Doblas Viso y Ramón M. Gómez. |
---|
| 30 | #@date 2013-12-04 |
---|
[1a2fa9d8] | 31 | #@version 1.0.6 - Se añade la gestión de errores de la CACHE cuando en el engine.cfg se define RESTOREPROTOCOLNOCACHE=NONE. |
---|
| 32 | #@author Antonio J. Doblas Viso. |
---|
| 33 | #@date 2015-02-23 |
---|
[fe6843b] | 34 | #@version 1.1 - Cambio de repositorio para el recurso remoto images si es necesario |
---|
| 35 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
| 36 | #@date 2015-06-16 |
---|
[d2f28cf] | 37 | #**/ |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | #Descripcion: |
---|
[1a2fa9d8] | 41 | # Si Repositorio es el global (REPO) realiza un deploy. |
---|
| 42 | # Si Repositorio es local (CACHE) realiza un restoreImage CACHE |
---|
| 43 | # El deploy, si detecta que el cliente no tiene una CACHE o no tiene espacio suficiente consulta el engine.cfg RESTOREPROTOCOLNOCACHE |
---|
[f311787] | 44 | |
---|
| 45 | |
---|
| 46 | |
---|
[914d834] | 47 | PROG="$(basename $0)" |
---|
| 48 | if [ $# -lt 4 ]; then |
---|
[811d00e] | 49 | ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO imagen ndisco nparticion [ UNICAST-DIRECT|UNICAST|UNICAST-CACHE|MULTICAST-DIRECT|MULTICAST|MULTICAST-CACHE|TORRENT [opciones protocolo] ]" |
---|
[914d834] | 50 | exit $? |
---|
| 51 | fi |
---|
| 52 | |
---|
[d2f28cf] | 53 | # Asignación de variables (repositorio y protocolo se convierten a mayúsculas). |
---|
| 54 | TIME1=$SECONDS |
---|
| 55 | REPO="${1^^}" |
---|
[96d7f3f] | 56 | REPO=${REPO:-"REPO"} |
---|
[d2f28cf] | 57 | IMGNAME="$2" |
---|
| 58 | DISK="$3" |
---|
| 59 | PART="$4" |
---|
| 60 | PROTO="${5^^}" |
---|
| 61 | PROTO="${PROTO:-"UNICAST"}" |
---|
| 62 | PROTOOPT="$6" |
---|
| 63 | |
---|
| 64 | #Load engine configurator from engine.cfg file. |
---|
| 65 | #Carga el configurador del engine desde el fichero engine.cfg |
---|
| 66 | [ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg |
---|
[5c23e04] | 67 | |
---|
[d2f28cf] | 68 | # Clear temporary file used as log track by httpdlog |
---|
| 69 | # Limpia los ficheros temporales usados como log de seguimiento para httpdlog |
---|
[4fcbcc8] | 70 | echo " " > $OGLOGCOMMAND |
---|
| 71 | [ "$(ogGetCaller)" == "EjecutarScript" ] || echo -n "" > $OGLOGSESSION |
---|
[5c23e04] | 72 | |
---|
[d2f28cf] | 73 | # Registro de inicio de ejecución |
---|
[e7e3140] | 74 | ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*" |
---|
[5c23e04] | 75 | |
---|
[d2f28cf] | 76 | # Si el origen(pariticion) esta bloqueada salir. |
---|
[64cf3d3] | 77 | ogIsLocked $DISK $PART && exit $(ogRaiseError session $OG_ERR_LOCKED "$MSG_PARTITION, $DISK $PART"; echo $?) |
---|
[5c23e04] | 78 | |
---|
[64cf3d3] | 79 | ogEcho log session "$MSG_HELP_ogUnmount $DISK $PART" |
---|
[d2f28cf] | 80 | ogUnmount $DISK $PART 2>/dev/null |
---|
| 81 | |
---|
| 82 | # Valor por defecto para el repositorio. |
---|
[fe6843b] | 83 | ogCheckIpAddress "$REPO" |
---|
| 84 | [ $? == 0 -o "$REPO" == "REPO" ] && MODE="REPO" |
---|
| 85 | [ "$REPO" == "$(ogGetIpAddress)" -o "$REPO" == "CACHE" ] && MODE="CACHE" |
---|
[d2f28cf] | 86 | |
---|
[fe6843b] | 87 | # Se comenta lo siguiente porque no se puede obtener antes de cambiar de repositorio |
---|
| 88 | # Solo informativo, se comprueba en updateCache y restoreImage |
---|
[d2f28cf] | 89 | #Informacioin previa de la imagen |
---|
[fe6843b] | 90 | #IMGOS=$(ogGetImageInfo `ogGetPath $REPO $IMGNAME.img`) || exit $(ogRaiseError session $OG_ERR_NOTFOUND "$REPO $2"; echo $?) |
---|
| 91 | #IMGSIZE=$(ls -s `ogGetPath $REPO $IMGNAME.img`| cut -f1 -d" ") |
---|
[d2f28cf] | 92 | |
---|
[fe6843b] | 93 | #ogEcho log session "[1] REPO=$REPO IMG-FILE=$IMGNAME.img SIZE=$IMGSIZE (KB) METADATA=$IMGOS" |
---|
[d2f28cf] | 94 | |
---|
| 95 | # Procesar repositorio. |
---|
[fe6843b] | 96 | case "$MODE" in |
---|
[d2f28cf] | 97 | CACHE) # Repositorio en caché local. |
---|
| 98 | NEXTOPERATION=CACHE |
---|
| 99 | ;; |
---|
| 100 | REPO) # Repositorio remoto por defecto. |
---|
| 101 | case "$PROTO" in |
---|
| 102 | MULTICAST-DIRECT) |
---|
| 103 | NEXTOPERATION=MULTICAST |
---|
| 104 | ;; |
---|
| 105 | UNICAST-DIRECT) |
---|
| 106 | NEXTOPERATION=UNICAST |
---|
| 107 | ;; |
---|
| 108 | |
---|
| 109 | # Si protocolo es torrent|torrent-cache o multicast|multicast-cache |
---|
| 110 | TORRENT|TORRENT-CACHE|MULTICAST|MULTICAST-CACHE|UNICAST|UNICAST-CACHE) |
---|
[fe6843b] | 111 | ogEcho log session "[2] updateCache "$REPO" \"/$IMGNAME.img\" $PROTO $PROTOOPT" |
---|
[d2f28cf] | 112 | TIME2=$SECONDS |
---|
[fe6843b] | 113 | updateCache "$REPO" "/$IMGNAME.img" "$PROTO" "$PROTOOPT" |
---|
[d2f28cf] | 114 | RETVAL=$? |
---|
| 115 | TIME2=$[SECONDS-TIME2] |
---|
[e7e3140] | 116 | ogEcho log session " [ ] $MSG_SCRIPTS_TIME_PARTIAL updateCache $[TIME2/60]m $[TIME2%60]s" |
---|
[d2f28cf] | 117 | case $RETVAL in |
---|
| 118 | 0) |
---|
[e7e3140] | 119 | ogEcho log session "[50] updateCache (OK)" |
---|
[d2f28cf] | 120 | NEXTOPERATION=CACHE |
---|
| 121 | ;; |
---|
| 122 | 15|16) |
---|
[1a2fa9d8] | 123 | # no se permite usar la cache (no existe(15) o no espacio sufiente (16). Se consulta engine.cfg para RESTOREPROTOCOLNOCACHE [ multicast unicast none ] |
---|
[e7e3140] | 124 | ogEcho log session "[50] $MSG_ERR_NOTCACHE ; $MSG_ERR_CACHESIZE " |
---|
[1a2fa9d8] | 125 | ogEcho log session "[50] $MSG_SCRIPTS_CHECK_ENGINE: RESTOREPROTOCOLNOTCACHE=$RESTOREPROTOCOLNOTCACHE " |
---|
| 126 | case "$RESTOREPROTOCOLNOTCACHE" in |
---|
| 127 | MULTICAST) |
---|
| 128 | case "$PROTO" in |
---|
| 129 | MULTICAST) NEXTOPERATION=MULTICAST ;; |
---|
| 130 | TORRENT) NEXTOPERATION=UNICAST ;; |
---|
| 131 | UNICAST) NEXTOPERATION=UNICAST ;; |
---|
| 132 | esac |
---|
| 133 | ;; |
---|
| 134 | UNICAST) |
---|
| 135 | NEXTOPERATION=UNICAST |
---|
| 136 | ;; |
---|
| 137 | NONE) |
---|
| 138 | case $RETVAL in |
---|
| 139 | 15) |
---|
| 140 | ogEcho log session "[100] $MSG_ERR_NOTCACHE" |
---|
| 141 | ogRaiseError session $OG_ERR_NOTCACHE "NOT CACHE" |
---|
| 142 | exit $? |
---|
| 143 | ;; |
---|
| 144 | 16) |
---|
| 145 | ogEcho log session "[100] $MSG_ERR_CACHESIZE " |
---|
| 146 | ogRaiseError session $OG_ERR_CACHESIZE "CACHE FULL" |
---|
| 147 | exit $? |
---|
| 148 | ;; |
---|
| 149 | esac # del segundo RETAVAL |
---|
| 150 | ;; |
---|
| 151 | esac # del RESTOREPROTOCOLNOTCACHE |
---|
[d2f28cf] | 152 | ;; |
---|
| 153 | esac |
---|
| 154 | ;; |
---|
| 155 | *) # Error: protocolo desconocido. |
---|
[64cf3d3] | 156 | ogRaiseError session $OG_ERR_FORMAT "$MSG_ERR_FORMAT, $PROTO" |
---|
[d2f28cf] | 157 | exit $? |
---|
| 158 | ;; |
---|
| 159 | esac |
---|
| 160 | ;; |
---|
| 161 | *) # Error: repositorio desconocido. |
---|
[64cf3d3] | 162 | ogRaiseError session $OG_ERR_FORMAT "$MSG_ERR_FORMAT, $REPO" |
---|
[30ad471] | 163 | exit $? |
---|
[d2f28cf] | 164 | ;; |
---|
| 165 | esac |
---|
| 166 | |
---|
| 167 | TIME3=$SECONDS |
---|
| 168 | |
---|
[b8969db] | 169 | # Obtener parámetros de restauración. |
---|
[d2f28cf] | 170 | case "$NEXTOPERATION" in |
---|
| 171 | CACHE) |
---|
[b8969db] | 172 | PARAMS="CACHE $IMGNAME $DISK $PART" ;; |
---|
[d2f28cf] | 173 | UNICAST) |
---|
[fe6843b] | 174 | PARAMS="$REPO $IMGNAME $DISK $PART" ;; |
---|
[d2f28cf] | 175 | MULTICAST) |
---|
[fe6843b] | 176 | PARAMS="$REPO $IMGNAME $DISK $PART $PROTO $PROTOOPT" ;; |
---|
[d2f28cf] | 177 | esac |
---|
[b8969db] | 178 | |
---|
| 179 | # Si existe, ejecuta script personalizado "restoreImageCustom"; si no, llama al genérico "restoreImage". |
---|
| 180 | if which restoreImageCustom &>/dev/null; then |
---|
| 181 | ogEcho log session "[55] $MSG_HELP_ogRestoreImage: restoreImageCustom $PARAMS" |
---|
| 182 | restoreImageCustom $PARAMS |
---|
| 183 | else |
---|
| 184 | ogEcho log session "[55] $MSG_HELP_ogRestoreImage: restoreImage $PARAMS" |
---|
| 185 | restoreImage $PARAMS |
---|
| 186 | fi |
---|
| 187 | RETVAL=$? |
---|
| 188 | |
---|
| 189 | # Mostrar resultados. |
---|
[4fcbcc8] | 190 | RESUMERESTOREIMAGE=$(grep -m 1 "Total Time:" $OGLOGCOMMAND) |
---|
[fe10bff] | 191 | ogEcho log session " [ ] $RESUMERESTOREIMAGE " |
---|
[4fcbcc8] | 192 | # Si la transferencia ha dado error me salgo. |
---|
| 193 | if [ $RETVAL -ne 0 ] ; then |
---|
[fe10bff] | 194 | ogRaiseError session $OG_ERR_IMAGE "$REPO $IMGNAME" 2>&1 |
---|
| 195 | # Muestro registro de fin de ejecución si no viene de Ejecutar Script |
---|
| 196 | [ "$(ogGetCaller)" == "EjecutarScript" ] || ogEcho log session "$MSG_INTERFACE_END $OG_ERR_IMAGE" |
---|
| 197 | exit $OG_ERR_IMAGE |
---|
[4fcbcc8] | 198 | fi |
---|
[d2f28cf] | 199 | TIME3=$[SECONDS-TIME3] |
---|
[e7e3140] | 200 | ogEcho log session " [ ] $MSG_SCRIPTS_TIME_PARTIAL : $[TIME3/60]m $[TIME3%60]s" |
---|
[d2f28cf] | 201 | |
---|
[b8969db] | 202 | # Si existe, ejecuta script personalizado de postconfiguración "configureOsCustom"; si no, llama al genérico "configureOs". |
---|
[d2f28cf] | 203 | if which configureOsCustom &>/dev/null; then |
---|
[e7e3140] | 204 | ogEcho log session "[90] configureOsCustom" |
---|
[a012113] | 205 | configureOsCustom "$DISK" "$PART" "$REPO" "$IMGNAME" |
---|
[d2f28cf] | 206 | else |
---|
[e7e3140] | 207 | ogEcho log session "[90] $MSG_SCRIPTS_OS_CONFIGURE " |
---|
[d2f28cf] | 208 | configureOs "$DISK" "$PART" |
---|
[5c23e04] | 209 | fi |
---|
[d2f28cf] | 210 | |
---|
[5c23e04] | 211 | TIME=$[SECONDS-TIME1] |
---|
[e7e3140] | 212 | ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s" |
---|
[5c23e04] | 213 | |
---|
[d2f28cf] | 214 | # Registro de fin de ejecución |
---|
[4fcbcc8] | 215 | # Si se ha llamado desde ejecutar script no lo muestro para no repetir. |
---|
[6dc82b60] | 216 | if [ "$(ogGetCaller)" != "EjecutarScript" ] ; then |
---|
[fe10bff] | 217 | ogEcho log session "$MSG_INTERFACE_END $RETVAL" |
---|
| 218 | exit $RETVAL |
---|
[4fcbcc8] | 219 | fi |
---|
[5c23e04] | 220 | |
---|