get rid of bashisms

This commit is contained in:
Patrick Stadler 2015-03-15 17:18:27 +01:00
parent d018d6ea12
commit 7a43a2e21c
5 changed files with 36 additions and 8 deletions

View File

@ -55,8 +55,8 @@ main_init () {
# register trap
trap '
main_terminate
trap - SIGTERM && kill -- -$$ SIGINT SIGTERM EXIT
' SIGINT SIGTERM EXIT
trap - TERM && kill -- -$$ INT TERM EXIT
' INT TERM EXIT
# check if reporter exists
if ! in_array $__REPORTER "$__AVAILABLE_REPORTERS"; then

View File

@ -8,4 +8,27 @@ is_function () {
copy_function () {
is_function $1 || return 1
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

View File

@ -11,7 +11,7 @@ iso_date () {
in_array () {
local item=$1
local arr=$2
[[ " $2 " = *" $1 "* ]]
echo " $2 " | grep -q " $1 "
}
trim () {

View File

@ -1,5 +1,10 @@
#!/bin/sh
# OSTYPE is non-posix, provide alternative
if [ -z $OSTYPE ]; then
OSTYPE=$(uname | tr '[:upper:]' '[:lower:]')
fi
readonly OS_TYPE=$(case "$OSTYPE" in
(solaris*) echo solaris;;
(darwin*) echo osx;;
@ -17,7 +22,7 @@ is_unknown () { [ $OS_TYPE = 'unknown' ]; }
# http://unix.stackexchange.com/a/84980/50905
if is_osx; then
make_temp_dir () {
mktemp -d -t 'sysmetrics'
mktemp -d -t 'metrics'
}
else
make_temp_dir () {

View File

@ -16,9 +16,9 @@ init() {
fi
__keen_io_api_url="https://api.keen.io/3.0"
__keen_io_api_url+="/projects/$KEEN_IO_PROJECT_ID"
__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/projects/$KEEN_IO_PROJECT_ID"
__keen_io_api_url="$__keen_io_api_url/events/$KEEN_IO_EVENT_COLLECTION"
__keen_io_api_url="$__keen_io_api_url?api_key=$KEEN_IO_WRITE_KEY"
}
report () {