Skip to content

Commit

Permalink
shell stub: use md5 on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Dec 1, 2024
1 parent e03968f commit 337d0c4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tools/credential-helper
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,28 @@ set -o errtrace

credential_helper_install_command="bazel run @tweag-credential-helper//installer"

# Bazel spawns the credential helper process using the workspace root as working directory.
# We abuse this fact to obtain a stable, workspace specific install dir (just like Bazel's output base).
install_base_hash() {
if builtin command -v md5 > /dev/null; then
echo -n "$(pwd)" | md5
elif builtin command -v md5sum > /dev/null ; then
local md5_array=($(echo -n "$(pwd)" | md5sum))
echo "${md5_array}"
else
echo "Neither md5 nor md5sum were found in the PATH" >&2
exit 1
fi
}

cache_dir="${HOME}/.cache"
if [ -n "${TEST_TMPDIR}" ]; then
cache_dir="${TEST_TMPDIR}"
fi
if [ -n "${CREDENTIAL_HELPER_INSTALL_BASE}" ]; then
install_base="${CREDENTIAL_HELPER_INSTALL_BASE}"
else
# Bazel spawns the credential helper process using the workspace root as working directory.
# We abuse this fact to obtain a stable, workspace specific install dir (just like Bazel's output base).
install_base_hash=($(echo -n $(pwd) | md5sum))
install_base="${cache_dir}/tweag-credential-helper/${install_base_hash[0]}"
install_base="${cache_dir}/tweag-credential-helper/$(install_base_hash)"
fi

if [ -n "${CREDENTIAL_HELPER_BIN}" ]; then
Expand All @@ -46,9 +57,9 @@ else
fi

if [ ! -f $helper_bin ]; then
echo "credential helper is not installed under ${helper_bin}"
echo "You can install it using the following command:"
echo " ${credential_helper_install_command}"
echo "credential helper is not installed under ${helper_bin}" >&2
echo "You can install it using the following command:" >&2
echo " ${credential_helper_install_command}" >&2
exit 1
fi

Expand Down

0 comments on commit 337d0c4

Please sign in to comment.