diff --git a/validate_workflow.sh b/validate_workflow.sh index 0ba99197df848e6c21a0ba9b975765cb073b99ad..9192645176b5e0a4e06a0c673a076d5a0d3f2296 100755 --- a/validate_workflow.sh +++ b/validate_workflow.sh @@ -95,12 +95,21 @@ validators[______lfulg_tif__current]="/usr/bin/checkit_tiff_current /etc/checkit validators[______lfulg_tif_upcoming]="/usr/bin/checkit_tiff_upcoming /etc/checkit_tiff/retrogeomono_upcoming FILE" validators[___fotothek_tif__current]="/usr/bin/checkit_tiff_current /etc/checkit_tiff/retrofoto_current FILE" validators[___fotothek_tif_upcoming]="/usr/bin/checkit_tiff_upcoming /etc/checkit_tiff/retrofoto_upcoming FILE" -validators[_____kitodo_icc__current]="/usr/bin/iccDumpProfile -v FILE" -validators[_____kitodo_icc_upcoming]="/usr/bin/iccDumpProfile -v FILE" +validators[_____kitodo_icc__current]="/usr/local/bin/iccDumpProfile -v FILE" +validators[_____kitodo_icc_upcoming]="/usr/local/bin/iccDumpProfile -v FILE" set -o nounset # Treat unset variables as an error +check_argument_count() { + local count=$1 + local expected=$2 + 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 +} + # Don't just call this function "help()", as that's a reserved command in Bash. comment_help() { sed -rn 's/^#hh ?//;T;p' "$0" @@ -129,6 +138,7 @@ print_statistics() { } update_statistics() { + check_argument_count $# 5 local is_valid=$1 local duration=$2 local ftype=$3 @@ -157,6 +167,7 @@ error() { } get_mimetype() { + check_argument_count $# 1 local filename=$1 local res res=$(file --mime-type "$filename" | sed -e "s/^.*: //") @@ -300,6 +311,7 @@ get_cli_args() { } prepare_cmd() { + check_argument_count $# 3 local mode=$1 local ftype=$2 local stage=$3 @@ -317,6 +329,7 @@ prepare_cmd() { } prepare_ftype() { + check_argument_count $# 1 local mimetype=$1 local ftype debug "prepare_ftype, using mimetype: $mimetype" @@ -340,6 +353,7 @@ prepare_ftype() { } estimate_mode() { + check_argument_count $# 1 local mimetype=$1 debug "estimate_mode, using mimetype: $mimetype" case ${mimetype} in @@ -362,6 +376,7 @@ estimate_mode() { } exec_cmd() { + check_argument_count $# 5 local cmd=$1 local ftype=$2 local workflow=$3 @@ -371,20 +386,17 @@ exec_cmd() { local stop_t start_t=$(date +"%s") debug "scan_file, calling cmd='$cmd'" - if [ -n "$log" ]; then $cmd >>"$log" 2>&1 - else - $cmd 2>&1 - fi local is_valid=$? stop_t=$(date +"%s") local duration=$((stop_t - start_t)) - debug "scan_file, 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" echo "$is_valid" } handle_input_if_requested() { + check_argument_count $# 2 local filename=$1 local is_valid=$2 debug "handle_input_if_requested, filename=$filename is_valid=$is_valid" @@ -403,12 +415,18 @@ handle_input_if_requested() { } get_logfile() { + check_argument_count $# 1 local filename=$1 local logname 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="" + logname="$filename.log" + fi + logdir=$(dirname "$logname") + if [ ! -d "$logdir" ]; then + debug "get_logfile, mkdir $logdir" + mkdir -p "$logdir" fi debug "get_logfile, logname=$logname (filename=$filename)" echo "$logname" @@ -416,6 +434,7 @@ get_logfile() { scan_file() { + check_argument_count $# 1 local filename="$1" local mimetype local ftype @@ -438,7 +457,10 @@ scan_file() { 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 + debug "scan_file, early break" break + else + debug "scan_file, no early break, because is_valid='$is_valid'" fi done handle_input_if_requested "$filename" "$is_valid" @@ -453,6 +475,7 @@ scan_file() { } scan_dir() { + check_argument_count $# 1 find "$1" -type f -print0| while IFS= read -r -d '' filename; do scan_file "$filename" done @@ -468,6 +491,8 @@ if [ "$WITH_PIPE" -eq 1 ]; then filename=$(mktemp --tmpdir validate_wrg.XXXX) cat - > "$filename" scan_file "$filename" + cat "$filename.log" + 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