diff --git a/.travis.yml b/.travis.yml index 7cc5202..f004410 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ addons: - shellcheck script: - - shellcheck -e SC2034 -e SC2166 duplicity-backup.sh duplicity-backup.conf.example + - shellcheck -e SC2034 duplicity-backup.sh duplicity-backup.conf.example matrix: fast_finish: true diff --git a/duplicity-backup.sh b/duplicity-backup.sh index fc771a3..0dba351 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -97,7 +97,7 @@ while getopts ":c:t:bfvelsnd-:" opt; do restore) COMMAND=${OPTARG} # We try to find the optional value [restore dest] - if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then + if [ ! -z "${!OPTIND:0:1}" ] && [ ! "${!OPTIND:0:1}" = "-" ]; then RESTORE_DEST=${!OPTIND} OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing fi @@ -107,28 +107,28 @@ while getopts ":c:t:bfvelsnd-:" opt; do restore-file|restore-dir) COMMAND=${OPTARG} # We try to find the first optional value [file to restore] - if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then + if [ ! -z "${!OPTIND:0:1}" ] && [ ! "${!OPTIND:0:1}" = "-" ]; then FILE_TO_RESTORE=${!OPTIND} OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing else continue # no value for the restore-file option, skip the rest fi # We try to find the second optional value [restore dest] - if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then + if [ ! -z "${!OPTIND:0:1}" ] && [ ! "${!OPTIND:0:1}" = "-" ]; then RESTORE_DEST=${!OPTIND} OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing fi ;; config) # set the config file from the command line # We try to find the config file - if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then + if [ ! -z "${!OPTIND:0:1}" ] && [ ! "${!OPTIND:0:1}" = "-" ]; then CONFIG=${!OPTIND} OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing fi ;; time) # set the restore time from the command line # We try to find the restore time - if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then + if [ ! -z "${!OPTIND:0:1}" ] && [ ! "${!OPTIND:0:1}" = "-" ]; then TIME=${!OPTIND} OPTIND=$(( OPTIND + 1 )) # we found it, move forward in arg parsing fi @@ -167,7 +167,7 @@ while getopts ":c:t:bfvelsnd-:" opt; do done # Read config file if specified -if [ ! -z "${CONFIG}" -a -f "${CONFIG}" ]; +if [ ! -z "${CONFIG}" ] && [ -f "${CONFIG}" ]; then # shellcheck source=duplicity-backup.conf.example . "${CONFIG}" @@ -214,7 +214,7 @@ if [ "${ENCRYPTION}" = "yes" ]; then if [ ! -z "${GPG_ENC_KEY}" ] && [ ! -z "${GPG_SIGN_KEY}" ]; then if [ "${HIDE_KEY_ID}" = "yes" ]; then ENCRYPT="--hidden-encrypt-key=${GPG_ENC_KEY}" - if [ "${COMMAND}" != "restore" -a "${COMMAND}" != "restore-file" -a "${COMMAND}" != "restore-dir" ]; then + if [ "${COMMAND}" != "restore" ] && [ "${COMMAND}" != "restore-file" ] && [ "${COMMAND}" != "restore-dir" ]; then ENCRYPT="${ENCRYPT} --sign-key=${GPG_SIGN_KEY}" fi else @@ -270,10 +270,10 @@ if [ "$(echo "${DEST}" | cut -c 1,2)" = "s3" ]; then S3CMD="$(which s3cmd)" if [ ! -x "${S3CMD}" ]; then echo "${NO_S3CMD}"; S3CMD_AVAIL=false - elif [ -z "${S3CMD_CONF_FILE}" -a ! -f "${HOME}/.s3cfg" ]; then + elif [ -z "${S3CMD_CONF_FILE}" ] && [ ! -f "${HOME}/.s3cfg" ]; then S3CMD_CONF_FOUND=false echo "${NO_S3CMD_CFG}"; S3CMD_AVAIL=false - elif [ ! -z "${S3CMD_CONF_FILE}" -a ! -f "${S3CMD_CONF_FILE}" ]; then + elif [ ! -z "${S3CMD_CONF_FILE}" ] && [ ! -f "${S3CMD_CONF_FILE}" ]; then S3CMD_CONF_FOUND=false echo "${S3CMD_CONF_FILE} not found, check S3CMD_CONF_FILE variable in duplicity-backup's configuration!"; echo "${NO_S3CMD_CFG}"; @@ -281,7 +281,7 @@ if [ "$(echo "${DEST}" | cut -c 1,2)" = "s3" ]; then else S3CMD_AVAIL=true S3CMD_CONF_FOUND=true - if [ ! -z "${S3CMD_CONF_FILE}" -a -f "${S3CMD_CONF_FILE}" ]; then + if [ ! -z "${S3CMD_CONF_FILE}" ] && [ -f "${S3CMD_CONF_FILE}" ]; then # if conf file specified and it exists then add it to the command line for s3cmd S3CMD="${S3CMD} -c ${S3CMD_CONF_FILE}" fi @@ -654,7 +654,7 @@ duplicity_cleanup_failed() setup_passphrase() { - if [ ! -z "${GPG_ENC_KEY}" -a ! -z "${GPG_SIGN_KEY}" -a "${GPG_ENC_KEY}" != "${GPG_SIGN_KEY}" ]; then + if [ ! -z "${GPG_ENC_KEY}" ] && [ ! -z "${GPG_SIGN_KEY}" ] && [ "${GPG_ENC_KEY}" != "${GPG_SIGN_KEY}" ]; then echo -n "Please provide the passphrase for decryption (GPG key 0x${GPG_ENC_KEY}): " builtin read -s -r ENCPASSPHRASE echo -ne "\n" @@ -702,7 +702,7 @@ backup_this_script() echo "You are backing up: " echo " 1. ${SCRIPTPATH}" - if [ ! -z "${GPG_ENC_KEY}" -a ! -z "${GPG_SIGN_KEY}" ]; then + if [ ! -z "${GPG_ENC_KEY}" ] && [ ! -z "${GPG_SIGN_KEY}" ]; then if [ "${GPG_ENC_KEY}" = "${GPG_SIGN_KEY}" ]; then echo " 2. GPG Secret encryption and sign key: ${GPG_ENC_KEY}" else @@ -712,12 +712,12 @@ backup_this_script() echo " 2. GPG Secret encryption and sign key: none (symmetric encryption)" fi - if [ ! -z "${CONFIG}" -a -f "${CONFIG}" ]; + if [ ! -z "${CONFIG}" ] && [ -f "${CONFIG}" ]; then echo " 3. Config file: ${CONFIG}" fi - if [ ! -z "${INCEXCFILE}" -a -f "${INCEXCFILE}" ]; + if [ ! -z "${INCEXCFILE}" ] && [ -f "${INCEXCFILE}" ]; then echo " 4. Include/Exclude globbing file: ${INCEXCFILE}" fi @@ -734,17 +734,17 @@ backup_this_script() mkdir -p "${TMPDIR}" cp "${SCRIPTPATH}" "${TMPDIR}"/ - if [ ! -z "${CONFIG}" -a -f "${CONFIG}" ]; + if [ ! -z "${CONFIG}" ] && [ -f "${CONFIG}" ]; then cp "${CONFIG}" "${TMPDIR}"/ fi - if [ ! -z "${INCEXCFILE}" -a -f "${INCEXCFILE}" ]; + if [ ! -z "${INCEXCFILE}" ] && [ -f "${INCEXCFILE}" ]; then cp "${INCEXCFILE}" "${TMPDIR}"/ fi - if [ ! -z "${GPG_ENC_KEY}" -a ! -z "${GPG_SIGN_KEY}" ]; then + if [ ! -z "${GPG_ENC_KEY}" ] && [ ! -z "${GPG_SIGN_KEY}" ]; then GPG_TTY=$(tty) export GPG_TTY if [ "${GPG_ENC_KEY}" = "${GPG_SIGN_KEY}" ]; then