#!/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 [ $# -ne 4 ]; then ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion" exit $? fi echo "[0] $PROG: Origen=$IMGFILE, Destino=$PART" # Procesar parámetros de entrada IMGFILE=$(ogGetPath "$1" "$2.img") 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 $? if [ -z "$IMGFILE" ]; then echo "[10] Copiando imagen \"$2\" del repositorio a caché local" ogCopyFile "repo" "$2.img" "$IMGDIR" || exit $? IMGFILE=$(ogGetPath "cache" "$2.img") fi fi if [ -z "$IMGFILE" ]; then ogRaiseError $OG_ERR_NOTFOUND "$1, $2" exit $? fi PART=$(ogDiskToDev "$3" "$4") || exit $? # Restaurar la imagen. echo "[20] Restaurar imagen" 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"