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