4513feaf2677002422f390c92a8197eecbde6e07

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

Message

Merge pull request #118 from zertrin/shellcheck_cleaning

- massive cleaning with shellcheck: from 5 errors and 200 warnings to zero
- adding Travis-CI

Diff

This diff is truncated to protect this page.

  1diff --git a/.travis.yml b/.travis.yml
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..875f889ccbe0dea300c8a7efec0f00e750169a23
  4--- /dev/null
  5+++ b/.travis.yml
  6@@ -0,0 +1,18 @@
  7+language: bash
  8+
  9+# Use container-based infrastructure for quicker build start-up
 10+sudo: false
 11+
 12+addons:
 13+  apt:
 14+    sources:
 15+    - debian-sid
 16+    packages:
 17+    - shellcheck
 18+
 19+script:
 20+  - shellcheck -e SC2153 duplicity-backup.sh
 21+  - shellcheck -e SC2034 duplicity-backup.conf.example
 22+
 23+matrix:
 24+  fast_finish: true
 25diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example
 26index 763a8181131529c2c6e79dbfdfd79e420bdef3e3..b48dd082eb5e338f77f50780c0eec57978e1a9b3 100644
 27--- a/duplicity-backup.conf.example
 28+++ b/duplicity-backup.conf.example
 29@@ -354,7 +354,7 @@ CLEAN_UP_VARIABLE="4"
 30 # just makes it easier for me to read them and delete them as needed.
 31 
 32 LOGDIR="/home/foobar_user_name/logs/test2/"
 33-LOG_FILE="duplicity-`date +%Y-%m-%d_%H-%M`.txt"
 34+LOG_FILE="duplicity-$(date +%Y-%m-%d_%H-%M).txt"
 35 LOG_FILE_OWNER="foobar_user_name:foobar_user_name"
 36 
 37 # Note that if the configured LOGDIR does not exist it will be created
 38diff --git a/duplicity-backup.sh b/duplicity-backup.sh
 39index 94e16dbd3184d78dc9af903a1b8f4b3ae7fa01ea..cc28ebbdd6ee31c2241bb80dc0e2ff851418f163 100755
 40--- a/duplicity-backup.sh
 41+++ b/duplicity-backup.sh
 42@@ -44,7 +44,7 @@ CONFIG="duplicity-backup.conf"
 43 
 44 usage(){
 45 echo "USAGE:
 46-    `basename $0` [options]
 47+  $(basename "$0") [options]
 48 
 49   Options:
 50     -c, --config CONFIG_FILE   specify the config file to use
 51@@ -73,8 +73,8 @@ echo "USAGE:
 52   CURRENT SCRIPT VARIABLES:
 53   ========================
 54     DEST (backup destination)       = ${DEST}
 55-    INCLIST (directories included)  = ${INCLIST[@]:0}
 56-    EXCLIST (directories excluded)  = ${EXCLIST[@]:0}
 57+    INCLIST (directories included)  = ${INCLIST[*]:0}
 58+    EXCLIST (directories excluded)  = ${EXCLIST[*]:0}
 59     ROOT (root directory of backup) = ${ROOT}
 60     LOGFILE (log file path)         = ${LOGFILE}
 61 "
 62@@ -88,45 +88,45 @@ while getopts ":c:t:bfvlsnd-:" opt; do
 63     # parse long options (a bit tricky because builtin getopts does not
 64     # manage long options and I don't want to impose GNU getopt dependancy)
 65     -)
 66-      case "$OPTARG" in
 67+      case "${OPTARG}" in
 68         # --restore [restore dest]
 69         restore)
 70-          COMMAND=$OPTARG
 71+          COMMAND=${OPTARG}
 72           # We try to find the optional value [restore dest]
 73           if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
 74             RESTORE_DEST=${!OPTIND}
 75-            OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
 76+            OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing
 77           fi
 78         ;;
 79         # --restore-file [file to restore] [restore dest]
 80         # --restore-dir [path to restore] [restore dest]
 81         restore-file|restore-dir)
 82-          COMMAND=$OPTARG
 83+          COMMAND=${OPTARG}
 84           # We try to find the first optional value [file to restore]
 85           if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
 86             FILE_TO_RESTORE=${!OPTIND}
 87-            OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
 88+            OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing
 89           else
 90             continue # no value for the restore-file option, skip the rest
 91           fi
 92           # We try to find the second optional value [restore dest]
 93           if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
 94             RESTORE_DEST=${!OPTIND}
 95-            OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
 96+            OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing
 97           fi
 98         ;;
 99         config) # set the config file from the command line
100           # We try to find the config file
101           if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
102             CONFIG=${!OPTIND}
103-            OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
104+            OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing
105           fi
106         ;;
107         time) # set the restore time from the command line
108           # We try to find the restore time
109           if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
110             TIME=${!OPTIND}
111-            OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
112+            OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing
113           fi
114         ;;
115         dry-run)
116@@ -136,13 +136,13 @@ while getopts ":c:t:bfvlsnd-:" opt; do
117           ECHO=$(which echo)
118         ;;
119         *)
120-          COMMAND=$OPTARG
121+          COMMAND=${OPTARG}
122         ;;
123         esac
124     ;;
125     # here are parsed the short options
126-    c) CONFIG=$OPTARG;; # set the config file from the command line
127-    t) TIME=$OPTARG;; # set the restore time from the command line
128+    c) CONFIG=${OPTARG};; # set the config file from the command line
129+    t) TIME=${OPTARG};; # set the restore time from the command line
130     b) COMMAND="backup";;
131     f) COMMAND="full";;
132     v) COMMAND="verify";;
133@@ -151,29 +151,29 @@ while getopts ":c:t:bfvlsnd-:" opt; do
134     n) DRY_RUN="--dry-run ";; # dry run
135     d) ECHO=$(which echo);; # debug
136     :)
137-      echo "Option -$OPTARG requires an argument." >&2
138+      echo "Option -${OPTARG} requires an argument." >&2
139       COMMAND=""
140     ;;
141     \?)