[f8f4dfa] | 1 | #!/bin/bash |
---|
[e42f34e] | 2 | # Scirpt de ejemplo para restaurar una imagen. |
---|
[f8f4dfa] | 3 | # (puede usarse como base para el programa de restauración de imágenes usado por OpenGNSys Admin). |
---|
| 4 | |
---|
[f5432db7] | 5 | TIME1=$SECONDS |
---|
[f8f4dfa] | 6 | PROG="$(basename $0)" |
---|
| 7 | if [ $# -ne 4 ]; then |
---|
[892606b9] | 8 | ogRaiseError $OG_ERR_FORMAT "Formato: $PROG REPO|CACHE imagen ndisco nparticion" |
---|
[f8f4dfa] | 9 | exit $? |
---|
| 10 | fi |
---|
| 11 | |
---|
[180a07dd] | 12 | # Iniciación de porcentaje para la barra de progreso del Browser. |
---|
| 13 | echo "[0,100]" |
---|
| 14 | echo "[0] $PROG: Origen=$IMGFILE, Destino=$PART" |
---|
| 15 | |
---|
[f8f4dfa] | 16 | # Procesar parámetros de entrada |
---|
[c7d9af7] | 17 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
[e42f34e] | 18 | if [ "$1" == "CACHE" -o "$1" == "cache" ]; then |
---|
[c7d9af7] | 19 | IMGDIR=$(ogGetParentPath "$1" "$2") |
---|
| 20 | # Si no existe el directorio de la imagen, crearlo. |
---|
[b9a5881] | 21 | if [ -z "$IMGDIR" ]; then |
---|
[180a07dd] | 22 | echo "[5] Creando directorio de imagen \"$1, ${2%/*}\"." |
---|
[c7d9af7] | 23 | ogMakeDir "$1" "${2%/*}" || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? |
---|
| 24 | fi |
---|
| 25 | IMGDIR=$(ogGetParentPath "$1" "$2") || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? |
---|
[e42f34e] | 26 | if [ -z "$IMGFILE" ]; then |
---|
[180a07dd] | 27 | echo "[10] Copiando imagen \"$2\" del repositorio a caché local" |
---|
[c7d9af7] | 28 | ogCopyFile "repo" "$2.img" "$IMGDIR" || exit $? |
---|
| 29 | IMGFILE=$(ogGetPath "cache" "$2.img") |
---|
[e42f34e] | 30 | fi |
---|
[c7d9af7] | 31 | fi |
---|
| 32 | if [ -z "$IMGFILE" ]; then |
---|
| 33 | ogRaiseError $OG_ERR_NOTFOUND "$1, $2" |
---|
| 34 | exit $? |
---|
[e42f34e] | 35 | fi |
---|
[f8f4dfa] | 36 | PART=$(ogDiskToDev "$3" "$4") || exit $? |
---|
| 37 | |
---|
| 38 | # Restaurar la imagen. |
---|
[180a07dd] | 39 | echo "[20] Restaurar imagen" |
---|
[1c04494] | 40 | ogRestoreImage "$@" || exit $? |
---|
[f8f4dfa] | 41 | # Restaurar tamaño. |
---|
[180a07dd] | 42 | echo "[80] Extender sistema de archivos." |
---|
[f5432db7] | 43 | ogExtendFs $3 $4 |
---|
[1c04494] | 44 | # Cambiar nombre en sistemas Windows. |
---|
[9fb5086] | 45 | if [ "$(ogGetOsType $3 $4)" = "Windows" ]; then |
---|
| 46 | HOST=$(ogGetHostname) |
---|
| 47 | HOST=${HOST:-"UNKNOWN"} |
---|
[180a07dd] | 48 | echo "[90] Cambiar nombre Windows a \"$HOST\"." |
---|
[f5432db7] | 49 | ogSetWindowsName $3 $4 "$HOST" |
---|
[1c04494] | 50 | fi |
---|
[f5432db7] | 51 | TIME=$[SECONDS-TIME1] |
---|
[180a07dd] | 52 | echo "[100] Duración de la operación $[TIME/60]m $[TIME%60]s" |
---|
[f8f4dfa] | 53 | |
---|