#!/bin/bash # Scirpt de ejemplo para restaurar una imagen. # (puede usarse como base para el programa de restauración de imágenes usado por OpenGNSys Admin). TIME1=$SECONDS PROG="$(basename $0)" if [ $# -lt 4 ]; then ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]" exit $? fi # Procesar parámetros de entrada IMGFILE=$(ogGetPath "$1" "$2.img") PROTO=${5:-"UNICAST"} if [ "$1" == "CACHE" -o "$1" == "cache" ]; then IMGDIR=$(ogGetParentPath "$1" "$2") # Si no existe el directorio de la imagen, crearlo. if [ -z "$IMGDIR" ]; then echo "[5] Creando directorio de imagen \"$1, ${2%/*}\"." ogMakeDir "$1" "${2%/*}" || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? fi IMGDIR=$(ogGetParentPath "$1" "$2") || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? # Procesar protocolos de transferencia. case "$PROTO" in UNICAST|unicast) # Copiar fichero del repositorio al caché, si no existe en caché o es anterior. if [ -z "$IMGFILE" ] || [ $(ogIsNewerFile "repo" "$2.img" "$IMGFILE") ]; then echo "[10] Copiando imagen \"$2\" del repositorio a caché local" ogCopyFile "repo" "$2.img" "$IMGDIR" || exit $? IMGFILE=$(ogGetPath "cache" "$2.img") fi ;; MULTICAST|multicast) if [ -z "$IMGFILE" ]; then echo "[10] Copiando imagen multicast \"$2\" del repositorio a caché local" PORTBASE=`echo $6 | cut -f1 -d:` echo "ogMcastReceiverFile SOURCE:$PORTBASE TARGET:"CACHE" "$2.img" " ogMcastReceiverFile "$PORTBASE" "CACHE" "$2.img" || exit $? IMGFILE=$(ogGetPath "cache" "$2.img") fi ;; TORRENT|torrent) echo "[9] copiando el fichero torrent Unicast \"$2\" del repositorio a caché local" ogCopyFile "repo" "$2.img.torrent" "$IMGDIR" || exit $? echo "[10] descargando imagen torrent($6) \"$2\" del repositorio a caché local" ogTorrentStart "CACHE" "$2.img.torrent" "peer:60" || exit $? IMGFILE=$(ogGetPath "cache" "$2.img") ;; *) # Protocolo desconocido. ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT opciones ]" exit $? esac fi if [ -z "$IMGFILE" ]; then ogRaiseError $OG_ERR_NOTFOUND "$1, $2" exit $? fi PART=$(ogDiskToDev "$3" "$4") || exit $? # Restaurar la imagen. echo "[40] Restaurar imagen $IMGFILE en $PART" ogRestoreImage "$@" || exit $? # Restaurar tamaño. echo "[80] Extender sistema de archivos." ogExtendFs $3 $4 # Cambiar nombre en sistemas Windows. if [ "$(ogGetOsType $3 $4)" = "Windows" ]; then HOST=$(ogGetHostname) HOST=${HOST:-"UNKNOWN"} echo "[90] Cambiar nombre Windows a \"$HOST\"." ogSetWindowsName $3 $4 "$HOST" fi TIME=$[SECONDS-TIME1] echo "[100] Duración de la operación $[TIME/60]m $[TIME%60]s"