refactor: use if/elif/else instead of case for HTTP client detection
Avoids shellcheck SC2195 warnings caused by Terraform $${} escaping
that shellcheck doesn't understand. Split into fetch() for stdout
output and fetch_to_file() for downloading to disk, matching the
pattern used in vault-github module.
This commit is contained in:
parent
f295070544
commit
7cdc1069b1
@ -6,40 +6,34 @@ VAULT_TOKEN=${VAULT_TOKEN}
|
|||||||
INSTALL_DIR=${INSTALL_DIR}
|
INSTALL_DIR=${INSTALL_DIR}
|
||||||
VAULT_CLI_VERSION=${VAULT_CLI_VERSION}
|
VAULT_CLI_VERSION=${VAULT_CLI_VERSION}
|
||||||
|
|
||||||
# Fetch URL content. If dest is provided, write to file; otherwise output to stdout.
|
# Fetch URL content to stdout
|
||||||
# Usage: fetch <url> [dest]
|
|
||||||
fetch() {
|
fetch() {
|
||||||
url="$1"
|
url="$1"
|
||||||
dest="$${2:-}"
|
if command -v curl > /dev/null 2>&1; then
|
||||||
|
curl -sSL --fail "$${url}"
|
||||||
# Detect HTTP client on first run
|
elif command -v wget > /dev/null 2>&1; then
|
||||||
if [ -z "$${HTTP_CLIENT:-}" ]; then
|
wget -qO- "$${url}"
|
||||||
if command -v curl > /dev/null 2>&1; then
|
elif command -v busybox > /dev/null 2>&1; then
|
||||||
HTTP_CLIENT="curl"
|
busybox wget -qO- "$${url}"
|
||||||
elif command -v wget > /dev/null 2>&1; then
|
|
||||||
HTTP_CLIENT="wget"
|
|
||||||
elif command -v busybox > /dev/null 2>&1; then
|
|
||||||
HTTP_CLIENT="busybox"
|
|
||||||
else
|
|
||||||
printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$${dest}" ]; then
|
|
||||||
# shellcheck disable=SC2195
|
|
||||||
case "$${HTTP_CLIENT}" in
|
|
||||||
curl) curl -sSL --fail "$${url}" -o "$${dest}" ;;
|
|
||||||
wget) wget -O "$${dest}" "$${url}" ;;
|
|
||||||
busybox) busybox wget -O "$${dest}" "$${url}" ;;
|
|
||||||
esac
|
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2195
|
printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
|
||||||
case "$${HTTP_CLIENT}" in
|
return 1
|
||||||
curl) curl -sSL --fail "$${url}" ;;
|
fi
|
||||||
wget) wget -qO- "$${url}" ;;
|
}
|
||||||
busybox) busybox wget -qO- "$${url}" ;;
|
|
||||||
esac
|
# Download URL to a file
|
||||||
|
fetch_to_file() {
|
||||||
|
dest="$1"
|
||||||
|
url="$2"
|
||||||
|
if command -v curl > /dev/null 2>&1; then
|
||||||
|
curl -sSL --fail "$${url}" -o "$${dest}"
|
||||||
|
elif command -v wget > /dev/null 2>&1; then
|
||||||
|
wget -O "$${dest}" "$${url}"
|
||||||
|
elif command -v busybox > /dev/null 2>&1; then
|
||||||
|
busybox wget -O "$${dest}" "$${url}"
|
||||||
|
else
|
||||||
|
printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +125,7 @@ install() {
|
|||||||
cd "$${TEMP_DIR}" || return 1
|
cd "$${TEMP_DIR}" || return 1
|
||||||
|
|
||||||
printf "Downloading from %s\n" "$${DOWNLOAD_URL}"
|
printf "Downloading from %s\n" "$${DOWNLOAD_URL}"
|
||||||
if ! fetch "$${DOWNLOAD_URL}" vault.zip; then
|
if ! fetch_to_file vault.zip "$${DOWNLOAD_URL}"; then
|
||||||
printf "Failed to download Vault.\n"
|
printf "Failed to download Vault.\n"
|
||||||
rm -rf "$${TEMP_DIR}"
|
rm -rf "$${TEMP_DIR}"
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user