From 7168fe6ee8603228e2ca9b1ff77ac86d36859430 Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Mon, 24 Oct 2016 13:56:23 -0400 Subject: [PATCH] Migrated miscellaneous Bash utilities into the `hack/lib` library Signed-off-by: Steve Kuznetsov --- hack/lib/util/misc.sh | 36 ++++++++++++++++++++++++++++++++++++ hack/util.sh | 20 +------------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/hack/lib/util/misc.sh b/hack/lib/util/misc.sh index 221bc5aeab36..476c07b77680 100644 --- a/hack/lib/util/misc.sh +++ b/hack/lib/util/misc.sh @@ -129,3 +129,39 @@ function os::util::find-go-binary() { done } readonly -f os::util::find-go-binary + +# os::util::sed attempts to make our Bash scripts agnostic to the platform +# on which they run `sed` by glossing over a discrepancy in flag use in GNU. +# +# Globals: +# None +# Arguments: +# - all: arguments to pass to `sed -i` +# Return: +# None +function os::util::sed() { + if LANG=C sed --help 2>&1 | grep -q "GNU sed"; then + sed -i'' "$@" + else + sed -i '' "$@" + fi +} +readonly -f os::util::sed + +# os::util::base64decode attempts to make our Bash scripts agnostic to the platform +# on which they run `base64decode` by glossing over a discrepancy in flag use in GNU. +# +# Globals: +# None +# Arguments: +# - all: arguments to pass to `base64decode` +# Return: +# None +function os::util::base64decode() { + if [[ "$(go env GOHOSTOS)" == "darwin" ]]; then + base64 -D "$@" + else + base64 -d "$@" + fi +} +readonly -f os::util::base64decode \ No newline at end of file diff --git a/hack/util.sh b/hack/util.sh index 37eb5061bc8a..7acf51e6d1fe 100644 --- a/hack/util.sh +++ b/hack/util.sh @@ -543,22 +543,4 @@ readonly -f find_files function os::util::host_platform() { echo "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" } -readonly -f os::util::host_platform - -function os::util::sed() { - if LANG=C sed --help 2>&1 | grep -qs "GNU sed"; then - sed -i'' "$@" - else - sed -i '' "$@" - fi -} -readonly -f os::util::sed - -function os::util::base64decode() { - if [[ "$(go env GOHOSTOS)" == "darwin" ]]; then - base64 -D $@ - else - base64 -d $@ - fi -} -readonly -f os::util::base64decode \ No newline at end of file +readonly -f os::util::host_platform \ No newline at end of file