| 1 | #!/bin/bash |
|---|
| 2 | # Script 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 session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]" |
|---|
| 9 | exit $? |
|---|
| 10 | fi |
|---|
| 11 | |
|---|
| 12 | #Load engine configurator from engine.cfg file. |
|---|
| 13 | #Carga el configurador del engine desde el fichero engine.cfg |
|---|
| 14 | # Valores por defecto: #IMGPROG="partclone" ; #IMGCOMP="lzop" ; #IMGEXT="img" #IMGREDUCE="TRUE" |
|---|
| 15 | [ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg |
|---|
| 16 | |
|---|
| 17 | # Clear temporary file used as log track by httpdlog |
|---|
| 18 | # Limpia los ficheros temporales usados como log de seguimiento para httpdlog |
|---|
| 19 | echo " " > $OGLOGCOMMAND |
|---|
| 20 | [ "$(ogGetCaller)" == "deployImage" ] || echo -n "" > $OGLOGSESSION; |
|---|
| 21 | |
|---|
| 22 | ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*" |
|---|
| 23 | |
|---|
| 24 | # Procesar parámetros de entrada |
|---|
| 25 | REPO="${1^^}" |
|---|
| 26 | IMGNAME="$2" |
|---|
| 27 | DISK="$3" |
|---|
| 28 | PART="$4" |
|---|
| 29 | PROTO="${5^^}" |
|---|
| 30 | PROTO=${PROTO:-"UNICAST"} |
|---|
| 31 | PROTOOPT="$6" |
|---|
| 32 | IMGTYPE="${IMGTYPE:-"img"}" |
|---|
| 33 | # Comprobar que existe la imagen del origen. |
|---|
| 34 | IMGFILE=$(ogGetPath "$REPO" "$IMGNAME.$IMGTYPE") |
|---|
| 35 | IMGDIR=$(ogGetParentPath "$REPO" "$IMGNAME") |
|---|
| 36 | if [ "$IMGFILE" == "" -o "$IMGDIR" == "" ]; then |
|---|
| 37 | ogRaiseError session $OG_ERR_NOTFOUND "$REPO, ${IMGNAME%/*}" |
|---|
| 38 | exit $? |
|---|
| 39 | fi |
|---|
| 40 | |
|---|
| 41 | # Procesar protocolos de transferencia. |
|---|
| 42 | case "$PROTO" in |
|---|
| 43 | UNICAST|UNICAST-DIRECT) |
|---|
| 44 | # Restaurar la imagen. |
|---|
| 45 | ogEcho log session "[40] ogRestoreImage $REPO $IMGNAME $DISK $PART UNICAST" |
|---|
| 46 | ogExecAndLog command ogRestoreImage "$REPO" "$IMGNAME" "$DISK" "$PART" |
|---|
| 47 | RETVAL=$? |
|---|
| 48 | ;; |
|---|
| 49 | MULTICAST|MULTICAST-DIRECT) |
|---|
| 50 | PORT=$(echo $PROTOOPT | cut -f1 -d":") |
|---|
| 51 | TOOL=$(ogGetImageProgram REPO $IMGNAME) |
|---|
| 52 | COMPRESS=$(ogGetImageCompressor REPO $IMGNAME) |
|---|
| 53 | #TODO comprobar parametros anteriores |
|---|
| 54 | ogEcho log session "[40] ogMcastReceiverPartition $DISK $PART $PORT $TOOL $COMPRESS" |
|---|
| 55 | ogMcastRequest "$IMGNAME.img" "$PROTOOPT" |
|---|
| 56 | ogExecAndLog command ogMcastReceiverPartition "$DISK" "$PART" "$PORT" "$TOOL" "$COMPRESS" |
|---|
| 57 | RETVAL=${PIPESTATUS[0]} |
|---|
| 58 | ;; |
|---|
| 59 | *) # Protocolo desconocido. |
|---|
| 60 | ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones ]" |
|---|
| 61 | exit $? |
|---|
| 62 | esac |
|---|
| 63 | |
|---|
| 64 | TIME=$[SECONDS-TIME1] |
|---|
| 65 | ogEcho log session "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s" |
|---|
| 66 | |
|---|
| 67 | # Código de salida del comando prinicpal de restauración. |
|---|
| 68 | exit $RETVAL |
|---|
| 69 | |
|---|