diff options
-rw-r--r-- | admin/WebConsole/comandos/EliminarImagenCache.php | 4 | ||||
-rw-r--r-- | admin/WebConsole/includes/pintaParticiones.php | 4 | ||||
-rwxr-xr-x | client/engine/Image.lib | 92 | ||||
-rwxr-xr-x | client/shared/etc/init/default.sh | 3 | ||||
-rwxr-xr-x | client/shared/scripts/deployImage | 5 | ||||
-rwxr-xr-x | client/shared/scripts/restoreImage | 5 |
6 files changed, 104 insertions, 9 deletions
diff --git a/admin/WebConsole/comandos/EliminarImagenCache.php b/admin/WebConsole/comandos/EliminarImagenCache.php index 6c9e92ba..60a24cea 100644 --- a/admin/WebConsole/comandos/EliminarImagenCache.php +++ b/admin/WebConsole/comandos/EliminarImagenCache.php @@ -348,6 +348,10 @@ switch($ambito){ $ima[$x] = str_replace(".img.diff", "", $ima[$x]); //quitar todos los .img $ima[$x]=trim($ima[$x]); $nombreimagenes[]="f-".$ima[$x]; + } elseif (preg_match("/\.[0-3]/", $ima[$x])) { + $ima[$x] = preg_replace("/\.img\.[0-3]/", "", $ima[$x]); + $ima[$x] = trim($ima[$x]); + $nombreimagenes[] = "f-".$ima[$x]; }else{ $ima[$x] = str_replace(".img", "", $ima[$x]); //quitar todos los .img $ima[$x]=trim($ima[$x]); diff --git a/admin/WebConsole/includes/pintaParticiones.php b/admin/WebConsole/includes/pintaParticiones.php index c789298d..ef70de44 100644 --- a/admin/WebConsole/includes/pintaParticiones.php +++ b/admin/WebConsole/includes/pintaParticiones.php @@ -308,13 +308,15 @@ function pintaParticionesRestaurarImagen($cmd,$configuraciones,$idordenadores,$c $metodos.="UNICAST-DIRECT=UNICAST-DIRECT".chr(13); $metodos.="MULTICAST " . mcast_syntax($cmd,$ambito,$idambito) . "=MULTICAST-CACHE".chr(13); $metodos.="MULTICAST-DIRECT " . mcast_syntax($cmd,$ambito,$idambito) . "=MULTICAST-DIRECT".chr(13); - $metodos.="TORRENT " . torrent_syntax($cmd,$ambito,$idambito) . "=TORRENT-CACHE"; + $metodos.="TORRENT " . torrent_syntax($cmd,$ambito,$idambito) . "=TORRENT-CACHE".chr(13); + $metodos.="TIPTORRENT=TIPTORRENT-CACHE"; $TBmetodos["UNICAST-CACHE"]=1; $TBmetodos["UNICAST-DIRECT"]=2; $TBmetodos["MULTICAST-CACHE"]=3; $TBmetodos["MULTICAST-DIRECT"]=4; $TBmetodos["TORRENT-CACHE"]=5; + $TBmetodos["TIPTORRENT"]=6; $idxc=$_SESSION["protclonacion"]; if ($idxc == "UNICAST") { $idxc = "UNICAST-DIRECT"; 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 $?) diff --git a/client/shared/etc/init/default.sh b/client/shared/etc/init/default.sh index ed5527b9..fd88bb53 100755 --- a/client/shared/etc/init/default.sh +++ b/client/shared/etc/init/default.sh @@ -19,6 +19,9 @@ echo "${MSG_LAUNCHCLIENT:-.}" [ -f /usr/local/etc/${LANG%_*}.qmap ] && export QWS_KEYBOARD="TTY:keymap=/usr/local/etc/${LANG%_*}.qmap" if [ "$ogstatus" != "offline" ]; then + if ogFindCache &>/dev/null; then + /opt/opengnsys/bin/tiptorrent --root /opt/opengnsys/cache/opt/opengnsys/images -n 3 & + fi GROUP_CONFIG=/opt/opengnsys/ogClient/cfg/${group/ /_}.json PYMAJMIN=`python3 --version | cut -d" " -f2 | cut -d. -f1,2` export PYTHONPATH=/opt/opengnsys/lib/python$PYMAJMIN diff --git a/client/shared/scripts/deployImage b/client/shared/scripts/deployImage index d74d3ac2..e34c908f 100755 --- a/client/shared/scripts/deployImage +++ b/client/shared/scripts/deployImage @@ -121,6 +121,9 @@ case "$MODE" in UNICAST-DIRECT) NEXTOPERATION=UNICAST ;; + TIPTORRENT) + NEXTOPERATION=TIPTORRENT + ;; # Si protocolo es torrent|torrent-cache o multicast|multicast-cache TORRENT|TORRENT-CACHE|MULTICAST|MULTICAST-CACHE|UNICAST|UNICAST-CACHE) @@ -198,6 +201,8 @@ case "$NEXTOPERATION" in PARAMS="CACHE $IMGNAME $DISK $PART" ;; UNICAST) PARAMS="$REPO $IMGNAME $DISK $PART" ;; + TIPTORRENT) + PARAMS="$REPO $IMGNAME $DISK $PART TIPTORRENT" ;; MULTICAST) PARAMS="$REPO $IMGNAME $DISK $PART $PROTO $PROTOOPT" ;; esac diff --git a/client/shared/scripts/restoreImage b/client/shared/scripts/restoreImage index d9e7f584..537bcbb9 100755 --- a/client/shared/scripts/restoreImage +++ b/client/shared/scripts/restoreImage @@ -77,6 +77,11 @@ fi # Procesar protocolos de transferencia. case "$PROTO" in + TIPTORRENT) + ogEcho log session "[40] ogRestoreImage $REPO $IMGNAME $DISK $PART true" + ogExecAndLog command ogRestoreImage "$REPO" "$IMGNAME" "$DISK" "$PART" true + RETVAL=$? + ;; UNICAST|UNICAST-DIRECT) # Restaurar la imagen. ogEcho log session "[40] ogRestoreImage $REPO $IMGNAME $DISK $PART UNICAST" |