From 84e2897abbc0d04db349eaa9d3b5fe12e1aab135 Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <art1@andreas-romeyke.de> Date: Tue, 11 Oct 2022 18:20:41 +0200 Subject: [PATCH] - added help - added scan_dir() - prepared scan_file() --- validate_workflow.sh | 85 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 11 deletions(-) mode change 100644 => 100755 validate_workflow.sh diff --git a/validate_workflow.sh b/validate_workflow.sh old mode 100644 new mode 100755 index 5968355..19424f5 --- a/validate_workflow.sh +++ b/validate_workflow.sh @@ -18,12 +18,51 @@ # set tabwidth=4 # set indent=4 +#hh A cli tool which uses different validators to validate SLUB workflows. +#hh +#hh Usage: validate_workflow.sh [-h] | [-s] | -w watchfolder -r resultfolder [-d] [...] +#hh +#hh Options: +#hh +#hh -h, --help +#hh help output +#hh -w, -i, --watch-folder <DIR> +#hh watches folder for files which should be evaluated +#hh -r, -o, --result-folder <DIR> +#hh target folder to store validation results +#hh -f, --files-mode [sort|delete|nothing] +#hh mode=sort it sorts files to valid- and invalid-folder, +#hh mode=delete it deletes already checked files from watch-folder +#hh mode=nothing files in watch-folder are untouched +#hh The mode=delete is default. +#hh -p, --valid-folder <DIR> +#hh only needed if files-mode=sort, moves valid files from +#hh watch-folder to valid-folder +#hh -n, --invalid-folder <DIR> +#hh only needed if files-mode=sort, moves invalid files from +#hh watch-folder to invalid folder +#hh -s, --statistics +#hh print a statistic +#hh -m, -mode [auto, mediathek, fotothek, save, kitodo, lfulg] +#hh the mode auto tries to check files based on file endings. +#hh The other modes are concrete workflow names. +#hh -d, --daemon +#hh starts a daemon, works only in delete mode +#hh -t, --stage [current,upcoming,any] +#hh valides with current or upcoming profile/validator +#hh or any if any is valid +#hh +#hh + #DEFAULTS WITH_DAEMON=0 STAGE=any MODE=auto FILES_MODE=nothing +STATFILE=${HOME}/.cache/validate_workflows/statistics.cnt +LOCKFILE=/var/run/lock/validate_workflows.lock +set -o nounset # Treat unset variables as an error # Don't just call this function "help()", as that's a reserved command in Bash. comment_help() { @@ -80,50 +119,74 @@ get_cli_args() { shift ;; -f | --files-mode) - FILES_MODE"${2}" + FILES_MODE="${2}" shift shift ;; *) - $>2 echo "'${1}' ist kein gültiger Parameter. Bitte benutzen Sie '$(basename "${0}") --help'." + >&2 echo "'${1}' ist kein gültiger Parameter. Bitte benutzen Sie '$(basename "${0}") --help'." exit 1 ;; esac done if [ "$FILES_MODE" != "sort" -a "$FILES_MODE" != "delete" -a "$FILES_MODE" != "nothing" ]; then - $>2 echo "param --files-mode must be 'sort', 'delete' or 'nothing'!" + >&2 echo "param --files-mode must be 'sort', 'delete' or 'nothing'!" exit 1 fi if [ "$MODE" != "auto" -a "$MODE" != "mediathek" -a "$MODE" != "fotothek" \ -a "$MODE" != "save" -a "$MODE" != "kitodo" -a "$MODE" != "lfulg" ]; then - $>2 echo "param --mode must be 'auto', 'mediathek', 'fotothek', 'save', 'kitodo' or 'lfulg'!" + >&2 echo "param --mode must be 'auto', 'mediathek', 'fotothek', 'save', 'kitodo' or 'lfulg'!" exit 1 fi - if [ "$WITH_DAEMON" -a "$FILES_MODE" = "sort" ]; then - $>2 echo "param --daemon does only work with param --mode='delete' or --mode='nothing'!" + if [ "$WITH_DAEMON" -eq 1 -a "$FILES_MODE" = "sort" ]; then + >&2 echo "param --daemon does only work with param --mode='delete' or --mode='nothing'!" exit 1 fi if [ "$STAGE" != "current" -a "$STAGE" != "upcoming" -a "$STAGE" != "any" ]; then - $>2 echo "--param stage must be 'any', 'current' or 'upcoming'!" + >&2 echo "--param stage must be 'any', 'current' or 'upcoming'!" exit 1 fi if [ ! -d "$WATCH_FOLDER" ]; then - $>2 echo "watch folder '$WATCH_FOLDER' does not exist!" + >&2 echo "watch folder '$WATCH_FOLDER' does not exist!" exit 1 fi if [ ! -d "$RESULT_FOLDER" ]; then - $>2 echo "result folder '$RESULT_FOLDER' does not exist!" + >&2 echo "result folder '$RESULT_FOLDER' does not exist!" exit 1 fi if [ "$FILES_MODE" = "sort" ]; then if [ ! -d "$VALID_FOLDER" ]; then - $>2 echo "valid folder '$VALID_FOLDER' does not exist!" + >&2 echo "valid folder '$VALID_FOLDER' does not exist!" exit 1 fi if [ ! -d "$INVALID_FOLDER" ]; then - $>2 echo "invalid folder '$INVALID_FOLDER' does not exist!" + >&2 echo "invalid folder '$INVALID_FOLDER' does not exist!" exit 1 fi fi } + +scan_file() { + filename="$1" + echo "$filename" +} + +scan_dir() { + find "$WATCH_FOLDER" -type f -print0| while IFS= read -r -d '' filename; do + scan_file "$filename" + done +} + +#### MAIN + +get_cli_args "$@" +if [ "$WITH_DAEMON" -eq 1 ]; then + # echo daemon mode, use inotify to watch changes + echo "starting daemon" + echo "stopping daemon" +else + # cli mode, scan watch folder once + echo "checking dir $WATCH_FOLDER" + scan_dir +fi -- GitLab