Merge branch 'master' of https://github.com/patvdv/check_health
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
# RETURNS: 0
|
||||
function version_include_data
|
||||
{
|
||||
typeset _VERSION="2019-07-14" # YYYY-MM-DD
|
||||
typeset _VERSION="2020-03-06" # YYYY-MM-DD
|
||||
|
||||
print "INFO: $0: ${_VERSION#version_*}"
|
||||
|
||||
@@ -196,10 +196,30 @@ done
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# @(#) FUNCTION: data_has_newline()
|
||||
# DOES: checks if a string contains newlines
|
||||
# EXPECTS: $1=haystack [string]
|
||||
# OUTPUTS: n/a
|
||||
# RETURNS: 0=no newline found; 1=newlines found
|
||||
# REQUIRES: n/a
|
||||
function data_has_newline
|
||||
{
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
typeset _HAYSTACK="${1}"
|
||||
|
||||
typeset _COUNT=$(print -R "${_HAYSTACK}" | wc -l 2>/dev/null)
|
||||
|
||||
(( _COUNT > 1 )) && return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# @(#) FUNCTION: data_magic_quote()
|
||||
# DOES: magically quotes a needle in a string (default needle is: %)
|
||||
# EXPECTS: $1=to be magically quoted [string]; $2=needle [string]
|
||||
# EXPECTS: to be magically quoted [string]; $2=needle [string]
|
||||
# OUTPUTS: magically quoted [string]
|
||||
# RETURNS: n/a
|
||||
# REQUIRES: n/a
|
||||
@@ -593,6 +613,68 @@ esac
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# @(#) FUNCTION: data_expand_numerical_range()
|
||||
# DOES: expand numerical range (X-Y) to comma-separated list of numbers
|
||||
# EXPECTS: $1=numerical range [string]
|
||||
# $2=flag for leading zeroes <10 [0=do not add (default),1=add]
|
||||
# OUTPUTS: [string]
|
||||
# RETURNS: 0=no error occurred; <>0=some error occurred
|
||||
# REQUIRES: n/a
|
||||
function data_expand_numerical_range
|
||||
{
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _NUM_LIST=""
|
||||
typeset _HAS_LEAD_ZERO=${2:0}
|
||||
|
||||
case "${1}" in
|
||||
*-*)
|
||||
# range operator, expand
|
||||
# check if there are only 2 operands (fields)
|
||||
if (( $(print "${1}" | awk -F '-' '{ print NF }' 2>/dev/null) > 2 ))
|
||||
then
|
||||
(( ARG_DEBUG > 0 )) && debug "in range $1 found more than one range (-) operator"
|
||||
return 1
|
||||
fi
|
||||
# check if X < Y
|
||||
if $(print "${1}" | awk -F '-' '{ if ($1 < $2) { exit 1 }}' 2>/dev/null)
|
||||
then
|
||||
(( ARG_DEBUG > 0 )) && debug "in range $1 operator Y is smaller or equal to operator Y"
|
||||
return 1
|
||||
fi
|
||||
# expand list
|
||||
_NUM_LIST=$(print "${1}"| awk -F '-' -v has_lead_zero=${_HAS_LEAD_ZERO} '
|
||||
BEGIN { count = 0; }
|
||||
{
|
||||
while ($1 + count <= $2) {
|
||||
# add leading zero to sprintf when < 10
|
||||
if (has_lead_zero > 0 && $1 + count < 10) { lead_zero = "0" } else { lead_zero = "" }
|
||||
if (length (NUM_LIST) == 0) {
|
||||
NUM_LIST = sprintf ("%" lead_zero "2d", $1 + count);
|
||||
} else {
|
||||
NUM_LIST = sprintf ("%s,%" lead_zero "2d", NUM_LIST, $1 + count); }
|
||||
count++;
|
||||
}
|
||||
}
|
||||
# remove space from end result and print
|
||||
END { gsub(/[[:space:]]/, "", NUM_LIST); print NUM_LIST; }')
|
||||
if [[ -z "${_NUM_LIST}" ]]
|
||||
then
|
||||
(( ARG_DEBUG > 0 )) && debug "range conversion returned empty list"
|
||||
return 1
|
||||
else
|
||||
print "${_NUM_LIST}"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# no range, return as-is
|
||||
print "${1}"
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# @(#) FUNCTION: data_encode_url
|
||||
# DOES: encode URL data
|
||||
|
||||
Reference in New Issue
Block a user