diff options
-rwxr-xr-x | client/engine/Net.lib | 6 | ||||
-rwxr-xr-x | client/engine/Rsync.lib | 2 | ||||
-rwxr-xr-x | client/shared/scripts/createBaseImage | 54 | ||||
-rwxr-xr-x | client/shared/scripts/createDiffImage | 81 | ||||
-rwxr-xr-x | client/shared/scripts/restoreBaseImage | 46 | ||||
-rwxr-xr-x | client/shared/scripts/restoreDiffImage | 43 |
6 files changed, 148 insertions, 84 deletions
diff --git a/client/engine/Net.lib b/client/engine/Net.lib index 219d6d46..d8f272b1 100755 --- a/client/engine/Net.lib +++ b/client/engine/Net.lib @@ -37,6 +37,9 @@ if [ $# -lt 1 ]; then fi +# Opciones de montaje: lectura o escritura +mount |grep "ogimages.*rw," &>/dev/null && RW=",rw" || RW=",ro" + # Si REPO tomamos el repositorio y la unidad organizativa actual REPO=$(ogGetRepoIp) OGUNIT="$(df | awk -F " " '/ogimages/ {sub("//.*/ogimages","",$1); sub("/","",$1); print $1}')" @@ -53,9 +56,6 @@ umount $OGIMG [ "$2" == "" ] && SRCIMG="ogimages" || SRCIMG="ogimages/$2" eval $(grep "OPTIONS=" /scripts/ogfunctions) -# Opciones de montaje: lectura o escritura -mount |grep "ogimages.*rw," &>/dev/null && RW=",rw" || RW=",ro" - ogEcho session log "$MSG_HELP_ogChangeRepo $NEWREPO ${2%/}" ogConnect $NEWREPO $ogprotocol $SRCIMG $OGIMG $RW diff --git a/client/engine/Rsync.lib b/client/engine/Rsync.lib index 83140419..a68ea382 100755 --- a/client/engine/Rsync.lib +++ b/client/engine/Rsync.lib @@ -318,7 +318,7 @@ IMGLN="ogimg.ln" IMGINFO="ogimg.info" # Copiamos informacion de la imagen a /tmp (para basicas) -[ -r $DEST/$IMGACL ] && cp $DEST/ogimg.* /tmp +[ -r $DEST/$IMGINFO ] && cp $DEST/ogimg.* /tmp #Creamos o modificamos los enlaces. # La imagen diferencial tiene ogimg.ln diff --git a/client/shared/scripts/createBaseImage b/client/shared/scripts/createBaseImage index c367e930..f7ef2a58 100755 --- a/client/shared/scripts/createBaseImage +++ b/client/shared/scripts/createBaseImage @@ -6,7 +6,7 @@ #@brief Se usa como base para el programa de creación de imágenes de OpenGnsys Admin). #@param 1 disco #@param 2 particion -#@param 3 REPO|CACHE +#@param 3 REPO|CACHE|IPREPO #@param 4 imagen #@return #@exception OG_ERR_FORMAT # 1 formato incorrecto. @@ -25,15 +25,18 @@ #@version 1.1.0 - Se muestra el espacio necesario para alojar la imagen y el disponible (ticket #771) #@author Irina Gomez - ETSII Universidad de Sevilla #@date 2017-03-28 +#@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 $1 $2 $IMGFILE" 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=$? if [ $exit_status -ne 4 ]; then - ogUnlockImage "$3" "/$4.$IMGEXT" + ogUnlockImage "$IMGFILE" ogUnlock $1 $2 fi exit $exit_status @@ -62,15 +65,26 @@ ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*" # Valores por defecto en etc/engine.cfg IMGEXT=${IMGEXT:-"img"} -REPOIP=$(ogGetRepoIp) - +REPO="${3^^}" +# 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'; echo $?) + REPO="REPO" +fi # Comprobamos si la imagen o la particion estan bloqueada: -ogIsImageLocked "$3" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $4.$IMGEXT"; echo $?) +ogIsImageLocked "$REPO" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$REPO $4.$IMGEXT"; echo $?) ogIsLocked "$1" "$2" && exit $(ogRaiseError session $OG_ERR_LOCKED "$1 $2"; echo $?) # Si el repositorio es CACHE comprobamos que exista -if [ "$3" == "CACHE" -o "$3" == "cache" ]; then +if [ "$REPO" == "CACHE" -o "$REPO" == "cache" ]; then ! ogFindCache >/dev/null && exit $(ogRaiseError session $OG_ERR_NOTCACHE "CACHE "; echo $?) fi @@ -90,25 +104,25 @@ ORIG=$(ogMount $1 $2) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2" ; ogCleanOs $1 $2 #Comprobar espacio que requerira la imagen para ser almacenada -read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$3" "$4" SYNC) +read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$REPO" "$4" SYNC) ogEcho log session "[16] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED $SIZEFREE" -[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$3"; echo $?) +[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$REPO"; echo $?) -IMGDIR="$(ogGetParentPath "$3" "/$4")" -IMGFILE=${IMGDIR[$3]}/$(basename "/$4").$IMGEXT +IMGDIR="$(ogGetParentPath "$REPO" "/$4")" +IMGFILE=${IMGDIR}/$(basename "/$4").$IMGEXT # Crear la imagen. echo " " > $OGLOGCOMMAND TIME2=$SECONDS -ogEcho log session "[40] $MSG_HELP_ogCreateImage $1 $2 $3 $4 " +ogEcho log session "[40] $MSG_HELP_ogCreateImage $1 $2 $REPO $4 " # Si existe el fichero de la imagen se hace copia de seguridad y se redimensiona, si no existe se crea. # Bloqueo la imagen. Si esta en modo lectura dara error y nos salimos ogEcho log session "[50] $MSG_HELP_ogCreateFileImage." -ogLockImage "$3" "/$4.$IMGEXT" || exit $? -ogCreateFileImage $3 "$4" $IMGEXT $SIZEREQUIRED +ogLockImage "$REPO" "/$4.$IMGEXT" || exit $? +ogCreateFileImage $REPO "$4" $IMGEXT $SIZEREQUIRED # Creamos la lista del contenido y lo situamos en la particion a copiar. ogEcho log session "[60] $MSG_HELP_ogCreateInfoImage" @@ -118,11 +132,11 @@ TIMEAUX3=$[SECONDS-TIME2] ogEcho log session " $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX3/60]m $[TIMEAUX3%60]s" # Esperamos que el servidor termine de crear y montar la imagen -ogWaitSyncImage "$3" "$4" $IMGEXT "mounted" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?) +ogWaitSyncImage "$REPO" "$4" $IMGEXT "mounted" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $4 $IMGEXT: time_out."; echo $?) # Sincronizamos los datos de la particion con la imagen. ogEcho log session "[70] $MSG_HELP_ogSyncCreate." -ogSyncCreate $1 $2 $3 "$4" $IMGEXT +ogSyncCreate $1 $2 $REPO "$4" $IMGEXT RETVAL=$? [ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING" @@ -130,16 +144,16 @@ TIMEAUX5=$[SECONDS-TIMEAUX3] ogEcho log session " $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX5/60]m $[TIMEAUX5%60]s" # Reducimos la imagen: solo para kernel <= 3.7, imagenes con FS ext4. (Desmonta y desbloquea la imagen) -ogEcho log session "[80] $MSG_HELP_ogReduceImage: $3 /$4.$IMGEXT" -ogReduceImage $3 "$4" $IMGEXT +ogEcho log session "[80] $MSG_HELP_ogReduceImage: $REPO /$4.$IMGEXT" +ogReduceImage $REPO "$4" $IMGEXT # Esperamos que el servidor termine de reducir la imagen -ogWaitSyncImage "$3" "$4" $IMGEXT "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?) +ogWaitSyncImage "$REPO" "$4" $IMGEXT "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $4 $IMGEXT: time_out."; echo $?) echo " " > $OGLOGCOMMAND sleep 2 # Comprobamos que la imagen esta bien detectacdo que es un sistema de ficheros. ogEcho log session "[95] $MSG_HELP_ogCheckSyncImage" -ogCheckSyncImage $3 "$4" "img" || exit $(ogRaiseError session $OG_ERR_IMAGE "$3 $4 img" ; echo $?) +ogCheckSyncImage $REPO "$4" "img" || exit $(ogRaiseError session $OG_ERR_IMAGE "$REPO $4 img" ; echo $?) #resumen de la operacion IMGSIZE=$(ls -l --block-size=1024 "$IMGFILE" | cut -f5 -d" ") diff --git a/client/shared/scripts/createDiffImage b/client/shared/scripts/createDiffImage index 79ee9726..ddee5c7b 100755 --- a/client/shared/scripts/createDiffImage +++ b/client/shared/scripts/createDiffImage @@ -28,16 +28,19 @@ #@version 1.1.0 - Se muestra el espacio necesario para alojar la imagen y el disponible (ticket #771) #@author Irina Gomez - ETSII Universidad de Sevilla #@date 2017-03-28 +#@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\" \"$5\"" 1 2 3 6 9 14 15 EXIT +trap "onexit $1 $2 \"$4\" \"$5\"" 1 2 3 6 9 14 15 EXIT function onexit() { local exit_status=$? - ogUnmountImage $3 "$5" $DIFFTYPE &>/dev/null - ogUnmountImage $3 "$4" $IMGEXT &>/dev/null + ogUnmountImage $REPO "$5" $DIFFTYPE &>/dev/null + ogUnmountImage $REPO "$3" $IMGEXT &>/dev/null if [ $exit_status -ne 4 ]; then - ogUnlockImage "$3" "/$4.$IMGEXT" &>/dev/null - ogUnlockImage "$3" "/$5.$DIFFEXT" &>/dev/null + ogUnlockImage "$IMGFILE" &>/dev/null + ogUnlockImage "$DIFFFILE" &>/dev/null ogUnlock $1 $2 &>/dev/null fi exit $exit_status @@ -59,33 +62,45 @@ fi [ $# -lt 5 ] && exit $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE base_image diff_image"; echo $?) -# Valores por defecto en etc/engine.cfg -IMGEXT="img" -DIFFEXT="img.diff" -DIFFTYPE="diff" -REPOIP=$(ogGetRepoIp) - # Limpiamos los archivo de log echo -n "" >$OGLOGCOMMAND [ "$(ogGetCaller)" == "RestaurarSoftIncremental" ] || echo -n "" > $OGLOGSESSION ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*" +# Valores por defecto en etc/engine.cfg +IMGEXT="img" +DIFFEXT="img.diff" +DIFFTYPE="diff" +REPO="${3^^}" +# 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'; echo $?) + REPO="REPO" +fi + # Comprobamos si la imagen diferencial o la particion estan bloqueada: -ogIsImageLocked "$3" "$5.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $5.$DIFFEXT"; echo $?) +ogIsImageLocked "$REPO" "$5.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$REPO $5.$DIFFEXT"; echo $?) ogIsLocked "$1" "$2" && exit $(ogRaiseError session $OG_ERR_LOCKED "$1 $2"; echo $?) # Comprobar si la imagen completa existe. -IMGFILE="$(ogGetPath "$3" "$4.$IMGEXT")" -[ -n "$IMGFILE" ] || exit $(ogRaiseError session $OG_ERR_NOTFOUND "$3 $4.$IMGEXT"; echo $?) +IMGFILE="$(ogGetPath "$REPO" "$4.$IMGEXT")" +[ -n "$IMGFILE" ] || exit $(ogRaiseError session $OG_ERR_NOTFOUND "$REPO $4.$IMGEXT"; echo $?) # Comprobar que la imagen completa es sincronizable -ogIsSyncImage "$3" "$4" "img" || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$3 $4"; echo $?) +ogIsSyncImage "$REPO" "$4" "img" || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$REPO $4"; echo $?) # Comprobar que no está bloqueada -ogIsImageLocked "$3" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $4.$IMGEXT"; echo $?) +ogIsImageLocked "$REPO" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$REPO $4.$IMGEXT"; echo $?) # Si el repositorio es CACHE comprobamos que exista -if [ "$3" == "CACHE" -o "$3" == "cache" ]; then +if [ "$REPO" == "CACHE" -o "$REPO" == "cache" ]; then ! ogFindCache >/dev/null && exit $(ogRaiseError session $OG_ERR_NOTCACHE "CACHE "; echo $?) fi @@ -96,12 +111,12 @@ PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError session $OG_ERR #Comprobamos que la partición se puede montar. ORIG=$(ogMount $1 $2) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2"; echo $?) -DIFFDIR="$(ogGetParentPath "$3" "/$5")" +DIFFDIR="$(ogGetParentPath "$REPO" "/$5")" DIFFFILE="$DIFFDIR/$5.$DIFFEXT" # Bloqueo las imagenes -> Si no hay acceso de escritura dara error y nos saldremos. -ogLockImage "$3" "/$4.$IMGEXT" || exit $? -ogLockImage "$3" "/$5.$DIFFEXT" || exit $? +ogLockImage "$REPO" "/$4.$IMGEXT" || exit $? +ogLockImage "$REPO" "/$5.$DIFFEXT" || exit $? # Comprobar consistencia del sistema de archivos. echo " " > $OGLOGCOMMAND @@ -116,25 +131,25 @@ ogCleanOs $1 $2 # Crear la imagen. echo " " > $OGLOGCOMMAND TIME2=$SECONDS -ogEcho log session "[40] $MSG_HELP_createDiffImage: $1 $2 $3 $4" +ogEcho log session "[40] $MSG_HELP_createDiffImage: $1 $2 $REPO $4" # Creamos la lista del contenido y lo situamos en la particion a copiar. # Montamos imagen completa (con la que vamos a comparar) -ogMountImage $3 "$4" $IMGEXT >/dev/null +ogMountImage $REPO "$4" $IMGEXT >/dev/null # Comprobar que la imagen completa se ha montado -ogWaitSyncImage $3 "$4" $IMGEXT "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?) +ogWaitSyncImage $REPO "$4" $IMGEXT "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $4 $IMGEXT: time_out."; echo $?) # Creamos la informacion de la imagen. ogEcho log session "[45] $MSG_HELP_ogCreateInfoImage " -ogCreateInfoImage $1 $2 $3 "$4" "${DIFFTYPE}" +ogCreateInfoImage $1 $2 $REPO "$4" "${DIFFTYPE}" [ $? -eq $OG_ERR_NOTDIFFERENT ] && exit $(ogRaiseError session $OG_ERR_NOTDIFFERENT; echo $?) #Comprobar espacio que requerira la imagen para ser almacenada -read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$3" "$5" DIFF) +read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$REPO" "$5" DIFF) ogEcho log session "[50] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED $SIZEFREE" -[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$3"; echo $?) +[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$REPO"; echo $?) #Calculamos el tamaño de la imagen: ogMount $1 $2 >/dev/null @@ -150,31 +165,31 @@ sed -i s/SIZEDATA/"$SIZEDATA"/g /tmp/ogimg.info # Creamos o redimensionamos la imagen ogEcho log session "[60] $MSG_HELP_ogCreateFileImage." -ogCreateFileImage $3 "$5" $DIFFTYPE $SIZEREQUIRED +ogCreateFileImage $REPO "$5" $DIFFTYPE $SIZEREQUIRED # Esperamos que se monte la imagen despues de crarla en el servidor -ogWaitSyncImage "$3" "$5" "$DIFFTYPE" "mounted" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $5 $DIFFTYPE: time_out."; echo $?) +ogWaitSyncImage "$REPO" "$5" "$DIFFTYPE" "mounted" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $5 $DIFFTYPE: time_out."; echo $?) ogEcho log session "[70] $MSG_HELP_ogSyncCreate" # Copio los datos a la imagen diferecial : -ogSyncCreate $1 $2 $3 "$5" $DIFFTYPE +ogSyncCreate $1 $2 $REPO "$5" $DIFFTYPE RETVAL=$? [ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING" TIMEAUX6=$[SECONDS-TIMEAUX5] ogEcho log session " $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX6/60]m $[TIMEAUX6%60]s" # Reducimos la imagen diferencial -> solo para kernel <= 3.7, imagenes con FS ext4 -ogEcho log session "[80] $MSG_HELP_ogReduceImage: $3 /$4.$IMGEXT" -ogReduceImage $3 "$5" $DIFFTYPE +ogEcho log session "[80] $MSG_HELP_ogReduceImage: $REPO /$4.$IMGEXT" +ogReduceImage $REPO "$5" $DIFFTYPE # Esperamos que el servidor termine de reducir la imagen -ogWaitSyncImage "$3" "$5" $DIFFTYPE "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?) +ogWaitSyncImage "$REPO" "$5" $DIFFTYPE "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $4 $IMGEXT: time_out."; echo $?) # TODO: necesaria funcion que espere a que se reduzca la imagen para continuar el script echo " " > $OGLOGCOMMAND sleep 2 # Comprobamos que la imagen esta bien ogEcho log session "[95] $MSG_HELP_ogCheckSyncImage" -ogCheckSyncImage $3 "$5" diff || exit $(ogRaiseError session $OG_ERR_IMAGE "$3 $5 diff"; echo $?) +ogCheckSyncImage $REPO "$5" diff || exit $(ogRaiseError session $OG_ERR_IMAGE "$REPO $5 diff"; echo $?) #resumen de la operacion IMGSIZE=$(ls -l --block-size=1024 "${DIFFFILE}"| cut -f5 -d" ") 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 diff --git a/client/shared/scripts/restoreDiffImage b/client/shared/scripts/restoreDiffImage index 7d16ef90..4de5f31a 100755 --- a/client/shared/scripts/restoreDiffImage +++ b/client/shared/scripts/restoreDiffImage @@ -24,14 +24,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 $5" 1 2 3 6 9 14 15 EXIT +trap "onexit $REPO \"$2\" \"$3\" $4 $5" 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" "$3" "$DIFFTYPE" &>/dev/null + ogUnmountImage "$REPO" "$3" "$DIFFTYPE" &>/dev/null [ $exit_status -ne 4 ] && ogUnlock $4 $5 &>/dev/null exit $exit_status } @@ -59,27 +62,41 @@ ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*" # Procesar parámetros de entrada DIFFTYPE="diff" DIFFEXT="img.diff" +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 + REPODIFFFILE="$(ogGetPath "REPO" "$3.$DIFFEXT")" [ -n "$REPODIFFFILE" ] || exit $(ogRaiseError session $OG_ERR_NOTFOUND "REPO $3.$DIFFEXT";echo $?) # Comprobamos si la imagen o la particion estan bloqueada: -ogIsImageLocked "$1" "$3.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$1 $3.$DIFFEXT";echo $?) +ogIsImageLocked "$REPO" "$3.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$REPO $3.$DIFFEXT";echo $?) ogIsLocked "$4" "$5" && exit $(ogRaiseError session $OG_ERR_LOCKED "$4 $5";echo $?) -PART=$(ogDiskToDev "$4" "$5" 2>/dev/null ) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $3";echo $?) +PART=$(ogDiskToDev "$4" "$5" 2>/dev/null ) || exit $(ogRaiseError session $OG_ERR_PARTITION "$REPO $3";echo $?) # Carga del configurador del engine [ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg # Comprobar que es sincronizable -ogIsSyncImage REPO "$3" diff || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$1 $3";echo $?) +ogIsSyncImage REPO "$3" diff || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$REPO $3";echo $?) # Restauramos la imagen Basica. -restoreBaseImage $1 "$2" "$4" "$5" "$6" "$7" +restoreBaseImage $REPO "$2" "$4" "$5" "$6" "$7" PROTO=${6:-"UNICAST"} -if [ "$1" == "CACHE" -o "$1" == "cache" ]; then +if [ "$REPO" == "CACHE" -o "$REPO" == "cache" ]; then ogEcho log session "[10] $MSG_HELP_updateCache." ogEcho log session " updateCache REPO" "/$3.$DIFFEXT" "$PROTO" "$7" updateCache REPO "/$3.$DIFFEXT" "$PROTO" "$7" @@ -101,20 +118,20 @@ TIME2=$SECONDS ogEcho log session "[40] $MSG_RESTORE $PART" # Montamos la diferencial -ogMountImage "$1" "$3" "$DIFFTYPE" &>/dev/null +ogMountImage "$REPO" "$3" "$DIFFTYPE" &>/dev/null # Comprobar que la imagen diferencial se ha montado -ogWaitSyncImage "$1" "$3" "$DIFFTYPE" "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$1 $3 $DIFFTYPE: time_out $TIMEAUX seg.";echo $?) +ogWaitSyncImage "$REPO" "$3" "$DIFFTYPE" "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $3 $DIFFTYPE: time_out $TIMEAUX seg.";echo $?) ogMount $4 $5 >/dev/null ogLock $4 $5 # Sincronizamos la partición con la imagen. -ogEcho log session "[60] $MSG_HELP_ogSyncRestore: $1 $3 $DIFFTYPE $4 $5" -ogSyncRestore "$1" "$3" "$DIFFTYPE" $4 $5 +ogEcho log session "[60] $MSG_HELP_ogSyncRestore: $REPO $3 $DIFFTYPE $4 $5" +ogSyncRestore "$REPO" "$3" "$DIFFTYPE" $4 $5 RETVAL=$? [ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING" # Desmontamos la imagen -ogUnmountImage "$1" "$3" "$DIFFTYPE" +ogUnmountImage "$REPO" "$3" "$DIFFTYPE" ogUnlock $4 $5 TIMEAUX2=$[SECONDS-TIME2] @@ -130,7 +147,7 @@ ogEcho log session " $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL : $[T # Llamar al script de post-configuración del sistema operativo. if which configureOsCustom &>/dev/null; then ogEcho log session "[90] configureOsCustom" - configureOsCustom "$4" "$5" "$1" "$2" + configureOsCustom "$4" "$5" "$REPO" "$2" else ogEcho log session "[90] $MSG_HELP_configureOs." configureOs $4 $5 |