[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)" |
---|
[87a7a799] | 7 | if [ $# -lt 4 ]; then |
---|
[bba08bf] | 8 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]" |
---|
[f8f4dfa] | 9 | exit $? |
---|
| 10 | fi |
---|
| 11 | |
---|
| 12 | # Procesar parámetros de entrada |
---|
[c7d9af7] | 13 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
[87a7a799] | 14 | PROTO=${5:-"UNICAST"} |
---|
[e42f34e] | 15 | if [ "$1" == "CACHE" -o "$1" == "cache" ]; then |
---|
[c7d9af7] | 16 | IMGDIR=$(ogGetParentPath "$1" "$2") |
---|
| 17 | # Si no existe el directorio de la imagen, crearlo. |
---|
[b9a5881] | 18 | if [ -z "$IMGDIR" ]; then |
---|
[180a07dd] | 19 | echo "[5] Creando directorio de imagen \"$1, ${2%/*}\"." |
---|
[c7d9af7] | 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 $? |
---|
[87a7a799] | 23 | # Procesar protocolos de transferencia. |
---|
| 24 | case "$PROTO" in |
---|
| 25 | UNICAST|unicast) |
---|
| 26 | # Copiar fichero del repositorio al caché local. |
---|
| 27 | if [ -z "$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) |
---|
[bba08bf] | 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" " |
---|
[1678fa1] | 38 | ogMcastReceiverFile "$PORTBASE" "CACHE" "$2.img" || exit $? |
---|
[bba08bf] | 39 | IMGFILE=$(ogGetPath "cache" "$2.img") |
---|
| 40 | fi |
---|
[87a7a799] | 41 | ;; |
---|
| 42 | TORRENT|torrent) |
---|
[bba08bf] | 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" |
---|
[1678fa1] | 46 | ogTorrentStart "CACHE" "$2.img.torrent" "peer:60" || exit $? |
---|
[bba08bf] | 47 | IMGFILE=$(ogGetPath "cache" "$2.img") |
---|
[87a7a799] | 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 |
---|
[c7d9af7] | 53 | fi |
---|
| 54 | if [ -z "$IMGFILE" ]; then |
---|
| 55 | ogRaiseError $OG_ERR_NOTFOUND "$1, $2" |
---|
| 56 | exit $? |
---|
[e42f34e] | 57 | fi |
---|
[f8f4dfa] | 58 | PART=$(ogDiskToDev "$3" "$4") || exit $? |
---|
[41d9755] | 59 | echo "[20] $PROG: Origen=$IMGFILE, Destino=$PART" |
---|
| 60 | |
---|
[f8f4dfa] | 61 | |
---|
| 62 | # Restaurar la imagen. |
---|
[41d9755] | 63 | echo "[25] Restaurar imagen" |
---|
[1c04494] | 64 | ogRestoreImage "$@" || exit $? |
---|
[f8f4dfa] | 65 | # Restaurar tamaño. |
---|
[180a07dd] | 66 | echo "[80] Extender sistema de archivos." |
---|
[f5432db7] | 67 | ogExtendFs $3 $4 |
---|
[1c04494] | 68 | # Cambiar nombre en sistemas Windows. |
---|
[9fb5086] | 69 | if [ "$(ogGetOsType $3 $4)" = "Windows" ]; then |
---|
| 70 | HOST=$(ogGetHostname) |
---|
| 71 | HOST=${HOST:-"UNKNOWN"} |
---|
[180a07dd] | 72 | echo "[90] Cambiar nombre Windows a \"$HOST\"." |
---|
[f5432db7] | 73 | ogSetWindowsName $3 $4 "$HOST" |
---|
[1c04494] | 74 | fi |
---|
[f5432db7] | 75 | TIME=$[SECONDS-TIME1] |
---|
[180a07dd] | 76 | echo "[100] Duración de la operación $[TIME/60]m $[TIME%60]s" |
---|
[f8f4dfa] | 77 | |
---|