summaryrefslogtreecommitdiffstats
path: root/client/engine/Image.lib
diff options
context:
space:
mode:
Diffstat (limited to 'client/engine/Image.lib')
-rwxr-xr-xclient/engine/Image.lib92
1 files changed, 84 insertions, 8 deletions
diff --git a/client/engine/Image.lib b/client/engine/Image.lib
index 941deb91..728eb24a 100755
--- a/client/engine/Image.lib
+++ b/client/engine/Image.lib
@@ -102,6 +102,48 @@ esac
[ -n "$PARAM1" ] && echo "$PARAM1 $PARAM2 $PARAM3 $IMGFILE"
}
+function ogTiptorrentGet ()
+{
+local MAXTRIES err
+i=0
+MAXTRIES=3
+while [ "$i" -lt $MAXTRIES ]
+do
+ wget --spider -q "$ogrepo:9999/$1" && break
+ i=$(( i + 1 ))
+done
+if [ $i -eq 3 ]; then
+ ogRaiseError "$OG_ERR_NOTFOUND" "Error checking $1"
+ return $?
+fi
+pushd /opt/opengnsys/cache/opt/opengnsys/images > /dev/null || return 1
+/opt/opengnsys/bin/tiptorrent-client "$ogrepo" "$1" > /dev/null
+err=$?
+popd > /dev/null || return 1
+if [ $err -ne 0 ]; then
+ ogRaiseError "$OG_ERR_NOTFOUND" "Error downloading $1 image, tiptorrent-client failed. See /var/log/syslog on the client for details."
+fi
+return $err
+}
+
+function ogTiptorrentGetToCache ()
+{
+local MAXTRIES MD5FILE MD5IMG
+if ! wget -qO "$1".full.sum "$ogrepo:9999/$2.full.sum"; then
+ ogRaiseError "$OG_ERR_NOTFOUND" "Error downloading $2 checksum"
+ return $?
+fi
+MD5FILE=$(cat "$1".full.sum)
+if ! ogTiptorrentGet "$2"; then
+ return 1;
+fi
+MD5IMG=$(md5sum "$IMGPATH" | cut -f1 -d " ")
+if [ "$MD5IMG" != "$MD5FILE" ]; then
+ ogRaiseError "$OG_ERR_NOTFOUND" "Error downloading $2, checksum mismatch"
+ return $?
+fi
+return 0
+}
#/**
# ogRestoreImageSyntax path_filename path_device [str_tools] [str_compressionlevel]
@@ -121,7 +163,8 @@ esac
#*/ ##
function ogRestoreImageSyntax ()
{
-local TOOL COMPRESSOR LEVEL PART IMGFILE FILEHEAD INFOIMG
+local TOOL COMPRESSOR LEVEL PART IMGFILE FILEHEAD INFOIMG IMGPATH IMGCACHEDIR
+local MD5FILE MD5WGET
# Si se solicita, mostrar ayuda.
@@ -131,8 +174,8 @@ if [ "$*" == "help" ]; then
return
fi
-# Error si no se reciben entre 2 y 4 parámetros.
-[ $# -ge 2 -a $# -le 4 ] || ogRaiseError $OG_ERR_FORMAT "$*" || return $?
+# Error si no se reciben entre 2 y 5 parámetros.
+[ $# -ge 2 -a $# -le 5 ] || ogRaiseError $OG_ERR_FORMAT "$*" || return $?
# controlamos que el parametro 1 (imagen) es tipo file.
[ -f $1 ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
@@ -147,9 +190,8 @@ if [ "$#" -eq 2 ]; then
ogRestoreImageSyntax $IMGFILE $PART $TOOL $COMPRESSOR
fi
-
# Si cuatro parametros genera sintaxis
-if [ "$#" -eq 4 ]; then
+if [ "$#" -eq 4 ] || [ "$#" -eq 5 ]; then
IMGFILE=$1
PART=$2
# comprobamos parametro herramienta compresion.
@@ -198,7 +240,35 @@ if [ "$#" -eq 4 ]; then
;;
esac
- echo "$COMPRESSOR $IMGFILE $MBUFFER $TOOL"
+ if [ "$5" == "true" ]; then
+ IMGFILE=${1/\/opt\/opengnsys\/images\//}
+ if ogFindCache &>/dev/null; then
+ IMGCACHEDIR=$(ogGetMountPoint $(ogFindCache))/opt/opengnsys/images
+ IMGPATH="$IMGCACHEDIR/$IMGFILE"
+ if [ -f "$IMGPATH" ]; then
+ MD5FILE=$(md5sum "$IMGPATH" | cut -f1 -d " ")
+ MD5WGET=$(wget -qO - "$ogrepo:9999/$IMGFILE.full.sum")
+ if [ "$MD5FILE" != "$MD5WGET" ]; then
+ ogTiptorrentGetToCache "$IMGPATH" "$IMGFILE"
+ fi
+ else
+ mkdir -p "$IMGCACHEDIR"
+ ogTiptorrentGetToCache "$IMGPATH" "$IMGFILE"
+ fi
+ if [ $? -ne 0 ]; then
+ ogRaiseError "$OG_ERR_NOTFOUND" "Failed tiptorrent to cache $TOOL"
+ return $?
+ fi
+ CAT="cat $IMGPATH |"
+ COMPRESSOR="$COMPRESSOR -"
+ echo "$CAT $COMPRESSOR $MBUFFER $TOOL"
+ else
+ ogRaiseError "$OG_ERR_NOTFOUND" "Tiptorrent needs cache $TOOL"
+ return $?
+ fi
+ else
+ echo "$COMPRESSOR $IMGFILE $MBUFFER $TOOL"
+ fi
fi
}
@@ -363,6 +433,7 @@ ERRCODE=$?
if [ $ERRCODE == 0 ]; then
echo "$(ogGetImageInfo $IMGFILE):$(ogGetHostname)" > $IMGFILE.info
cp -f $IMGFILE.info /tmp/image.info
+ md5sum "$IMGFILE" | cut -f1 -d " " > "$IMGFILE".full.sum
else
ogRaiseError $OG_ERR_IMAGE "$1 $2 $IMGFILE"
rm -f "$IMGFILE"
@@ -746,7 +817,7 @@ if [ "$*" == "help" ]; then
return
fi
# Error si no se reciben 4 parámetros.
-[ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
+[ $# == 4 ] || [ $# == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $?
# Procesar parámetros.
PART="$(ogDiskToDev $3 $4)" || return $(ogRaiseError $OG_ERR_NOTFOUND " $3 $4"; echo $?)
#IMGTYPE=$(ogGetImageType "$1" "$2")
@@ -779,7 +850,12 @@ fi
# Solicitamos la generación de la instruccion a ejecutar
# Atención: no se comprueba el tipo de sistema de archivos.
# Atención: no se comprueba incongruencia entre partición e imagen.
-PROGRAM=`ogRestoreImageSyntax $IMGFILE $PART`
+INFOIMG=$(ogGetImageInfo $IMGFILE) || ogRaiseError $OG_ERR_NOTFOUND "No Image $1" || return $?
+TOOL=`echo $INFOIMG | cut -f1 -d:`
+COMPRESSOR=`echo $INFOIMG | cut -f2 -d:`
+PROGRAM=`ogRestoreImageSyntax $IMGFILE $PART $TOOL $COMPRESSOR $5`
+echo PROGRAMA
+echo "$PROGRAM"
# Desmontar y bloquear partición.
ogUnmount $3 $4 2>/dev/null || return $(ogRaiseError $OG_ERR_PARTITION " $3 $4"; echo $?)