From 30369488f88aff4e3a0fad709e90da194748d4ad Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 31 May 2023 14:28:07 +0200 Subject: [PATCH] Add check-dummy.sh script Added a new bash script that always returns OK. The script has usage instructions and exit codes. It also uses getopt to parse arguments. Significant changes: - Added check-dummy.sh - Script always returns OK - Usage instructions added - Exit codes defined - Getopt used for argument parsing --- check-dummy.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 check-dummy.sh diff --git a/check-dummy.sh b/check-dummy.sh new file mode 100644 index 0000000..166a239 --- /dev/null +++ b/check-dummy.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# +#/ +#/ Usage: +#/ check-dummy.sh +#/ +#/ Does not check anything. Always gives OK! +#/ +#/ +#/ Exit Codes: +#/ 0 Everything OK +#/ + +Usage() { + grep '^#/' "${script_dir}/${script_name}" | sed 's/^#\/\w*//' +} + +GetOptions() { + # https://stackoverflow.com/a/29754866 + OPTIONS='' + LONGOPTS='' + + # -use ! and PIPESTATUS to get exit code with errexit set + # -temporarily store output to be able to check for errors + # -activate quoting/enhanced mode (e.g. by writing out “--options”) + # -pass arguments only via -- "$@" to separate them correctly + ! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") + if [[ ${PIPESTATUS[0]} -ne 0 ]]; then + # e.g. return value is 1 + # then getopt has complained about wrong arguments to stdout + Usage + exit 2 + fi + + # read getopt's output this way to handle the quoting right: + eval set -- "$PARSED" + + # now enjoy the options in order and nicely split until we see -- + while true; do + case "$1" in + --) + shift + break + ;; + *) + echo "URL UNKNOWN - ${1} is not a valid parameter" + exit 3 + ;; + esac + done + + if [ -z ${1+x} ]; then + echo "URL UNKNOWN - url not given" + exit 3 + else + url=${1} + fi +} +echo "DUMMY OK" +exit 0 \ No newline at end of file