b207b90cba6762307aa24776accdde76e487ca61

Author
zertrin <zertrin@gmail.com>
Committer
zertrin <zertrin@gmail.com>
Date

Message

Add -h / --help option to print usage and don't send email or notification when printing usage only

Diff

 1diff --git a/duplicity-backup.sh b/duplicity-backup.sh
 2index 28aeffce71be11e853c08e80e25cea155ba2a46d..81d19c98db6c682dd8735c696db1d3fa20d88702 100755
 3--- a/duplicity-backup.sh
 4+++ b/duplicity-backup.sh
 5@@ -84,6 +84,7 @@ echo "USAGE:
 6     -n, --dry-run              perform a trial run with no changes made
 7     -d, --debug                echo duplicity commands to logfile
 8     -V, --version              print version information about this script and duplicity
 9+    -h, --help                 print this help and exit
10 
11   CURRENT SCRIPT VARIABLES:
12   ========================
13@@ -93,6 +94,7 @@ echo "USAGE:
14     ROOT (root directory of backup) = ${ROOT}
15     LOGFILE (log file path)         = ${LOGFILE}
16 " >&6
17+USAGE=1
18 }
19 
20 DUPLICITY="$(which duplicity)"
21@@ -114,7 +116,7 @@ version(){
22 # Some expensive argument parsing that allows the script to
23 # be insensitive to the order of appearance of the options
24 # and to handle correctly option parameters that are optional
25-while getopts ":c:t:bfvelsqndV-:" opt; do
26+while getopts ":c:t:bfvelsqndhV-:" opt; do
27   case $opt in
28     # parse long options (a bit tricky because builtin getopts does not
29     # manage long options and I don't want to impose GNU getopt dependancy)
30@@ -169,6 +171,10 @@ while getopts ":c:t:bfvelsqndV-:" opt; do
31         debug)
32           ECHO=$(which echo)
33         ;;
34+        help)
35+          usage
36+          exit 0
37+        ;;
38         version)
39           version
40         ;;
41@@ -189,6 +195,10 @@ while getopts ":c:t:bfvelsqndV-:" opt; do
42     q) QUIET=1;;
43     n) DRY_RUN="--dry-run ";; # dry run
44     d) ECHO=$(which echo);; # debug
45+    h)
46+      usage
47+      exit 0
48+    ;;
49     V) version;;
50     :)
51       echo "Option -${OPTARG} requires an argument." >&2
52@@ -1026,6 +1036,10 @@ esac
53 
54 echo -e "---------    END DUPLICITY-BACKUP SCRIPT    ---------\n" >&5
55 
56+if [ "${USAGE}" ]; then
57+  exit 0
58+fi
59+
60 if [ "${BACKUP_ERROR}" ]; then
61   BACKUP_STATUS="ERROR"
62 else