diff --git a/Scripts/tar.sh b/Scripts/tar.sh new file mode 100755 index 0000000..15891fe --- /dev/null +++ b/Scripts/tar.sh @@ -0,0 +1,68 @@ +#!/bin/bash +#=============================================================================== +# +# FILE: tar.sh +# USAGE: ./tar.sh +# DESCRIPTION: TAR command as a shell script! +# A bit of a toy/novelty idea to use a script for this +# CREATED: 17/11/2017 +# +#=============================================================================== + +if [ $# -lt 2 ] +then + echo "Usage: $0 (-x) | (-c files) archive.tar" + exit -1 +fi + +if [ x"$1" == x"-x" ] +then + echo "Extracting..." + LINE=0 + LINES=0 + FILE= + cat "$2" | while IFS= read -r TEXT + do + if [ x"$LINES" == x"$LINE" ] + then + LINE=0 + LINES=`echo $TEXT` + read FILE + echo "Extracting $LINES lines from $FILE " + if [ -f $FILE ] + then + echo "$FILE file already exists. Aborting." + exit -1 + fi + else + echo "${TEXT}" >> $FILE + LINE=$(($LINE + 1)) + fi + done + +elif [ x"$1" == x"-c" ] +then + if [ $# -lt 3 ] + then + echo "No files to add" + exit -1 + else + echo "Creating..." + shift + rm -rf .tmp.tar + while [ $# -gt 1 ] + do + echo "Adding $1" + echo "`cat \"$1\" | wc -l`" >> .tmp.tar + echo "$1" >> .tmp.tar + cat "$1" >> .tmp.tar + shift + done + mv .tmp.tar "$1" + echo "Created archive $1" + fi +else + echo "Usage: $0 (-x) | (-c files) archive.tar" + exit -1 +fi +