diff options
Diffstat (limited to 'client/engine/Image.lib')
-rwxr-xr-x | client/engine/Image.lib | 89 |
1 files changed, 81 insertions, 8 deletions
diff --git a/client/engine/Image.lib b/client/engine/Image.lib index 941deb91..7c9ba704 100755 --- a/client/engine/Image.lib +++ b/client/engine/Image.lib @@ -102,6 +102,42 @@ esac [ -n "$PARAM1" ] && echo "$PARAM1 $PARAM2 $PARAM3 $IMGFILE" } +function ogTiptorrentGet () +{ +local MAXTRIES +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 +popd > /dev/null || return 1 +return $? +} + +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) +ogTiptorrentGet "$2" +MD5IMG=$(cat "$IMGPATH"*[0-3] | md5sum | 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 +157,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 IMGPATHPART1 # Si se solicita, mostrar ayuda. @@ -131,8 +168,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 +184,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 +234,39 @@ 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" + IMGPATHPART1="$IMGPATH.1" + if [ -f "$IMGPATHPART1" ]; then + if [ ! -f "$IMGPATH".full.sum ]; then + cat "$IMGPATH"*[0-3] | md5sum "$IMGPATH" | cut -f1 -d " " > "$IMGPATH".full.sum + fi + MD5FILE=$(cat "$IMGPATH".full.sum) + MD5WGET=$(wget -qO - "$ogrepo:9999/$IMGPATH.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*[0-3] |" + 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 } @@ -746,7 +814,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 +847,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 $?) |