| 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 | IMGTYPE="img" |
|---|
| 14 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
|---|
| 15 | PROTO=${5:-"UNICAST"} |
|---|
| 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 | # Procesar protocolos de transferencia. |
|---|
| 25 | case "$PROTO" in |
|---|
| 26 | UNICAST|unicast) |
|---|
| 27 | # Copiar fichero del repositorio al caché local. |
|---|
| 28 | #IMGTYPE=$(ogGetImageType "repo" "$2") |
|---|
| 29 | IMGFILE=$(ogGetPath "cache" "$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" |
|---|
| 33 | fi |
|---|
| 34 | # Comprobar si existe el fichero en caché y no en el repositorio. |
|---|
| 35 | if [ -z "$IMGFILE" ]; then |
|---|
| 36 | #IMGTYPE=$(ogGetImageType "cache" "$2") |
|---|
| 37 | IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") |
|---|
| 38 | if [ -z "$IMGFILE" ]; then |
|---|
| 39 | ogRaiseError $OG_ERR_NOTFOUND "cache, $2.$IMGTYPE" |
|---|
| 40 | exit $? |
|---|
| 41 | fi |
|---|
| 42 | fi |
|---|
| 43 | ;; |
|---|
| 44 | MULTICAST|multicast) |
|---|
| 45 | if [ -z "$IMGFILE" ]; then |
|---|
| 46 | echo "[10] Copiando imagen multicast \"$2\" del repositorio a caché local" |
|---|
| 47 | #IMGTYPE=$(ogGetImageType "repo" "$2") |
|---|
| 48 | PORTBASE=`echo $6 | cut -f1 -d:` |
|---|
| 49 | echo "ogMcastReceiverFile SOURCE:$PORTBASE TARGET:CACHE $2.$IMGTYPE" |
|---|
| 50 | ogMcastReceiverFile "$PORTBASE" "CACHE" "$2.$IMGTYPE" || exit $? |
|---|
| 51 | IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") |
|---|
| 52 | fi |
|---|
| 53 | ;; |
|---|
| 54 | TORRENT|torrent) |
|---|
| 55 | echo "[9] copiando el fichero torrent Unicast \"$2\" del repositorio a caché local" |
|---|
| 56 | #IMGTYPE=$(ogGetImageType "repo" "$2") |
|---|
| 57 | ogCopyFile "repo" "$2.$IMGTYPE.torrent" "$IMGDIR" || exit $? |
|---|
| 58 | echo "[10] descargando imagen torrent($6) \"$2\" del repositorio a caché local" |
|---|
| 59 | ogTorrentStart "CACHE" "$2.$IMGTYPE.torrent" "peer:60" || exit $? |
|---|
| 60 | IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") |
|---|
| 61 | ;; |
|---|
| 62 | *) # Protocolo desconocido. |
|---|
| 63 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT opciones ]" |
|---|
| 64 | exit $? |
|---|
| 65 | esac |
|---|
| 66 | fi |
|---|
| 67 | if [ -z "$IMGFILE" ]; then |
|---|
| 68 | ogRaiseError $OG_ERR_NOTFOUND "$1, $2" |
|---|
| 69 | exit $? |
|---|
| 70 | fi |
|---|
| 71 | PART=$(ogDiskToDev "$3" "$4") || exit $? |
|---|
| 72 | |
|---|
| 73 | # Restaurar la imagen. |
|---|
| 74 | echo "[40] Restaurar imagen en $PART" |
|---|
| 75 | ogRestoreImage "$@" || exit $? |
|---|
| 76 | # Restaurar tamaño. |
|---|
| 77 | echo "[80] Extender sistema de archivos." |
|---|
| 78 | ogExtendFs $3 $4 |
|---|
| 79 | # Llamar al script de post-configuración del sistema operativo. |
|---|
| 80 | echo "[90] Post-configuracion de aranque del sistema." |
|---|
| 81 | configureOs $3 $4 |
|---|
| 82 | |
|---|
| 83 | TIME=$[SECONDS-TIME1] |
|---|
| 84 | echo "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s" |
|---|
| 85 | |
|---|