Skip to content

Commit 2520be6

Browse files
authored
Merge pull request #611 from DefangLabs/allow-versioned-install
Allow user to specify install version in env var
2 parents d561d0d + 4daa198 commit 2520be6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/bin/install

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ if [[ "$1" == "-y" ]] || [[ "$CI" == "1" ]] || [[ "$CI" == "true" ]]; then
2424
CI="1"
2525
fi
2626

27-
# Use curl to fetch the latest release data
28-
echo "Fetching the latest release information..."
29-
RELEASE_JSON=$(curl -s -L https://api.github.com/repos/DefangLabs/defang/releases/latest)
27+
# check if DEFANG_INSTALL_VERSION is set and set the release path accordingly
28+
if [[ -z "$DEFANG_INSTALL_VERSION" ]]; then
29+
RELEASE_PATH="latest"
30+
else
31+
RELEASE_PATH="tags/$DEFANG_INSTALL_VERSION"
32+
fi
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)
3037

3138
# Check for curl failure
32-
if [ $? -ne 0 ]; then
33-
echo "Error fetching release information. Please check your connection or if the URL is correct."
39+
if [ -z "$RELEASE_JSON" ]; then
40+
echo "Error fetching release information. Please check your connection or if the version is correct."
3441
return 1
3542
fi
3643

@@ -73,7 +80,7 @@ elif [ "$OS" = "Linux" ]; then
7380
fi
7481

7582
# Download the file
76-
if ! curl -s -L "$DOWNLOAD_URL" -o "$FILENAME"; then
83+
if ! curl -s -f -L "$DOWNLOAD_URL" -o "$FILENAME"; then
7784
echo "Download failed. Please check your internet connection and try again."
7885
return 4
7986
fi
@@ -232,5 +239,5 @@ rm "$FILENAME"
232239
echo "Installation completed. You can now use defang by typing '$BINARY_NAME' in the terminal."
233240

234241
# Unset the variables and functions to avoid polluting the user's environment
235-
unset EXTRACT_DIR DOWNLOAD_URL RELEASE_JSON ARCH_SUFFIX ARCH OS FILENAME INSTALL_DIR BINARY_NAME REPLY EXPORT_PATH CURRENT_SHELL FOUND_PROFILE_FILE
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
236243
unset -f _prompt_and_append_to_file _generate_completion_script _install_completion_script

0 commit comments

Comments
 (0)