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 [ $# -lt 4 ]; then |
---|
8 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]" |
---|
9 | exit $? |
---|
10 | fi |
---|
11 | |
---|
12 | # Procesar parámetros de entrada |
---|
13 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
14 | PROTO=${5:-"UNICAST"} |
---|
15 | if [ "$1" == "CACHE" -o "$1" == "cache" ]; then |
---|
16 | IMGDIR=$(ogGetParentPath "$1" "$2") |
---|
17 | # Si no existe el directorio de la imagen, crearlo. |
---|
18 | if [ -z "$IMGDIR" ]; then |
---|
19 | echo "[5] Creando directorio de imagen \"$1, ${2%/*}\"." |
---|
20 | ogMakeDir "$1" "${2%/*}" || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? |
---|
21 | fi |
---|
22 | IMGDIR=$(ogGetParentPath "$1" "$2") || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? |
---|
23 | # Procesar protocolos de transferencia. |
---|
24 | case "$PROTO" in |
---|
25 | UNICAST|unicast) |
---|
26 | # Copiar fichero del repositorio al caché, si no existe en caché o es anterior. |
---|
27 | if [ -z "$IMGFILE" ] || [ $(ogIsNewerFile "repo" "$2.img" "$IMGFILE") ]; then |
---|
28 | echo "[10] Copiando imagen \"$2\" del repositorio a caché local" |
---|
29 | ogCopyFile "repo" "$2.img" "$IMGDIR" || exit $? |
---|
30 | IMGFILE=$(ogGetPath "cache" "$2.img") |
---|
31 | fi |
---|
32 | ;; |
---|
33 | MULTICAST|multicast) |
---|
34 | if [ -z "$IMGFILE" ]; then |
---|
35 | echo "[10] Copiando imagen multicast \"$2\" del repositorio a caché local" |
---|
36 | PORTBASE=`echo $6 | cut -f1 -d:` |
---|
37 | echo "ogMcastReceiverFile SOURCE:$PORTBASE TARGET:"CACHE" "$2.img" " |
---|
38 | ogMcastReceiverFile "$PORTBASE" "CACHE" "$2.img" || exit $? |
---|
39 | IMGFILE=$(ogGetPath "cache" "$2.img") |
---|
40 | fi |
---|
41 | ;; |
---|
42 | TORRENT|torrent) |
---|
43 | echo "[9] copiando el fichero torrent Unicast \"$2\" del repositorio a caché local" |
---|
44 | ogCopyFile "repo" "$2.img.torrent" "$IMGDIR" || exit $? |
---|
45 | echo "[10] descargando imagen torrent($6) \"$2\" del repositorio a caché local" |
---|
46 | ogTorrentStart "CACHE" "$2.img.torrent" "peer:60" || exit $? |
---|
47 | IMGFILE=$(ogGetPath "cache" "$2.img") |
---|
48 | ;; |
---|
49 | *) # Protocolo desconocido. |
---|
50 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT opciones ]" |
---|
51 | exit $? |
---|
52 | esac |
---|
53 | fi |
---|
54 | if [ -z "$IMGFILE" ]; then |
---|
55 | ogRaiseError $OG_ERR_NOTFOUND "$1, $2" |
---|
56 | exit $? |
---|
57 | fi |
---|
58 | PART=$(ogDiskToDev "$3" "$4") || exit $? |
---|
59 | |
---|
60 | |
---|
61 | # Restaurar la imagen. |
---|
62 | echo "[40] Restaurar imagen $IMGFILE en $PART" |
---|
63 | ogRestoreImage "$@" || exit $? |
---|
64 | # Restaurar tamaño. |
---|
65 | echo "[80] Extender sistema de archivos." |
---|
66 | ogExtendFs $3 $4 |
---|
67 | # Cambiar nombre en sistemas Windows. |
---|
68 | if [ "$(ogGetOsType $3 $4)" = "Windows" ]; then |
---|
69 | HOST=$(ogGetHostname) |
---|
70 | HOST=${HOST:-"UNKNOWN"} |
---|
71 | echo "[90] Cambiar nombre Windows a \"$HOST\"." |
---|
72 | ogSetWindowsName $3 $4 "$HOST" |
---|
73 | fi |
---|
74 | TIME=$[SECONDS-TIME1] |
---|
75 | echo "[100] Duración de la operación $[TIME/60]m $[TIME%60]s" |
---|
76 | |
---|