[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 |
---|
[0fbc05e] | 13 | IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
| 14 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
[87a7a799] | 15 | PROTO=${5:-"UNICAST"} |
---|
[e42f34e] | 16 | if [ "$1" == "CACHE" -o "$1" == "cache" ]; then |
---|
[c7d9af7] | 17 | IMGDIR=$(ogGetParentPath "$1" "$2") |
---|
| 18 | # Si no existe el directorio de la imagen, crearlo. |
---|
[b9a5881] | 19 | if [ -z "$IMGDIR" ]; then |
---|
[180a07dd] | 20 | echo "[5] Creando directorio de imagen \"$1, ${2%/*}\"." |
---|
[c7d9af7] | 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 $? |
---|
[87a7a799] | 24 | # Procesar protocolos de transferencia. |
---|
| 25 | case "$PROTO" in |
---|
| 26 | UNICAST|unicast) |
---|
[0fbc05e] | 27 | # Copiar fichero del repositorio al caché local. |
---|
| 28 | IMGTYPE=$(ogGetImageType "repo" "$2") |
---|
| 29 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
| 30 | if [ -z "$IMGFILE" ] || [ $(ogIsNewerFile "repo" "$2.$IMGTYPE" "$IMGFILE") ]; then |
---|
| 31 | echo "[10] Copiando imagen \"$2\" del repositorio a caché local" |
---|
| 32 | ogCopyFile "repo" "$2.$IMGTYPE" "$IMGDIR" || exit $? |
---|
| 33 | IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") |
---|
[87a7a799] | 34 | fi |
---|
| 35 | ;; |
---|
| 36 | MULTICAST|multicast) |
---|
[bba08bf] | 37 | if [ -z "$IMGFILE" ]; then |
---|
[0fbc05e] | 38 | echo "[10] Copiando imagen multicast \"$2\" del repositorio a caché local" |
---|
| 39 | IMGTYPE=$(ogGetImageType "repo" "$2") |
---|
| 40 | PORTBASE=`echo $6 | cut -f1 -d:` |
---|
| 41 | echo "ogMcastReceiverFile SOURCE:$PORTBASE TARGET:CACHE $2.$IMGTYPE" |
---|
| 42 | ogMcastReceiverFile "$PORTBASE" "CACHE" "$2.$IMGTYPE" || exit $? |
---|
| 43 | IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") |
---|
[bba08bf] | 44 | fi |
---|
[87a7a799] | 45 | ;; |
---|
| 46 | TORRENT|torrent) |
---|
[0fbc05e] | 47 | echo "[9] copiando el fichero torrent Unicast \"$2\" del repositorio a caché local" |
---|
| 48 | IMGTYPE=$(ogGetImageType "repo" "$2") |
---|
| 49 | ogCopyFile "repo" "$2.$IMGTYPE.torrent" "$IMGDIR" || exit $? |
---|
| 50 | echo "[10] descargando imagen torrent($6) \"$2\" del repositorio a caché local" |
---|
| 51 | ogTorrentStart "CACHE" "$2.$IMGTYPE.torrent" "peer:60" || exit $? |
---|
| 52 | IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") |
---|
[87a7a799] | 53 | ;; |
---|
| 54 | *) # Protocolo desconocido. |
---|
| 55 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT opciones ]" |
---|
| 56 | exit $? |
---|
| 57 | esac |
---|
[c7d9af7] | 58 | fi |
---|
| 59 | if [ -z "$IMGFILE" ]; then |
---|
| 60 | ogRaiseError $OG_ERR_NOTFOUND "$1, $2" |
---|
| 61 | exit $? |
---|
[e42f34e] | 62 | fi |
---|
[f8f4dfa] | 63 | PART=$(ogDiskToDev "$3" "$4") || exit $? |
---|
[41d9755] | 64 | |
---|
[f8f4dfa] | 65 | # Restaurar la imagen. |
---|
[0fbc05e] | 66 | echo "[40] Restaurar imagen en $PART" |
---|
[1c04494] | 67 | ogRestoreImage "$@" || exit $? |
---|
[f8f4dfa] | 68 | # Restaurar tamaño. |
---|
[180a07dd] | 69 | echo "[80] Extender sistema de archivos." |
---|
[f5432db7] | 70 | ogExtendFs $3 $4 |
---|
[bfeb89a] | 71 | # Cambiar nombre en sistemas Windows y quitar usuario de acceso por defecto. |
---|
[9fb5086] | 72 | if [ "$(ogGetOsType $3 $4)" = "Windows" ]; then |
---|
| 73 | HOST=$(ogGetHostname) |
---|
[bfeb89a] | 74 | HOST=${HOST:-"pc"} |
---|
[0fbc05e] | 75 | echo "[90] Cambiar nombre Windows a \"$HOST\" y usuario de acceso." |
---|
[f5432db7] | 76 | ogSetWindowsName $3 $4 "$HOST" |
---|
[57a3d5b] | 77 | #ogSetWinlogonUser $3 $4 " " # Descomentar para cambiar usuario de inicio. |
---|
[1c04494] | 78 | fi |
---|
[f5432db7] | 79 | TIME=$[SECONDS-TIME1] |
---|
[bfeb89a] | 80 | echo "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s" |
---|
[f8f4dfa] | 81 | |
---|