@@ -7,40 +7,34 @@ INSTALL_DIR=${INSTALL_DIR}
77VAULT_CLI_VERSION=${VAULT_CLI_VERSION}
88ENTERPRISE=${ENTERPRISE}
99
10- # Fetch URL content. If dest is provided, write to file; otherwise output to stdout.
11- # Usage: fetch <url> [dest]
10+ # Fetch URL content to stdout
1211fetch () {
1312 url=" $1 "
14- dest=" $$ {2:-}"
15-
16- # Detect HTTP client on first run
17- if [ -z " $$ {HTTP_CLIENT:-}" ]; then
18- if command -v curl > /dev/null 2>&1 ; then
19- HTTP_CLIENT=" curl"
20- elif command -v wget > /dev/null 2>&1 ; then
21- HTTP_CLIENT=" wget"
22- elif command -v busybox > /dev/null 2>&1 ; then
23- HTTP_CLIENT=" busybox"
24- else
25- printf " curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
26- return 1
27- fi
13+ if command -v curl > /dev/null 2>&1 ; then
14+ curl -sSL --fail " $$ {url}"
15+ elif command -v wget > /dev/null 2>&1 ; then
16+ wget -qO- " $$ {url}"
17+ elif command -v busybox > /dev/null 2>&1 ; then
18+ busybox wget -qO- " $$ {url}"
19+ else
20+ printf " curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
21+ return 1
2822 fi
23+ }
2924
30- if [ -n " $$ {dest}" ]; then
31- # shellcheck disable=SC2195
32- case " $$ {HTTP_CLIENT}" in
33- curl) curl -sSL --fail " $$ {url}" -o " $$ {dest}" ;;
34- wget) wget -O " $$ {dest}" " $$ {url}" ;;
35- busybox) busybox wget -O " $$ {dest}" " $$ {url}" ;;
36- esac
25+ # Download URL to a file
26+ fetch_to_file () {
27+ dest=" $1 "
28+ url=" $2 "
29+ if command -v curl > /dev/null 2>&1 ; then
30+ curl -sSL --fail " $$ {url}" -o " $$ {dest}"
31+ elif command -v wget > /dev/null 2>&1 ; then
32+ wget -O " $$ {dest}" " $$ {url}"
33+ elif command -v busybox > /dev/null 2>&1 ; then
34+ busybox wget -O " $$ {dest}" " $$ {url}"
3735 else
38- # shellcheck disable=SC2195
39- case " $$ {HTTP_CLIENT}" in
40- curl) curl -sSL --fail " $$ {url}" ;;
41- wget) wget -qO- " $$ {url}" ;;
42- busybox) busybox wget -qO- " $$ {url}" ;;
43- esac
36+ printf " curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
37+ return 1
4438 fi
4539}
4640
@@ -141,7 +135,7 @@ install() {
141135 cd " $$ {TEMP_DIR}" || return 1
142136
143137 printf " Downloading from %s\n" " $$ {DOWNLOAD_URL}"
144- if ! fetch " $$ {DOWNLOAD_URL}" vault.zip ; then
138+ if ! fetch_to_file vault.zip " $$ {DOWNLOAD_URL}" ; then
145139 printf " Failed to download Vault.\n"
146140 rm -rf " $$ {TEMP_DIR}"
147141 return 1
0 commit comments