mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-07-08 08:32:16 -04:00
get rid of bashisms
This commit is contained in:
parent
d018d6ea12
commit
7a43a2e21c
@ -55,8 +55,8 @@ main_init () {
|
|||||||
# register trap
|
# register trap
|
||||||
trap '
|
trap '
|
||||||
main_terminate
|
main_terminate
|
||||||
trap - SIGTERM && kill -- -$$ SIGINT SIGTERM EXIT
|
trap - TERM && kill -- -$$ INT TERM EXIT
|
||||||
' SIGINT SIGTERM EXIT
|
' INT TERM EXIT
|
||||||
|
|
||||||
# check if reporter exists
|
# check if reporter exists
|
||||||
if ! in_array $__REPORTER "$__AVAILABLE_REPORTERS"; then
|
if ! in_array $__REPORTER "$__AVAILABLE_REPORTERS"; then
|
||||||
|
@ -9,3 +9,26 @@ copy_function () {
|
|||||||
is_function $1 || return 1
|
is_function $1 || return 1
|
||||||
eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)"
|
eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# if `type declare | grep -q 'shell builtin$'`; then
|
||||||
|
# is_function () {
|
||||||
|
# declare -f -F $1 > /dev/null; return $?
|
||||||
|
# }
|
||||||
|
|
||||||
|
# # http://stackoverflow.com/a/1369211/183097
|
||||||
|
# copy_function () {
|
||||||
|
# is_function $1 || return 1
|
||||||
|
# eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)"
|
||||||
|
# }
|
||||||
|
|
||||||
|
# # `declare` is non-posix, provide alternative
|
||||||
|
# else
|
||||||
|
# is_function () {
|
||||||
|
# type $1 | grep -q 'shell function$'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# copy_function () {
|
||||||
|
# is_function $1 || return 1
|
||||||
|
# echo "${2}() { ${1} }"
|
||||||
|
# }
|
||||||
|
# fi
|
@ -11,7 +11,7 @@ iso_date () {
|
|||||||
in_array () {
|
in_array () {
|
||||||
local item=$1
|
local item=$1
|
||||||
local arr=$2
|
local arr=$2
|
||||||
[[ " $2 " = *" $1 "* ]]
|
echo " $2 " | grep -q " $1 "
|
||||||
}
|
}
|
||||||
|
|
||||||
trim () {
|
trim () {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# OSTYPE is non-posix, provide alternative
|
||||||
|
if [ -z $OSTYPE ]; then
|
||||||
|
OSTYPE=$(uname | tr '[:upper:]' '[:lower:]')
|
||||||
|
fi
|
||||||
|
|
||||||
readonly OS_TYPE=$(case "$OSTYPE" in
|
readonly OS_TYPE=$(case "$OSTYPE" in
|
||||||
(solaris*) echo solaris;;
|
(solaris*) echo solaris;;
|
||||||
(darwin*) echo osx;;
|
(darwin*) echo osx;;
|
||||||
@ -17,7 +22,7 @@ is_unknown () { [ $OS_TYPE = 'unknown' ]; }
|
|||||||
# http://unix.stackexchange.com/a/84980/50905
|
# http://unix.stackexchange.com/a/84980/50905
|
||||||
if is_osx; then
|
if is_osx; then
|
||||||
make_temp_dir () {
|
make_temp_dir () {
|
||||||
mktemp -d -t 'sysmetrics'
|
mktemp -d -t 'metrics'
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
make_temp_dir () {
|
make_temp_dir () {
|
||||||
|
@ -16,9 +16,9 @@ init() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
__keen_io_api_url="https://api.keen.io/3.0"
|
__keen_io_api_url="https://api.keen.io/3.0"
|
||||||
__keen_io_api_url+="/projects/$KEEN_IO_PROJECT_ID"
|
__keen_io_api_url="$__keen_io_api_url/projects/$KEEN_IO_PROJECT_ID"
|
||||||
__keen_io_api_url+="/events/$KEEN_IO_EVENT_COLLECTION"
|
__keen_io_api_url="$__keen_io_api_url/events/$KEEN_IO_EVENT_COLLECTION"
|
||||||
__keen_io_api_url+="?api_key=$KEEN_IO_WRITE_KEY"
|
__keen_io_api_url="$__keen_io_api_url?api_key=$KEEN_IO_WRITE_KEY"
|
||||||
}
|
}
|
||||||
|
|
||||||
report () {
|
report () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user