Skip to content

Commit 002ec53

Browse files
committed
feat(installer): add github token support
This adds support for utilizing the env var GITHUB_TOKEN when the --auth flag is passed for both curl/wget download utils. The command invocations are not included in xtrace output so that the token is not logged. fixes #2664
1 parent b14a7b5 commit 002ec53

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

www/install.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ USAGE:
2020
FLAGS:
2121
-h, --help Display this message
2222
-f, --force Force overwriting an existing binary
23+
-a, --auth Authenticate downloads from Github using GITHUB_TOKEN
2324
2425
OPTIONS:
2526
--tag TAG Tag (version) of the crate to install, defaults to latest release
@@ -55,16 +56,35 @@ download() {
5556
url="$1"
5657
output="$2"
5758

58-
if command -v curl > /dev/null; then
59-
curl --proto =https --tlsv1.2 -sSfL "$url" "-o$output"
59+
if [ "$auth" = false ]; then
60+
if command -v curl > /dev/null; then
61+
curl --proto =https --tlsv1.2 -sSfL "$url" -o"$output"
62+
else
63+
wget --https-only --secure-protocol=TLSv1_2 --quiet "$url" -O"$output"
64+
fi
6065
else
61-
wget --https-only --secure-protocol=TLSv1_2 --quiet "$url" "-O$output"
66+
debug_mode=$(set +o | grep xtrace)
67+
set +x
68+
69+
if command -v curl > /dev/null; then
70+
curl --proto =https --tlsv1.2 -sSfL -H "Authorization: Bearer $GITHUB_TOKEN" "$url" -o"$output"
71+
else
72+
wget --https-only --secure-protocol=TLSv1_2 --quiet --header="Authorization: Bearer $GITHUB_TOKEN" "$url" -O"$output"
73+
fi
74+
75+
if echo "$debug_mode" | grep -q "set -o xtrace"; then
76+
set -x
77+
fi
6278
fi
6379
}
6480

81+
auth=false
6582
force=false
6683
while test $# -gt 0; do
6784
case $1 in
85+
--auth| -a)
86+
auth=true
87+
;;
6888
--force | -f)
6989
force=true
7090
;;

0 commit comments

Comments
 (0)