-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
usage() { | ||
cat <<EOS >&2 | ||
Check each message file. | ||
Exits with an error if the pattern is not found in the message file. | ||
Usage: $0 MATCHER PATTERN MESSAGE_FILE [MARKER_FILE ...] | ||
MATCHER | ||
Executable to check if the pattern string is inside the message file | ||
PATTERN | ||
Pattern string | ||
MESSAGE_FILE | ||
Text file containing a message | ||
MARKER_FILE ... | ||
Empty text files are created at the specified paths before exiting the script | ||
EOS | ||
} | ||
|
||
if [ "$#" -lt 3 ]; then | ||
echo "ERROR: Incorrect number of arguments" >&2 | ||
usage | ||
exit 1 | ||
fi | ||
|
||
matcher=$1 | ||
pattern=$2 | ||
message_file=$3 | ||
shift 3 | ||
|
||
files_to_touch=("$@") | ||
|
||
# Make sure the required files are touched before exiting | ||
if [[ "${#files_to_touch[@]}" -gt 0 ]]; then | ||
trap 'touch "${files_to_touch[@]}"' EXIT | ||
fi | ||
|
||
if ! "${matcher}" "${pattern}" "${message_file}" ; then | ||
echo "Pattern '${pattern}' is not found in the message file '${message_file}' with the matcher '${matcher}'." >&2 | ||
echo "" >&2 | ||
echo "---------- Message: BEGIN ----------" >&2 | ||
cat "${message_file}" >&2 | ||
echo "---------- Message: END ----------" >&2 | ||
echo "" >&2 | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters