#!/bin/bash

TARFILE=$1
ERRORMSG="Tar file $TARFILE is in an incorrect format or corrupted and cannot be extracted."

/opt/meru/bin/tar -tf $TARFILE >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo $ERRORMSG
    exit -1
fi

FILELIST=`tar -tf $TARFILE | egrep -v "/$"`

for FILE in $FILELIST; do
    /opt/meru/bin/tar -x $FILE -f $TARFILE
    /opt/meru/bin/tar --delete $FILE -f $TARFILE >/dev/null 2>&1
done

exit 0
