#!/bin/sh

# listTarFile - List the contents of tar backup file to make sure it was
#               written properly to the ACTBKP DVD
#
# Usage: listTarFile <archive> <logfile>
# This script must be run by a user with appropriate privileges (e.g., root)
#
# archive: the filename of the backup archive
# logfile: the filename of the log file to create
#
# Return Codes:
# 1 - tar error


ARCHIVE=$1
LOG=$2


# Start log
echo -e "-> listing backup tar file `date`\n" >> $LOG

#Make sure to remount the DVD before running the tar -tvjf command
umount /media/cdrom
mount /media/cdrom
echo -e "media device was properly remounted \n" >> $LOG

if !(tar -tvjf $ARCHIVE > /tmp/testtarlog 2>&1); then
    echo -e "tar: Error listing tar file contents \n" >> $LOG
    cat /tmp/testtarlog >> $LOG
    echo -e "<- listing backup tar file ended with errors `date`\n" >> $LOG
    exit 1
fi
echo -e "backup tar file was successful tested.\n" >> $LOG
echo -e "<- listing backup tar file ended without errors `date`\n" >> $LOG

exit 0