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