#!/bin/bash # Scirpt de ejemplo para restaurar una imagen. # (puede usarse como base para el programa de restauración de imágenes usado por OpenGNSys Admin). TIME1=$SECONDS PROG="$(basename $0)" if [ $# -lt 4 ]; then ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]" exit $? fi # Procesar parámetros de entrada IMGTYPE="img" IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") PROTO=${5:-"UNICAST"} if [ "$1" == "CACHE" -o "$1" == "cache" ]; then IMGDIR=$(ogGetParentPath "$1" "$2") # Si no existe el directorio de la imagen, crearlo. if [ -z "$IMGDIR" ]; then echo "[5] Creando directorio de imagen \"$1, ${2%/*}\"." ogMakeDir "$1" "${2%/*}" || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? fi IMGDIR=$(ogGetParentPath "$1" "$2") || ogRaiseError $OG_ERR_NOTFOUND "$1, ${2%/*}" || exit $? # Procesar protocolos de transferencia. case "$PROTO" in UNICAST|unicast) # Copiar fichero del repositorio al caché local. #IMGTYPE=$(ogGetImageType "repo" "$2") IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") if [ -z "$IMGFILE" ] || [ $(ogIsNewerFile "repo" "$2.$IMGTYPE" "$IMGFILE") ]; then echo "[10] Copiando imagen \"$2\" del repositorio a caché local" ogCopyFile "repo" "$2.$IMGTYPE" "$IMGDIR" fi # Comprobar si existe el fichero en caché y no en el repositorio. if [ -z "$IMGFILE" ]; then #IMGTYPE=$(ogGetImageType "cache" "$2") IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") if [ -z "$IMGFILE" ]; then ogRaiseError $OG_ERR_NOTFOUND "cache, $2.$IMGTYPE" exit $? fi fi ;; MULTICAST|multicast) if [ -z "$IMGFILE" ]; then echo "[10] Copiando imagen multicast \"$2\" del repositorio a caché local" #IMGTYPE=$(ogGetImageType "repo" "$2") PORTBASE=`echo $6 | cut -f1 -d:` echo "ogMcastReceiverFile SOURCE:$PORTBASE TARGET:CACHE $2.$IMGTYPE" ogMcastReceiverFile "$PORTBASE" "CACHE" "$2.$IMGTYPE" || exit $? IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") fi ;; TORRENT|torrent) echo "[9] copiando el fichero torrent Unicast \"$2\" del repositorio a caché local" #IMGTYPE=$(ogGetImageType "repo" "$2") ogCopyFile "repo" "$2.$IMGTYPE.torrent" "$IMGDIR" || exit $? echo "[10] descargando imagen torrent($6) \"$2\" del repositorio a caché local" ogTorrentStart "CACHE" "$2.$IMGTYPE.torrent" "peer:60" || exit $? IMGFILE=$(ogGetPath "cache" "$2.$IMGTYPE") ;; *) # Protocolo desconocido. ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT opciones ]" exit $? esac fi if [ -z "$IMGFILE" ]; then ogRaiseError $OG_ERR_NOTFOUND "$1, $2" exit $? fi PART=$(ogDiskToDev "$3" "$4") || exit $? # Restaurar la imagen. echo "[40] Restaurar imagen en $PART" ogRestoreImage "$@" || exit $? # Restaurar tamaño. echo "[80] Extender sistema de archivos." ogExtendFs $3 $4 # Cambiar nombre en sistemas Windows y quitar usuario de acceso por defecto. if [ "$(ogGetOsType $3 $4)" = "Windows" ]; then HOST=$(ogGetHostname) HOST=${HOST:-"pc"} echo "[90] Cambiar nombre Windows a \"$HOST\" y usuario de acceso." ogSetWindowsName $3 $4 "$HOST" #ogSetWinlogonUser $3 $4 " " # Descomentar para cambiar usuario de inicio. fi TIME=$[SECONDS-TIME1] echo "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s"