Skip to content
Snippets Groups Projects
Commit 5ee8d668 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- fixed shellcheck warnings

parent 293e1792
Branches
No related tags found
No related merge requests found
...@@ -105,15 +105,15 @@ set -e ...@@ -105,15 +105,15 @@ 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
} }
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
...@@ -125,7 +125,7 @@ comment_help() { ...@@ -125,7 +125,7 @@ comment_help() {
} }
calc_statistics() { calc_statistics() {
flock -x "$LOCKFILE" cat "$STATFILE" | awk -F "," '{cnt_invalid+=$3;total++} END {print total, cnt_invalid}' flock -x "${LOCKFILE}" cat "${STATFILE}" | awk -F "," '{cnt_invalid+=$3;total++} END {print total, cnt_invalid}'
} }
print_statistics() { print_statistics() {
...@@ -135,14 +135,14 @@ print_statistics() { ...@@ -135,14 +135,14 @@ print_statistics() {
local cnt_invalid local cnt_invalid
local ratio local ratio
stat=$(calc_statistics) stat=$(calc_statistics)
cnt_total=$(echo "$stat" | awk 'END {print $1}') cnt_total=$(echo "${stat}" | awk 'END {print $1}')
cnt_valid=$(echo "$stat" | awk 'END {print $2}') cnt_valid=$(echo "${stat}" | awk 'END {print $2}')
cnt_invalid=$((cnt_total - cnt_valid)) cnt_invalid=$((cnt_total - cnt_valid))
ratio=$(( 100*cnt_valid / cnt_total )) ratio=$(( 100*cnt_valid / cnt_total ))
echo "Validation Statistics" echo "Validation Statistics"
echo "valid files: $cnt_valid" echo "valid files: ${cnt_valid}"
echo "invalid files: $cnt_invalid" echo "invalid files: ${cnt_invalid}"
echo "ratio: $ratio% valid" echo "ratio: ${ratio}% valid"
} }
...@@ -153,25 +153,25 @@ update_statistics() { ...@@ -153,25 +153,25 @@ update_statistics() {
local ftype=$3 local ftype=$3
local workflow=$4 local workflow=$4
local stage=$5 local stage=$5
check_argument_notempty "$is_valid" check_argument_notempty "${is_valid}"
check_argument_notempty "$duration" check_argument_notempty "${duration}"
check_argument_notempty "$ftype" check_argument_notempty "${ftype}"
check_argument_notempty "$workflow" check_argument_notempty "${workflow}"
check_argument_notempty "$stage" check_argument_notempty "${stage}"
local date local date
date=$(date +"%F%T") date=$(date +"%F%T")
debug "date=$date" debug "date=${date}"
flock -x $LOCKFILE echo "$date,$is_valid,$duration,$ftype,$workflow,$stage" >> "$STATFILE" flock -x "${LOCKFILE}" echo "${date},${is_valid},${duration},${ftype},${workflow},${stage}" >> "${STATFILE}"
} }
trim_statistics() { trim_statistics() {
debug "trim_statistics" debug "trim_statistics"
tail -n $MIN_STAT_LINES "$STATFILE" > "$STATFILE.new" || (error "could not trim $STATFILE to $STATFILE.new" ; exit 1 ) tail -n "${MIN_STAT_LINES}" "${STATFILE}" > "${STATFILE}.new" || (error "could not trim ${STATFILE} to ${STATFILE}.new" ; exit 1 )
mv "$STATFILE.new" "$STATFILE" || ( error "count not trim $STATFILE,because could not mv $STATFILE.new to $STATFILE"; exit 1 ) mv "${STATFILE}.new" "${STATFILE}" || ( error "count not trim ${STATFILE},because could not mv ${STATFILE}.new to ${STATFILE}"; exit 1 )
} }
debug() { debug() {
if [ $WITH_DEBUG -eq 1 ]; then if [ "${WITH_DEBUG}" -eq 1 ]; then
>&2 echo "DEBUG: $1" >&2 echo "DEBUG: $1"
fi fi
} }
...@@ -188,10 +188,10 @@ error() { ...@@ -188,10 +188,10 @@ error() {
get_mimetype() { get_mimetype() {
check_argument_count $# 1 check_argument_count $# 1
local filename=$1 local filename=$1
check_argument_notempty "$filename" check_argument_notempty "${filename}"
local res local res
res=$(file --mime-type "$filename" | sed -e "s/^.*: //") res=$(file --mime-type "${filename}" | sed -e "s/^.*: //")
echo "$res" echo "${res}"
} }
...@@ -199,7 +199,7 @@ get_cli_args() { ...@@ -199,7 +199,7 @@ get_cli_args() {
local lines local lines
local cachedir local cachedir
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case ${1} in case $1 in
-h | --help) -h | --help)
comment_help comment_help
exit 0 exit 0
...@@ -213,32 +213,32 @@ get_cli_args() { ...@@ -213,32 +213,32 @@ get_cli_args() {
exit 0 exit 0
;; ;;
-w | --watch-folder) -w | --watch-folder)
WATCH_FOLDER="${2}" WATCH_FOLDER="$2"
shift shift
shift shift
;; ;;
-r | --result-folder) -r | --result-folder)
RESULT_FOLDER="${2}" RESULT_FOLDER="$2"
shift shift
shift shift
;; ;;
-v | --valid-folder) -v | --valid-folder)
VALID_FOLDER="${2}" VALID_FOLDER="$2"
shift shift
shift shift
;; ;;
-i | --invalid-folder) -i | --invalid-folder)
INVALID_FOLDER="${2}" INVALID_FOLDER="$2"
shift shift
shift shift
;; ;;
-m | --mode) -m | --mode)
MODE="${2}" MODE="$2"
shift shift
shift shift
;; ;;
-t | --stage) -t | --stage)
STAGE="${2}" STAGE="$2"
shift shift
shift shift
;; ;;
...@@ -247,7 +247,7 @@ get_cli_args() { ...@@ -247,7 +247,7 @@ get_cli_args() {
shift shift
;; ;;
-f | --files-mode) -f | --files-mode)
FILES_MODE="${2}" FILES_MODE="$2"
shift shift
shift shift
;; ;;
...@@ -256,76 +256,76 @@ get_cli_args() { ...@@ -256,76 +256,76 @@ get_cli_args() {
shift shift
;; ;;
*) *)
error "'${1}' is invalid param. Please, give '$(basename "${0}") --help' a chance!" error "'$1' is invalid param. Please, give '$(basename "$0") --help' a chance!"
exit 1 exit 1
;; ;;
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 combineable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode" error "param --pipe not combineable 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
) 9>"$LOCKFILE" ) 9>"${LOCKFILE}"
fi fi
fi fi
} }
...@@ -335,21 +335,21 @@ prepare_cmd() { ...@@ -335,21 +335,21 @@ prepare_cmd() {
local mode=$1 local mode=$1
local ftype=$2 local ftype=$2
local stage=$3 local stage=$3
check_argument_notempty "$mode" check_argument_notempty "${mode}"
check_argument_notempty "$ftype" check_argument_notempty "${ftype}"
check_argument_notempty "$stage" check_argument_notempty "${stage}"
local key local key
local cmd local cmd
key=$(printf "%11s%4s%9s" "$mode" "$ftype" "$stage"|sed -e "y/ /_/") key=$(printf "%11s%4s%9s" "${mode}" "${ftype}" "${stage}"|sed -e "y/ /_/")
check_argument_notempty "$key" check_argument_notempty "${key}"
debug "prepare_cmd, key=$key" debug "prepare_cmd, key=${key}"
if [[ ${validators[$key]:+1} ]]; then if [[ -n ${validators[${key}]:+1} ]]; then
cmd=${validators[$key]}; cmd=${validators[${key}]};
check_argument_notempty "$cmd" check_argument_notempty "${cmd}"
debug "prepare_cmd, cmd=$cmd" debug "prepare_cmd, cmd=${cmd}"
echo "$cmd" echo "${cmd}"
else else
debug "no valid command found using key $key" debug "no valid command found using key ${key}"
echo "echo 'no validation tool detected!'" echo "echo 'no validation tool detected!'"
fi fi
} }
...@@ -357,9 +357,9 @@ prepare_cmd() { ...@@ -357,9 +357,9 @@ prepare_cmd() {
prepare_ftype() { prepare_ftype() {
check_argument_count $# 1 check_argument_count $# 1
local mimetype=$1 local mimetype=$1
check_argument_notempty "$mimetype" check_argument_notempty "${mimetype}"
local ftype local ftype
debug "prepare_ftype, using mimetype: $mimetype" debug "prepare_ftype, using mimetype: ${mimetype}"
case ${mimetype} in case ${mimetype} in
"image/tiff") "image/tiff")
ftype="tif" ftype="tif"
...@@ -371,20 +371,20 @@ prepare_ftype() { ...@@ -371,20 +371,20 @@ prepare_ftype() {
ftype="icc" ftype="icc"
;; ;;
*) *)
warn "unknown file format with mime-type '$mimetype'" warn "unknown file format with mime-type '${mimetype}'"
ftype="???" ftype="???"
;; ;;
esac esac
check_argument_notempty "$ftype" check_argument_notempty "${ftype}"
debug "prepare_ftype, detect ftype: $ftype" debug "prepare_ftype, detect ftype: ${ftype}"
echo "$ftype" echo "${ftype}"
} }
estimate_mode() { estimate_mode() {
check_argument_count $# 1 check_argument_count $# 1
local mimetype=$1 local mimetype=$1
check_argument_notempty "$mimetype" check_argument_notempty "${mimetype}"
debug "estimate_mode, using mimetype: $mimetype" debug "estimate_mode, using mimetype: ${mimetype}"
case ${mimetype} in case ${mimetype} in
"image/tiff") "image/tiff")
MODE="ddz" MODE="ddz"
...@@ -396,13 +396,13 @@ estimate_mode() { ...@@ -396,13 +396,13 @@ estimate_mode() {
MODE="ddz" MODE="ddz"
;; ;;
*) *)
warn "workflow not detectable for mimetype $mimetype" warn "workflow not detectable for mimetype ${mimetype}"
MODE="???" MODE="???"
;; ;;
esac esac
check_argument_notempty "$MODE" check_argument_notempty "${MODE}"
debug "estimate_mode, detected mode: $MODE" debug "estimate_mode, detected mode: ${MODE}"
echo "$MODE" echo "${MODE}"
} }
exec_cmd() { exec_cmd() {
...@@ -414,41 +414,41 @@ exec_cmd() { ...@@ -414,41 +414,41 @@ exec_cmd() {
local log=$5 local log=$5
local start_t local start_t
local stop_t local stop_t
check_argument_notempty "$cmd" check_argument_notempty "${cmd}"
check_argument_notempty "$ftype" check_argument_notempty "${ftype}"
check_argument_notempty "$workflow" check_argument_notempty "${workflow}"
check_argument_notempty "$stage" check_argument_notempty "${stage}"
check_argument_notempty "$log" check_argument_notempty "${log}"
start_t=$(date +"%s") start_t=$(date +"%s")
debug "scan_file, calling cmd='$cmd'" debug "scan_file, calling cmd='${cmd}'"
$cmd >>"$log" 2>&1 ${cmd} >>"${log}" 2>&1
local is_valid=$? local is_valid=$?
check_argument_notempty $is_valid check_argument_notempty "${is_valid}"
stop_t=$(date +"%s") stop_t=$(date +"%s")
local duration=$((stop_t - start_t)) local duration=$((stop_t - start_t))
debug "exec_cmd, duration=$duration is_valid=$is_valid log=$log" debug "exec_cmd, duration=${duration} is_valid=${is_valid} log=${log}"
update_statistics "$is_valid" "$duration" "$ftype" "$workflow" "$stage" update_statistics "${is_valid}" "${duration}" "${ftype}" "${workflow}" "${stage}"
echo "$is_valid" echo "${is_valid}"
} }
handle_input_if_requested() { handle_input_if_requested() {
check_argument_count $# 2 check_argument_count $# 2
local filename=$1 local filename=$1
local is_valid=$2 local is_valid=$2
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 watchfolder $WATCH_FOLDER" debug "handle_input_if_requested, rm ${filename} from watchfolder ${WATCH_FOLDER}"
rm -f "$filename" rm -f "${filename}"
fi fi
} }
...@@ -456,21 +456,21 @@ get_logfile() { ...@@ -456,21 +456,21 @@ get_logfile() {
check_argument_count $# 1 check_argument_count $# 1
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"
fi fi
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
debug "get_logfile, logname=$logname (filename=$filename)" debug "get_logfile, logname=${logname} (filename=${filename})"
echo "$logname" echo "${logname}"
} }
...@@ -482,37 +482,37 @@ scan_file() { ...@@ -482,37 +482,37 @@ scan_file() {
local logname local logname
local cmd local cmd
local is_valid local is_valid
check_argument_notempty "$filename" check_argument_notempty "${filename}"
debug "scan_file, using filename: $filename" debug "scan_file, using filename: ${filename}"
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
check_argument_notempty "$mimetype" check_argument_notempty "${mimetype}"
check_argument_notempty "$ftype" check_argument_notempty "${ftype}"
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
debug "scan_file, no early break, because is_valid='$is_valid'" debug "scan_file, no early break, because is_valid='${is_valid}'"
fi fi
done done
handle_input_if_requested "$filename" "$is_valid" handle_input_if_requested "${filename}" "${is_valid}"
else else
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}")
handle_input_if_requested "$filename" "$is_valid" handle_input_if_requested "${filename}" "${is_valid}"
fi fi
debug "scan_file, === leaving protected area ===" debug "scan_file, === leaving protected area ==="
trap - SIGINT trap - SIGINT
...@@ -523,7 +523,7 @@ scan_dir() { ...@@ -523,7 +523,7 @@ scan_dir() {
check_argument_count $# 1 check_argument_count $# 1
check_argument_notempty "$1" check_argument_notempty "$1"
find "$1" -type f -cmin +1 -mmin +1 -print0 | while IFS= read -r -d '' filename; do find "$1" -type f -cmin +1 -mmin +1 -print0 | while IFS= read -r -d '' filename; do
scan_file "$filename" scan_file "${filename}"
done done
} }
...@@ -531,35 +531,35 @@ scan_dir() { ...@@ -531,35 +531,35 @@ 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)
cat - > "$filename" cat - > "${filename}"
scan_file "$filename" scan_file "${filename}"
cat "$filename.log" cat "${filename}.log"
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"
while [[ 1 ]]; do while true; do
scan_dir "$WATCH_FOLDER" # to clean up existing files scan_dir "${WATCH_FOLDER}" # to clean up existing files
sleep 10 sleep 10
done done
# /usr/bin/inotifywait --monitor --recursive --event create \ # /usr/bin/inotifywait --monitor --recursive --event create \
# --event attrib --event moved_to --format "%w%f" "$WATCH_FOLDER" \ # --event attrib --event moved_to --format "%w%f" "${WATCH_FOLDER}" \
# | while read -r filename; do # | while read -r filename; do
# debug "called inotifywait using /usr/bin/inotifywait --monitor # debug "called inotifywait using /usr/bin/inotifywait --monitor
# --recursive --event create --event attrib --event moved_to --format '%f' $WATCH_FOLDER" # --recursive --event create --event attrib --event moved_to --format '%f' ${WATCH_FOLDER}"
# scan_file "$filename" # scan_file "${filename}"
# done # done
debug "stopping daemon" debug "stopping daemon"
else else
# cli mode, scan watch folder once # cli mode, scan watch folder once
debug "checking dir $WATCH_FOLDER" debug "checking dir ${WATCH_FOLDER}"
scan_dir "$WATCH_FOLDER" scan_dir "${WATCH_FOLDER}"
fi fi
fi fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment