Skip to content

Commit

Permalink
Check if gbase64 (GNU) is available on Mac and use it in preference t…
Browse files Browse the repository at this point in the history
…o BSD base64 @marcjay

Check if gbase64 (GNU) is available on Mac and use it in preference to BSD base64
  • Loading branch information
toniblyx committed Apr 22, 2020
2 parents 5b9cf7f + 5805576 commit 0cca77a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions include/os_detector
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# specific language governing permissions and limitations under the License.

DATE_CMD="date"
BASE64_CMD="base64"

gnu_how_older_from_today() {
DATE_TO_COMPARE=$1
Expand Down Expand Up @@ -44,10 +45,10 @@ bsd_timestamp_to_date() {
}

gnu_decode_report() {
base64 -d
"$BASE64_CMD" -d
}
bsd_decode_report() {
base64 -D
"$BASE64_CMD" -D
}

gnu_how_many_days_from_today() {
Expand Down Expand Up @@ -146,22 +147,23 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
# It is possible that the user has installed GNU coreutils on OS X. By default, this will make GNU commands
# available with a 'g' prefix, e.g. 'gdate'. Test if this is present, and use it if so, as it supports more features.
# The user also may have replaced the default Mac OS X BSD tools with the GNU coreutils equivalents.
# Only GNU date allows --version as a valid argument, so use the validity of this argument
# Only GNU date/base64 allows --version as a valid argument, so use the validity of this argument
# as a means to detect that coreutils is installed and is overriding the default tools
GDATE=$(which gdate)
if [ -n "${GDATE}" ]; then
DATE_CMD="gdate"
fi
GBASE64=$(which gbase64)
if [ -n "${GBASE64}" ]; then
BASE64_CMD="gbase64"
fi
if "$DATE_CMD" --version >/dev/null 2>&1 ; then
how_older_from_today() {
gnu_how_older_from_today "$1"
}
timestamp_to_date() {
gnu_timestamp_to_date "$1"
}
decode_report() {
gnu_decode_report
}
how_many_days_from_today() {
gnu_how_many_days_from_today "$1"
}
Expand All @@ -181,9 +183,6 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
timestamp_to_date() {
bsd_timestamp_to_date "$1"
}
decode_report() {
bsd_decode_report
}
how_many_days_from_today() {
bsd_how_many_days_from_today "$1"
}
Expand All @@ -197,6 +196,15 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
bsd_get_iso8601_timestamp
}
fi
if "$BASE64_CMD" --version >/dev/null 2>&1 ; then
decode_report() {
gnu_decode_report
}
else
decode_report() {
bsd_decode_report
}
fi
test_tcp_connectivity() {
bsd_test_tcp_connectivity "$1" "$2" "$3"
}
Expand Down

0 comments on commit 0cca77a

Please sign in to comment.