#!/bin/bash # # ./fastback-unload-receipt RECEIPT # where RECEIPT is the name of the file containing the receipt # output by fastback # # will check the md5sum of the file, and decript it if it is encrypted # the file must have already been downloaded to the local directory # RECEIPT=$1 if [ "$2" = "" ]; then DO_FETCH=false elif [ "$2" = "fetch" ]; then DO_FETCH=true else echo >&2 "Error: invalid second argument: $2" exit 2 fi if [ ! -e $RECEIPT ]; then echo >&2 "Error: no such file $RECEIPT" exit 2 fi cat $RECEIPT | while read FIRST REST ; do #echo "FIRST:" $FIRST #echo "REST:" $REST if [ "$FIRST" = "FILE:" ]; then export FILE=$REST if [ -z "$FILE" ]; then echo >&2 "Error: file name missing from \"FILE:\" line" exit 2 fi #echo found FILE: $FILE fi if [ "$FIRST" = "MD5SUM:" ]; then if ! read MD5LINE; then echo >&2 "Error: unable to read MD5SUM" exit 2 fi #echo found MD5LINE: $MD5LINE fi if [ "$FIRST" = "KEY:" ]; then KEYCODE=$REST if [ -z "$KEYCODE" ]; then echo >&2 "Error: key code name missing from \"KEY:\" line" exit 2 fi if ! read KEYLINE; then echo >&2 "Error: unable to read encryption key" exit 2 fi #echo found KEY: $KEYCODE $KEYLINE fi if [ "$FIRST" = "END:" ]; then if [ -z "$FILE" ]; then echo >&2 "Error: no file name found in receipt: $RECEIPT" exit 2 fi if $DO_FETCH; then ./fetch-from-indus $FILE fi if [ -z "$MD5LINE" ]; then echo >&2 "Error: no md5sum found in receipt: $RECEIPT" exit 2 else #echo "MD5LINE:$MD5LINE" echo "\"md5sum --check\" reports:" echo "$MD5LINE" | md5sum --check - fi if [ ! -z "$KEYLINE" ]; then OUTFILE=${FILE%.aes} if [ "$OUTFILE" = "$FILE" ]; then OUTFILE=$FILE.decoded fi if openssl $KEYCODE -d -in $FILE -out $OUTFILE -pass pass:$KEYLINE; then echo decode file writen to $OUTFILE fi fi fi done