10 echo "$1 v$2 (@PACKAGE@ @VERSION@)"
11 printf '%b' "@WARRANTY@"
15 printf '%b' "@SUPPORT@"
19 # check_range takes a value and a range string, returning successfully if an
20 # alert should be raised based on the range. Range values are inclusive.
21 # Values may be integers or floats.
25 # Generating an exit code of 1:
28 # Generating an exit code of 0:
32 local v range
yes no err decimal start end
cmp match
36 # whether to raise an alert or not
41 # regex to match a decimal number
42 decimal
="-?([0-9]+\.?[0-9]*|[0-9]*\.[0-9]+)"
44 # compare numbers (including decimals), returning true/false
45 cmp() { awk "BEGIN{ if ($1) exit(0); exit(1)}"; }
47 # returns successfully if the string in the first argument matches the
49 match
() { echo "$1" |
grep -E -q -- "$2"; }
51 # make sure value is valid
52 if ! match
"$v" "^$decimal$"; then
53 echo "${0##*/}: check_range: invalid value" >&2
58 # make sure range is valid
59 if ! match
"$range" "^@?(~|$decimal)(:($decimal)?)?$"; then
60 echo "${0##*/}: check_range: invalid range" >&2
65 # check for leading @ char, which negates the range
66 if match
$range '^@'; then
72 # parse the range string
73 if ! match
"$range" ':'; then
81 # do the comparison, taking positive ("") and negative infinity ("~")
83 if [ "$start" != "~" ] && [ "$end" != "" ]; then
84 if cmp "$start <= $v" && cmp "$v <= $end"; then
91 elif [ "$start" != "~" ] && [ "$end" = "" ]; then
92 if cmp "$start <= $v"; then
99 elif [ "$start" = "~" ] && [ "$end" != "" ]; then
100 if cmp "$v <= $end"; then