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

- added comments

- simplified if-clauses
- added file replacement
- added cmd call
parent 10544734
Branches
No related tags found
No related merge requests found
...@@ -80,6 +80,7 @@ declare -A validators ...@@ -80,6 +80,7 @@ declare -A validators
# workflow has max 11 chars # workflow has max 11 chars
# filetype has max 4 chars # filetype has max 4 chars
# stage has max 9 chars # stage has max 9 chars
# each validator should return true if file was valid
validators[__mediathek_mkv__current]="/usr/bin/mediaconch -ft -p /etc/mediaconch/profile,xml FILE" validators[__mediathek_mkv__current]="/usr/bin/mediaconch -ft -p /etc/mediaconch/profile,xml FILE"
validators[__mediathek_mkv_upcoming]="/usr/bin/mediaconch -ft -p /etc/mediaconch/profile,xml FILE" validators[__mediathek_mkv_upcoming]="/usr/bin/mediaconch -ft -p /etc/mediaconch/profile,xml FILE"
validators[_____kitodo_tif__current]="/usr/bin/checkit_tiff_current /etc/checkit_tiff/retromono_current FILE" validators[_____kitodo_tif__current]="/usr/bin/checkit_tiff_current /etc/checkit_tiff/retromono_current FILE"
...@@ -203,11 +204,11 @@ get_cli_args() { ...@@ -203,11 +204,11 @@ get_cli_args() {
exit 1 exit 1
fi fi
else else
if [ "$WITH_DAEMON" -eq 1 -a "$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" -a "$STAGE" != "upcoming" -a "$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
...@@ -236,7 +237,7 @@ prepare_cmd() { ...@@ -236,7 +237,7 @@ prepare_cmd() {
mode=$1 mode=$1
ftype=$2 ftype=$2
stage=$3 stage=$3
key=$(printf "%11s%4s%9s" $MODE $ftype $stage|sed -e "y/ /_/") key=$(printf "%11s%4s%9s" "$mode" "$ftype" "$stage"|sed -e "y/ /_/")
debug "prepare_cmd, key=$key" debug "prepare_cmd, key=$key"
cmd=${validators[$key]}; cmd=${validators[$key]};
debug "prepare_cmd, cmd=$cmd" debug "prepare_cmd, cmd=$cmd"
...@@ -293,13 +294,15 @@ scan_file() { ...@@ -293,13 +294,15 @@ scan_file() {
if [ "$STAGE" = "any" ]; then if [ "$STAGE" = "any" ]; then
for stage in current upcoming; do for stage in current upcoming; do
debug "scan_file, using stage: $stage (STAGE mode '$STAGE')" debug "scan_file, using stage: $stage (STAGE mode '$STAGE')"
cmd=$(prepare_cmd "$MODE" "$ftype" "$stage") cmd=$(prepare_cmd "$MODE" "$ftype" "$stage" | sed -e "s#FILE#'$filename'#")
echo "cmd=$cmd" debug "scan_file, calling cmd='$cmd'"
"$cmd" || ( error "failed call of '$cmd', $?"; exit 1)
done done
else else
debug "scan_file, using stage: $STAGE" debug "scan_file, using stage: $STAGE"
cmd=$(prepare_cmd "$MODE" "$ftype" "$STAGE") cmd=$(prepare_cmd "$MODE" "$ftype" "$STAGE" | sed -e "s#FILE#'$filename'#")
echo "cmd=$cmd" debug "scan_file, calling cmd='$cmd'"
"$cmd" || ( error "failed call of '$cmd', $?"; exit 1)
fi fi
} }
...@@ -316,10 +319,10 @@ get_cli_args "$@" ...@@ -316,10 +319,10 @@ get_cli_args "$@"
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 validate_wrg.XXXX) filename=$(mktemp --tmpdir validate_wrg.XXXX)
cat - > $filename cat - > "$filename"
scan_file "$filename" scan_file "$filename"
rm -f $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
# echo daemon mode, use inotify to watch changes # echo daemon mode, use inotify to watch changes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment