diff --git a/install_libchdb.sh b/install_libchdb.sh index 6740406..fb1ad45 100644 --- a/install_libchdb.sh +++ b/install_libchdb.sh @@ -6,6 +6,28 @@ set -e command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required but it's not installed. Aborting."; exit 1; } command -v tar >/dev/null 2>&1 || { echo >&2 "tar is required but it's not installed. Aborting."; exit 1; } +# Function to download and extract the file +download_and_extract() { + local url=$1 + local file="libchdb.tar.gz" + + echo "Attempting to download $PLATFORM from $url" + + # Download the file with a retry logic + if curl -L -o "$file" "$url"; then + echo "Download successful." + + # Optional: Verify download integrity here, if checksums are provided + + # Untar the file + if tar -xzf "$file"; then + echo "Extraction successful." + return 0 + fi + fi + return 1 +} + # Get the newest release version LATEST_RELEASE=$(curl --silent "https://api.github.com/repos/chdb-io/chdb/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') @@ -31,17 +53,18 @@ case "$(uname -s)" in ;; esac +# Main download URL DOWNLOAD_URL="https://github.com/chdb-io/chdb/releases/download/$LATEST_RELEASE/$PLATFORM" +FALLBACK_URL="https://github.com/chdb-io/chdb/releases/latest/download/$PLATFORM" -echo "Downloading $PLATFORM from $DOWNLOAD_URL" - -# Download the file -curl -L -o libchdb.tar.gz $DOWNLOAD_URL - -# Optional: Verify download integrity here, if checksums are provided - -# Untar the file -tar -xzf libchdb.tar.gz +# Try the main download URL first +if ! download_and_extract "$DOWNLOAD_URL"; then + echo "Retrying with fallback URL..." + if ! download_and_extract "$FALLBACK_URL"; then + echo "Both primary and fallback downloads failed. Aborting." + exit 1 + fi +fi # If current uid is not 0, check if sudo is available and request the user to input the password if [[ $EUID -ne 0 ]]; then @@ -88,5 +111,5 @@ fi rm -f libchdb.tar.gz libchdb.so chdb.h GREENECHO "Installation completed successfully." ; ENDECHO -REDECHO "If any error occurred, please report it to:" ; ENDECHO -REDECHO " https://github.com/chdb-io/chdb/issues/new/choose" ; ENDECHO +GREENECHO "If any error occurred, please report it to:" ; ENDECHO +GREENECHO " https://github.com/chdb-io/chdb/issues/new/choose" ; ENDECHO