From df6cf31242061a6367fa134d64aeba07cf674a5d Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Mon, 16 Dec 2013 17:17:02 +0100 Subject: [PATCH] =?UTF-8?q?Implemented=20options=20and=20arguments=20to=20?= =?UTF-8?q?=C3=96vning=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Labb5/ovning5.sh | 55 +++++++++++++++++++++++++++++++++--------- Labb5/ovning5_todo.txt | 2 ++ 2 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 Labb5/ovning5_todo.txt diff --git a/Labb5/ovning5.sh b/Labb5/ovning5.sh index 0f36991..9c51973 100755 --- a/Labb5/ovning5.sh +++ b/Labb5/ovning5.sh @@ -7,27 +7,58 @@ # Set some variabels BackupTo="$HOME/backups/" - -# Set our binarys +declare Verbose Tar="/bin/tar" +# Help screens +short_usage() +{ + echo "Usage: `basename $0` -b -f -o -v -h" +} + +long_usage() +{ + short_usage + cat <<- EOF + -b Directory to make a backup of + -f Optional tar output filename (default is the name of the directory) + -o Optional directory to put the backup in (default is \$HOME/backups) + -v Turn on tar -v (Verbose) + -h This help + EOF +} + +# Parse arguments and options +while getopts b:f:o:vh Opt; do + case "$Opt" in + b) BackupThis=$OPTARG + ;; + f) File=$OPTARG + ;; + o) BackupTo=$OPTARG + ;; + v) Verbose=v + ;; + h) long_usage + ;; + *) short_usage + ;; + esac +done + # Sanity checks -if [ $# -ne 1 ]; then - echo "Usage: $0 " - exit 2 -fi - if [ ! -w $BackupTo ] || [ ! -d $BackupTo ]; then - echo "Can't write to $BackupTo or doesn't exist" > /dev/stderr + echo "Can't write to $BackupTo or $BackupTo doesn't exist" > /dev/stderr exit 2 fi -if [ ! -r "$1" ]; then - echo "Can't read $1" +if [ ! -r $BackupThis ]; then + echo "Can't read $BackupThis" exit 2 fi -# Main -$Tar cvf ${BackupTo}`basename $1`.tar $1 +# Main (do the actual backup) + +$Tar cf$Verbose ${BackupTo}/`basename $BackupThis`.tar $BackupThis exit 0 diff --git a/Labb5/ovning5_todo.txt b/Labb5/ovning5_todo.txt new file mode 100644 index 0000000..50fe186 --- /dev/null +++ b/Labb5/ovning5_todo.txt @@ -0,0 +1,2 @@ +[ ] Check if backup.tar already exist (we don't want to overwrite it) +[ ]