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

- added help

- added scan_dir()
- prepared scan_file()
parent c6db1676
No related branches found
No related tags found
No related merge requests found
...@@ -18,12 +18,51 @@ ...@@ -18,12 +18,51 @@
# set tabwidth=4 # set tabwidth=4
# set indent=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 #DEFAULTS
WITH_DAEMON=0 WITH_DAEMON=0
STAGE=any STAGE=any
MODE=auto MODE=auto
FILES_MODE=nothing 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. # Don't just call this function "help()", as that's a reserved command in Bash.
comment_help() { comment_help() {
...@@ -80,50 +119,74 @@ get_cli_args() { ...@@ -80,50 +119,74 @@ get_cli_args() {
shift shift
;; ;;
-f | --files-mode) -f | --files-mode)
FILES_MODE"${2}" FILES_MODE="${2}"
shift shift
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 exit 1
;; ;;
esac esac
done done
if [ "$FILES_MODE" != "sort" -a "$FILES_MODE" != "delete" -a "$FILES_MODE" != "nothing" ]; then 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 exit 1
fi fi
if [ "$MODE" != "auto" -a "$MODE" != "mediathek" -a "$MODE" != "fotothek" \ if [ "$MODE" != "auto" -a "$MODE" != "mediathek" -a "$MODE" != "fotothek" \
-a "$MODE" != "save" -a "$MODE" != "kitodo" -a "$MODE" != "lfulg" ]; then -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 exit 1
fi fi
if [ "$WITH_DAEMON" -a "$FILES_MODE" = "sort" ]; then if [ "$WITH_DAEMON" -eq 1 -a "$FILES_MODE" = "sort" ]; then
$>2 echo "param --daemon does only work with param --mode='delete' or --mode='nothing'!" >&2 echo "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" -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 exit 1
fi fi
if [ ! -d "$WATCH_FOLDER" ]; then 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 exit 1
fi fi
if [ ! -d "$RESULT_FOLDER" ]; then 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 exit 1
fi fi
if [ "$FILES_MODE" = "sort" ]; then if [ "$FILES_MODE" = "sort" ]; then
if [ ! -d "$VALID_FOLDER" ]; 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 exit 1
fi fi
if [ ! -d "$INVALID_FOLDER" ]; then 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 exit 1
fi fi
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment