diff --git a/src/usr/local/bin/validate_workflow.sh b/src/usr/local/bin/validate_workflow.sh index aa08488ff610866925a732ce3d10c561a3bf6e40..69bad62a17857b50f09ca2c4621d0a2819000218 100755 --- a/src/usr/local/bin/validate_workflow.sh +++ b/src/usr/local/bin/validate_workflow.sh @@ -58,6 +58,14 @@ #hh -p, --pipe #hh validates a single filestream from STDIN, writes result to STDOUT #hh no daemon, no folder nor filemode params needed +#hh -F, --single-file <FILENAME> +#hh validates a single file, writes result to STDOUT +#hh no daemon, no folder nor filemode params needed +#hh +#hh CAUTION: IN GENERAL, DO NOT USE THIS OPTION, USE DAEMON MODE INSTEAD! +#hh +#hh HINT: You MUST set the environment variable $TMPDIR to a dir in same +#hh filesystem as FILENAME exists, because hard links used! #hh #hh @@ -74,6 +82,7 @@ FILES_MODE_LIST="sort,delete,nothing" # DEFAULTS WITH_DAEMON=0 WITH_DEBUG=0 +export WITH_SINGLE_FILE=0 export WITH_PIPE=0 export STAGE=any export MODE=auto @@ -223,7 +232,7 @@ get_mimetype() { echo_validation_result_if_pipe() { local is_valid="$1" - if [[ "${WITH_PIPE}" -eq 1 ]]; then + if [[ "${WITH_PIPE}" -eq 1 || "${WITH_SINGLE_FILE}" -eq 1 ]]; then echo "${is_valid}" fi } @@ -288,6 +297,12 @@ get_cli_args() { WITH_PIPE=1 shift ;; + -F | --single-file) + WITH_SINGLE_FILE=1 + FILE_NAME="$2" + shift + shift + ;; *) error "'$1' is invalid param. Please, give '$(basename "$0") --help' a chance!" exit 1 @@ -310,11 +325,30 @@ get_cli_args() { || [[ -n "${VALID_FOLDER}" ]] \ || [[ -n "${INVALID_FOLDER}" ]] \ || [[ "${FILES_MODE}" = "sort" ]] \ + || [[ -n "${SINGLE_FILE}" ]] \ ; then error "param --pipe not combinable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode" exit 1 fi else + if [[ "${WITH_SINGLE_FILE}" -eq 1 ]]; then + if + [[ "${WITH_DAEMON}" -eq 1 ]] \ + || [[ -n "${WATCH_FOLDER}" ]] \ + || [[ -n "${RESULT_FOLDER}" ]] \ + || [[ -n "${VALID_FOLDER}" ]] \ + || [[ -n "${INVALID_FOLDER}" ]] \ + || [[ "${FILES_MODE}" = "sort" ]] \ + || [[ "${WITH_PIPE}" -ne 0 ]] \ + ; then + error "param --single-file not combinable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode" + exit 1 + fi + if [[ ! -f "${FILE_NAME}" ]]; then + error "filename '$FILE_NAME' for param --single-file does not exist!" + exit 1 + fi + else if [[ "${WITH_DAEMON}" -eq 1 ]] && [[ "${FILES_MODE}" = "sort" ]]; then error "param --daemon does only work with param --mode='delete' or --mode='nothing'!" exit 1 @@ -342,6 +376,7 @@ get_cli_args() { fi fi fi + fi cachedir=$(dirname "${STATFILE}") if [[ ! -d "${cachedir}" ]]; then mkdir -p "${cachedir}" || error "Could not create dir ${cachedir}, $?" @@ -609,7 +644,22 @@ if [[ "${WITH_PIPE}" -eq 1 ]]; then rm -f "${filename}.log" || error "could not remove temporary file '${filename}.log'" rm -f "${filename}" || error "could not remove temporary file '${filename}'" exit "${result}" -else +else + if [[ "${WITH_SINGLE_FILE}" -eq 1 ]]; then + #cli mode, use filename + debug "checking filename '${FILE_NAME}'" + dirname=$(mktemp -d --tmpdir validate_wrg.XXXX) + basename=$(basename "${FILE_NAME}") + filename="${dirname}/${basename}" + ln -t "${dirname}" "${FILE_NAME}" + result=$(scan_file "${filename}") + debug "single-file mode result (is_valid): ${result}" + 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}'" + rm -Rf "${dirname}" || error "could not remove temporary dir '${dirname}'" + exit "${result}" + else if [[ "${WITH_DAEMON}" -eq 1 ]]; then # TODO: protect DAEMON from STRG-C for clean shutdown # echo daemon mode, use inotify to watch changes @@ -631,4 +681,5 @@ else debug "checking dir ${WATCH_FOLDER}" scan_dir "${WATCH_FOLDER}" fi + fi fi