Fix shellcheck error SC2166

This commit is contained in:
zertrin 2016-09-03 15:16:17 +02:00
parent 6b7c1c66b2
commit 17e40b3c67
2 changed files with 18 additions and 18 deletions

View file

@ -11,7 +11,7 @@ addons:
- shellcheck - shellcheck
script: script:
- shellcheck -e SC2034 -e SC2166 duplicity-backup.sh duplicity-backup.conf.example - shellcheck -e SC2034 duplicity-backup.sh duplicity-backup.conf.example
matrix: matrix:
fast_finish: true fast_finish: true

View file

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