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 "Formato: $PROG REPO|CACHE imagen ndisco nparticion" |
---|
9 | exit $? |
---|
10 | fi |
---|
11 | |
---|
12 | # Procesar parámetros de entrada |
---|
13 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
14 | if [ "$1" == "CACHE" -o "$1" == "cache" ]; then |
---|
15 | IMGDIR=$(ogGetParentPath "$1" "$2") |
---|
16 | # Si no existe el directorio de la imagen, crearlo. |
---|
17 | if [ -z "$IMGDIR" ]; then |
---|
18 | echo "Creando directorio de imagen \"$1, ${2%/*}\"." |
---|
19 | ogMakeDir "$1" "${2%/*}" || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? |
---|
20 | fi |
---|
21 | IMGDIR=$(ogGetParentPath "$1" "$2") || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? |
---|
22 | if [ -z "$IMGFILE" ]; then |
---|
23 | echo "Copiando imagen \"$2\" del repositorio a caché local" |
---|
24 | ogCopyFile "repo" "$2.img" "$IMGDIR" || exit $? |
---|
25 | IMGFILE=$(ogGetPath "cache" "$2.img") |
---|
26 | fi |
---|
27 | fi |
---|
28 | if [ -z "$IMGFILE" ]; then |
---|
29 | ogRaiseError $OG_ERR_NOTFOUND "$1, $2" |
---|
30 | exit $? |
---|
31 | fi |
---|
32 | PART=$(ogDiskToDev "$3" "$4") || exit $? |
---|
33 | |
---|
34 | # Restaurar la imagen. |
---|
35 | ogEcho info "$PROG: Origen=$IMGFILE, Destino=$PART" |
---|
36 | ogRestoreImage "$@" || exit $? |
---|
37 | # Restaurar tamaño. |
---|
38 | ogEcho info "$PROG: Extender sistema de archivos." |
---|
39 | ogExtendFs $3 $4 |
---|
40 | # Cambiar nombre en sistemas Windows. |
---|
41 | if [ "$(ogGetOsType $3 $4)" = "Windows" ]; then |
---|
42 | HOST=$(ogGetHostname) |
---|
43 | HOST=${HOST:-"UNKNOWN"} |
---|
44 | ogEcho info "$PROG: Cambiar nombre Windows a \"$HOST\"." |
---|
45 | ogSetWindowsName $3 $4 "$HOST" |
---|
46 | fi |
---|
47 | TIME=$[SECONDS-TIME1] |
---|
48 | ogEcho info "$PROG: Duración de la operación $[TIME/60]m $[TIME%60]s" |
---|
49 | |
---|