Skip to content
Snippets Groups Projects
Commit 4efdf3c4 authored by Jens Steidl's avatar Jens Steidl :baby_chick:
Browse files

- refactor: spellcheck SC2292 (https://github.com/koalaman/shellcheck/wiki/SC2292)

parent f5584a05
No related branches found
No related tags found
No related merge requests found
Pipeline #4978 passed
......@@ -108,7 +108,7 @@ set -e
check_argument_count() {
local count="$1"
local expected="$2"
if [ "${count}" -ne "${expected}" ]; then
if [[ "${count}" -ne "${expected}" ]]; then
error "called function ${FUNCNAME[1]} expected ${expected} params, but got ${count} by caller function ${FUNCNAME[2]} (line ${BASH_LINENO[2]})"
exit 1
fi
......@@ -116,7 +116,7 @@ check_argument_count() {
check_argument_notempty() {
local param="$1"
if [ -z "${param}" ]; then
if [[ -z "${param}" ]]; then
error "called function ${FUNCNAME[1]} expected non-empty params, but some are empty set in line ${BASH_LINENO[0]}, eventually taken from caller function ${FUNCNAME[1]} (line ${BASH_LINENO[1]})"
exit 1
fi
......@@ -174,7 +174,7 @@ trim_statistics() {
}
debug() {
if [ "${WITH_DEBUG}" -eq 1 ]; then
if [[ "${WITH_DEBUG}" -eq 1 ]]; then
>&2 echo "DEBUG: $1"
fi
}
......@@ -264,67 +264,67 @@ get_cli_args() {
;;
esac
done
if [ "${FILES_MODE}" != "sort" ] && [ "${FILES_MODE}" != "delete" ] && [ "${FILES_MODE}" != "nothing" ]; then
if [[ "${FILES_MODE}" != "sort" ]] && [[ "${FILES_MODE}" != "delete" ]] && [[ "${FILES_MODE}" != "nothing" ]]; then
error "param --files-mode must be 'sort', 'delete' or 'nothing'!"
exit 1
fi
if [ "${MODE}" != "auto" ] \
&& [ "${MODE}" != "mediathek" ] \
&& [ "${MODE}" != "fotothek" ] \
&& [ "${MODE}" != "save" ] \
&& [ "${MODE}" != "ddz" ] \
&& [ "${MODE}" != "digas" ]; then
if [[ "${MODE}" != "auto" ]] \
&& [[ "${MODE}" != "mediathek" ]] \
&& [[ "${MODE}" != "fotothek" ]] \
&& [[ "${MODE}" != "save" ]] \
&& [[ "${MODE}" != "ddz" ]] \
&& [[ "${MODE}" != "digas" ]]; then
error "param --mode must be 'auto', 'mediathek', 'fotothek', 'save', 'ddz' or 'digas'!"
exit 1
fi
if [ "${WITH_PIPE}" -eq 1 ]; then
if [[ "${WITH_PIPE}" -eq 1 ]]; then
if
[ "${WITH_DAEMON}" -eq 1 ] \
|| [ -n "${WATCH_FOLDER}" ] \
|| [ -n "${RESULT_FOLDER}" ] \
|| [ -n "${VALID_FOLDER}" ] \
|| [ -n "${INVALID_FOLDER}" ] \
|| [ "${FILES_MODE}" = "sort" ] \
[[ "${WITH_DAEMON}" -eq 1 ]] \
|| [[ -n "${WATCH_FOLDER}" ]] \
|| [[ -n "${RESULT_FOLDER}" ]] \
|| [[ -n "${VALID_FOLDER}" ]] \
|| [[ -n "${INVALID_FOLDER}" ]] \
|| [[ "${FILES_MODE}" = "sort" ]] \
; then
error "param --pipe not combinable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode"
exit 1
fi
else
if [ "${WITH_DAEMON}" -eq 1 ] && [ "${FILES_MODE}" = "sort" ]; then
if [[ "${WITH_DAEMON}" -eq 1 ]] && [[ "${FILES_MODE}" = "sort" ]]; then
error "param --daemon does only work with param --mode='delete' or --mode='nothing'!"
exit 1
fi
if [ "${STAGE}" != "current" ] && [ "${STAGE}" != "upcoming" ] && [ "${STAGE}" != "any" ]; then
if [[ "${STAGE}" != "current" ]] && [[ "${STAGE}" != "upcoming" ]] && [[ "${STAGE}" != "any" ]]; then
error "--param stage must be 'any', 'current' or 'upcoming'!"
exit 1
fi
if [ ! -d "${WATCH_FOLDER}" ]; then
if [[ ! -d "${WATCH_FOLDER}" ]]; then
error "watch folder '${WATCH_FOLDER}' does not exist!"
exit 1
fi
if [ ! -d "${RESULT_FOLDER}" ]; then
if [[ ! -d "${RESULT_FOLDER}" ]]; then
error "result folder '${RESULT_FOLDER}' does not exist!"
exit 1
fi
if [ "${FILES_MODE}" = "sort" ]; then
if [ ! -d "${VALID_FOLDER}" ]; then
if [[ "${FILES_MODE}" = "sort" ]]; then
if [[ ! -d "${VALID_FOLDER}" ]]; then
error "valid folder '${VALID_FOLDER}' does not exist!"
exit 1
fi
if [ ! -d "${INVALID_FOLDER}" ]; then
if [[ ! -d "${INVALID_FOLDER}" ]]; then
error "invalid folder '${INVALID_FOLDER}' does not exist!"
exit 1
fi
fi
fi
cachedir=$(dirname "${STATFILE}")
if [ ! -d "${cachedir}" ]; then
if [[ ! -d "${cachedir}" ]]; then
mkdir -p "${cachedir}" || error "Could not create dir ${cachedir}, $?"
fi
if [ -e "${STATFILE}" ]; then
if [[ -e "${STATFILE}" ]]; then
lines=$( flock -x "${LOCKFILE}" wc -l "${STATFILE}" | cut -d " " -f 1)
debug "found ${lines} lines in ${STATFILE})"
if [ "${lines}" -gt "${MAX_STAT_LINES}" ]; then
if [[ "${lines}" -gt "${MAX_STAT_LINES}" ]]; then
(
flock -n 9 || exit 1
trim_statistics
......@@ -442,15 +442,15 @@ handle_input_if_requested() {
check_argument_notempty "${filename}"
check_argument_notempty "${is_valid}"
debug "handle_input_if_requested, filename=${filename} is_valid=${is_valid}"
if [ "${FILES_MODE}" = "sort" ]; then
if [ "${is_valid}" -eq 0 ]; then
if [[ "${FILES_MODE}" = "sort" ]]; then
if [[ "${is_valid}" -eq 0 ]]; then
debug "handle_input_if_requested, mv ${filename} to ${VALID_FOLDER}, because valid"
mv "${filename}" "${VALID_FOLDER}"
else
debug "handle_input_if_requested, mv ${filename} to ${INVALID_FOLDER}, because invalid"
mv "${filename}" "${INVALID_FOLDER}"
fi
elif [ "${FILES_MODE}" = "delete" ]; then
elif [[ "${FILES_MODE}" = "delete" ]]; then
debug "handle_input_if_requested, rm ${filename} from watch-folder ${WATCH_FOLDER}"
rm -f "${filename}"
fi
......@@ -461,7 +461,7 @@ get_logfile() {
local filename="$1"
local logname
check_argument_notempty "${filename}"
if [ -n "${WATCH_FOLDER}" ] && [ "${WITH_PIPE}" -eq 0 ]; then
if [[ -n "${WATCH_FOLDER}" ]] && [[ "${WITH_PIPE}" -eq 0 ]]; then
logname=$(echo "${filename}"| sed -e "s#^${WATCH_FOLDER}#${RESULT_FOLDER}#" -e "s#\$#.log#")
else # pipe uses a temp filename
logname="${filename}.log"
......@@ -469,7 +469,7 @@ get_logfile() {
check_argument_notempty "${logname}"
logdir=$(dirname "${logname}")
check_argument_notempty "${logdir}"
if [ ! -d "${logdir}" ]; then
if [[ ! -d "${logdir}" ]]; then
debug "get_logfile, mkdir ${logdir}"
mkdir -p "${logdir}"
fi
......@@ -491,7 +491,7 @@ scan_file() {
mimetype=$(get_mimetype "${filename}")
ftype=$(prepare_ftype "${mimetype}")
logname=$(get_logfile "${filename}")
if [ "${MODE}" = "auto" ]; then
if [[ "${MODE}" = "auto" ]]; then
# try best guess
MODE=$(estimate_mode "${mimetype}")
fi
......@@ -500,12 +500,12 @@ scan_file() {
check_argument_notempty "${logname}"
trap "" SIGINT
debug "scan_file, === entering protected area ==="
if [ "${STAGE}" = "any" ]; then
if [[ "${STAGE}" = "any" ]]; then
is_valid=1
for stage in upcoming current; do
cmd=$(prepare_cmd "${MODE}" "${ftype}" "${stage}" | sed -e "s#FILE#${filename}#")
is_valid=$(exec_cmd "${cmd}" "${ftype}" "${MODE}" "${stage}" "${logname}")
if [ "${is_valid}" -eq 0 ]; then
if [[ "${is_valid}" -eq 0 ]]; then
debug "scan_file, early break"
break
else
......@@ -535,7 +535,7 @@ scan_dir() {
get_cli_args "$@"
#trap signalhandler SIGINT SIGABRT #sigint
if [ "${WITH_PIPE}" -eq 1 ]; then
if [[ "${WITH_PIPE}" -eq 1 ]]; then
#cli mode, use stdin
debug "checking stream"
filename=$(mktemp --tmpdir validate_wrg.XXXX)
......@@ -545,7 +545,7 @@ if [ "${WITH_PIPE}" -eq 1 ]; then
rm -f "${filename}.log" || error "could not remove temporary file '${filename}.log'"
rm -f "${filename}" || error "could not remove temporary file '${filename}'"
else
if [ "${WITH_DAEMON}" -eq 1 ]; then
if [[ "${WITH_DAEMON}" -eq 1 ]]; then
# TODO: protect DAEMON from STRG-C for clean shutdown
# echo daemon mode, use inotify to watch changes
debug "starting daemon"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment