summaryrefslogtreecommitdiffstats
path: root/client/shared/scripts/restoreBaseImage
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2018-11-26 12:52:31 +0100
committerRamón M. Gómez <ramongomez@us.es>2018-11-26 12:52:31 +0100
commit51e67a2cc790796cf3e6832d430c4473e6377ed8 (patch)
tree41e24b0c7e74d95f55dcaca94f778f008774bb4f /client/shared/scripts/restoreBaseImage
parent910a4c358af0191b5c83f45f93a444b60a633fff (diff)
parent518d4d84f755185f224c82d5cc3f49b350af4b05 (diff)
#794: Fast-forward.
Diffstat (limited to 'client/shared/scripts/restoreBaseImage')
-rwxr-xr-xclient/shared/scripts/restoreBaseImage46
1 files changed, 32 insertions, 14 deletions
diff --git a/client/shared/scripts/restoreBaseImage b/client/shared/scripts/restoreBaseImage
index 0b291518..046c4658 100755
--- a/client/shared/scripts/restoreBaseImage
+++ b/client/shared/scripts/restoreBaseImage
@@ -3,7 +3,7 @@
# restoreBaseImage
#@brief Script de ejemplo para restaurar una imagen
#@brief Se usa como base para el programa de restauración de imágenes de OpenGnsys Admin).
-#@param 1 REPO|CACHE
+#@param 1 REPO|CACHE|IPREPO
#@param 2 imagen
#@param 3 disco
#@param 4 particion
@@ -22,14 +22,17 @@
#@version 1.0 - restauración de imagen con sincronizacion.
#@author
#@date 2012-12-04
+#@version 1.1.1 - Varios repositorios para un mismo cliente (ticket #679).
+#@author Irina Gomez - ETSII Universidad de Sevilla
+#@date 2018/11/06
#*/ ##
-trap "onexit $1 \"$2\" $3 $4" 1 2 3 6 9 14 15 EXIT
+trap "onexit $REPO \"$2\" $3 $4" 1 2 3 6 9 14 15 EXIT
# Si salimos con error demontamos la imagen y desbloqueamos la imagen y la particion
function onexit() {
local exit_status=$?
- ogUnmountImage "$1" "$2" "$IMGEXT" &>/dev/null
+ ogUnmountImage "$REPO" "$2" "$IMGEXT" &>/dev/null
[ $exit_status -ne 4 ] && ogUnlock $3 $4 &>/dev/null
exit $exit_status
}
@@ -54,6 +57,21 @@ fi
[ $# -lt 4 ] && exit $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]"; echo $?)
+# Procesar parámetros de entrada
+REPO="${1^^}"
+# No permite directorios diferentes para OU
+OGUNIT=""
+
+# Si es una ip y es igual a la del equipo restaura desde cache
+[ "$REPO" == "$(ogGetIpAddress)" ] && REPO="CACHE"
+# Si es una ip y es distinta a la del recurso samba cambiamos de REPO.
+ogCheckIpAddress $REPO
+if [ $? == 0 -o $REPO == "REPO" ] ; then
+ # Si falla el cambio -> salimos con error repositorio no valido
+ ogChangeRepo $REPO ${OGUNIT%/} || exit $(ogRaiseError $OG_ERR_NOTFOUND '$REPO $OGUNIT'; echo $?)
+ REPO="REPO"
+fi
+
# Carga del configurador del engine
[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
@@ -62,17 +80,17 @@ REPOFILE="$(ogGetPath "REPO" "$2.$IMGEXT")"
[ -n "$REPOFILE" ] || exit $(ogRaiseError session $OG_ERR_NOTFOUND "REPO, $2.$IMGEXT"; echo $?)
# Comprobar que es sincronizable (con REPO)
-ogIsSyncImage REPO "$2" $IMGEXT || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$1 $2"; echo $?)
+ogIsSyncImage REPO "$2" $IMGEXT || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$REPO $2"; echo $?)
IMGEXT="img"
# Comprobamos si la imagen o la particion estan bloqueada:
-ogIsImageLocked "REPO" "$2.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$1 $2.$IMGEXT"; echo $?)
+ogIsImageLocked "REPO" "$2.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$REPO $2.$IMGEXT"; echo $?)
ogIsLocked "$3" "$4" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $4"; echo $?)
# Detectamos el sistema de ficheros de la imagen
# TODO ogGetImageInfo
DIRMOUNT=$(ogMountImage "REPO" "$2")
-ogWaitSyncImage "REPO" "$2" "$IMGEXT" "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$1 $2 $IMGEXT: time_out."; echo $?)
+ogWaitSyncImage "REPO" "$2" "$IMGEXT" "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $2 $IMGEXT: time_out."; echo $?)
IMGFSTYPE=$(head -1 $DIRMOUNT/ogimg.info |cut -d: -f3)
# Comprobamos si el sistema de ficheros se puede montar
@@ -89,7 +107,7 @@ fi
PROTO=${5:-"UNICAST"}
-if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
+if [ "$REPO" == "CACHE" -o "$REPO" == "cache" ]; then
# Las imagenes sincronizables aunque sean iguales no tienen el mismo sum.
# Sincronizamos si existe el fichero y si no usamos updateCache.
ogEcho log session "[10] $MSG_SCRIPTS_TASK_START updateCache REPO $2.$IMGEXT $PROTO $6"
@@ -107,20 +125,20 @@ if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
ogEcho log session " $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX1/60]m $[TIMEAUX1%60]s"
# Montamos la imagen de cache
- ogMountImage "$1" "$2" >/dev/null
- ogWaitSyncImage "$1" "$2" "$IMGEXT" "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$1 $2 $IMGEXT: time_out."; echo $?)
+ ogMountImage "$REPO" "$2" >/dev/null
+ ogWaitSyncImage "$REPO" "$2" "$IMGEXT" "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $2 $IMGEXT: time_out."; echo $?)
fi
TIME2=$SECONDS
# Restaurar la imagen.
-ogEcho log session "[40] $MSG_HELP_ogRestoreImage: $1 $2 $3 $4"
+ogEcho log session "[40] $MSG_HELP_ogRestoreImage: $REPO $2 $3 $4"
ogLock $3 $4
# Sincronizamos la partición con la imagen.
-ogEcho log session "[60] $MSG_HELP_ogSyncRestore: $1 $2 $IMGEXT $3 $4"
-ogSyncRestore "$1" "$2" "$IMGEXT" $3 $4
+ogEcho log session "[60] $MSG_HELP_ogSyncRestore: $REPO $2 $IMGEXT $3 $4"
+ogSyncRestore "$REPO" "$2" "$IMGEXT" $3 $4
RETVAL=$?
[ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING"
@@ -128,7 +146,7 @@ TIMEAUX2=$[SECONDS-TIME2]
ogEcho log session " $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX2/60]m $[TIMEAUX2%60]s"
# Desmontamos imagen basica.
-ogUnmountImage "$1" "$2" "$IMGEXT"
+ogUnmountImage "$REPO" "$2" "$IMGEXT"
# Restableciendo acl
ogUnlock $3 $4
@@ -141,7 +159,7 @@ if [ "$(ogGetCaller)" != "restoreDiffImage" ];then
ogExecAndLog command ogRestoreAclImage $3 $4
if which configureOsCustom &>/dev/null; then
ogEcho log session "[90] configureOsCustom"
- configureOsCustom "$3" "$4" "$1" "$2"
+ configureOsCustom "$3" "$4" "$REPO" "$2"
else
ogEcho log session "[90] $MSG_HELP_configureOs"
configureOs $3 $4