|
28 | 28 | if [[ -z "$DEFANG_INSTALL_VERSION" ]]; then
|
29 | 29 | RELEASE_PATH="latest"
|
30 | 30 | else
|
31 |
| - RELEASE_PATH="tags/$DEFANG_INSTALL_VERSION" |
| 31 | + RELEASE_PATH="tags/v${DEFANG_INSTALL_VERSION#v}" |
32 | 32 | fi
|
33 | 33 |
|
34 |
| -# Echo fetching the release path either latest or strip the tags/ from the version |
35 |
| -echo "Fetching the ${DEFANG_INSTALL_VERSION:-latest} release of defang..." |
36 |
| -RELEASE_JSON=$(curl -s -f -L https://api.github.com/repos/DefangLabs/defang/releases/$RELEASE_PATH) |
| 34 | +# Anonymous API request to GitHub are rate limited to 60 requests per hour. |
| 35 | +# Check whether the user has set a GitHub token to increase the rate limit. |
| 36 | +AUTH_HEADER="" |
| 37 | +if [[ -n "$GITHUB_TOKEN" ]]; then |
| 38 | + AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" |
| 39 | +elif [[ -n "$GH_TOKEN" ]]; then |
| 40 | + AUTH_HEADER="Authorization: Bearer $GH_TOKEN" |
| 41 | +fi |
| 42 | + |
| 43 | +# Echo fetching the release path either latest or the version |
| 44 | +echo "Fetching the ${RELEASE_PATH#tags/} release of defang..." |
| 45 | +# Download the release information from GitHub, using the token if available, but falling back to anonymous access |
| 46 | +RELEASE_JSON=$([[ -n "$AUTH_HEADER" ]] && |
| 47 | + curl -sfL -H "$AUTH_HEADER" https://api.github.com/repos/DefangLabs/defang/releases/$RELEASE_PATH || |
| 48 | + curl -sfL https://api.github.com/repos/DefangLabs/defang/releases/$RELEASE_PATH) |
37 | 49 |
|
38 | 50 | # Check for curl failure
|
39 | 51 | if [ -z "$RELEASE_JSON" ]; then
|
@@ -80,7 +92,7 @@ elif [ "$OS" = "Linux" ]; then
|
80 | 92 | fi
|
81 | 93 |
|
82 | 94 | # Download the file
|
83 |
| -if ! curl -s -f -L "$DOWNLOAD_URL" -o "$FILENAME"; then |
| 95 | +if ! curl -sfL "$DOWNLOAD_URL" -o "$FILENAME"; then |
84 | 96 | echo "Download failed. Please check your internet connection and try again."
|
85 | 97 | return 4
|
86 | 98 | fi
|
@@ -239,5 +251,5 @@ rm "$FILENAME"
|
239 | 251 | echo "Installation completed. You can now use defang by typing '$BINARY_NAME' in the terminal."
|
240 | 252 |
|
241 | 253 | # Unset the variables and functions to avoid polluting the user's environment
|
242 |
| -unset EXTRACT_DIR DOWNLOAD_URL RELEASE_JSON RELEASE_PATH ARCH_SUFFIX ARCH OS FILENAME INSTALL_DIR BINARY_NAME REPLY EXPORT_PATH CURRENT_SHELL FOUND_PROFILE_FILE |
| 254 | +unset EXTRACT_DIR DOWNLOAD_URL RELEASE_JSON RELEASE_PATH ARCH_SUFFIX ARCH OS FILENAME INSTALL_DIR BINARY_NAME REPLY EXPORT_PATH CURRENT_SHELL FOUND_PROFILE_FILE AUTH_HEADER |
243 | 255 | unset -f _prompt_and_append_to_file _generate_completion_script _install_completion_script
|
0 commit comments