From 4b42f6573d14ac0a065484d9642ef8d36f1d58b7 Mon Sep 17 00:00:00 2001 From: auxten Date: Fri, 19 Jul 2024 16:04:15 +0800 Subject: [PATCH 1/4] Update install_libchdb.sh --- install_libchdb.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/install_libchdb.sh b/install_libchdb.sh index 6740406..860a156 100644 --- a/install_libchdb.sh +++ b/install_libchdb.sh @@ -8,6 +8,10 @@ command -v tar >/dev/null 2>&1 || { echo >&2 "tar is required but it's not insta # 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/') +if [[ $? -ne 0 ]]; then + echo "Error fetching the latest release version, trying the fallback URL." + LATEST_RELEASE="latest" # Using 'latest' as the fallback release version +fi # Select the correct package based on OS and architecture case "$(uname -s)" in @@ -32,16 +36,26 @@ case "$(uname -s)" in esac 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 +if ! curl -L -o libchdb.tar.gz $DOWNLOAD_URL; then + echo "Failed to download the package, attempting to download from fallback URL." + if ! curl -L -o libchdb.tar.gz $FALLBACK_URL; then + echo "Failed to download the package from both primary and fallback URLs. Aborting." + exit 1 + fi +fi # Optional: Verify download integrity here, if checksums are provided # Untar the file -tar -xzf libchdb.tar.gz +if ! tar -xzf libchdb.tar.gz; then + echo "Failed to extract the package. Aborting." + exit 1 +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 From c9d6066501b3145e91295f2ff83914353da003ab Mon Sep 17 00:00:00 2001 From: auxten Date: Fri, 19 Jul 2024 16:12:22 +0800 Subject: [PATCH 2/4] Update install_libchdb.sh --- install_libchdb.sh | 53 +++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/install_libchdb.sh b/install_libchdb.sh index 860a156..573b7af 100644 --- a/install_libchdb.sh +++ b/install_libchdb.sh @@ -1,17 +1,39 @@ #!/bin/bash -set -e +set -u # Treat unset variables as an error # Check for necessary tools 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 + else + echo "Failed to extract the file." + fi + else + echo "Failed to download the file." + 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/') -if [[ $? -ne 0 ]]; then - echo "Error fetching the latest release version, trying the fallback URL." - LATEST_RELEASE="latest" # Using 'latest' as the fallback release version -fi # Select the correct package based on OS and architecture case "$(uname -s)" in @@ -35,28 +57,19 @@ 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 -if ! curl -L -o libchdb.tar.gz $DOWNLOAD_URL; then - echo "Failed to download the package, attempting to download from fallback URL." - if ! curl -L -o libchdb.tar.gz $FALLBACK_URL; then - echo "Failed to download the package from both primary and fallback URLs. Aborting." +# 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 -# Optional: Verify download integrity here, if checksums are provided - -# Untar the file -if ! tar -xzf libchdb.tar.gz; then - echo "Failed to extract the package. Aborting." - exit 1 -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 command -v sudo >/dev/null 2>&1 || { echo >&2 "This script requires sudo privileges but sudo is not installed. Aborting."; exit 1; } From 82ff8f672fb588045d30041ff26a39736acb46cc Mon Sep 17 00:00:00 2001 From: auxten Date: Fri, 19 Jul 2024 16:16:15 +0800 Subject: [PATCH 3/4] Update install_libchdb.sh --- install_libchdb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_libchdb.sh b/install_libchdb.sh index 573b7af..b3ca376 100644 --- a/install_libchdb.sh +++ b/install_libchdb.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -u # Treat unset variables as an error +set -e # Check for necessary tools command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required but it's not installed. Aborting."; exit 1; } From 7af48ba75272b346320d8dea0eb75a90d449eeda Mon Sep 17 00:00:00 2001 From: auxten Date: Fri, 19 Jul 2024 16:20:41 +0800 Subject: [PATCH 4/4] Update install_libchdb.sh --- install_libchdb.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/install_libchdb.sh b/install_libchdb.sh index b3ca376..fb1ad45 100644 --- a/install_libchdb.sh +++ b/install_libchdb.sh @@ -23,11 +23,7 @@ download_and_extract() { if tar -xzf "$file"; then echo "Extraction successful." return 0 - else - echo "Failed to extract the file." fi - else - echo "Failed to download the file." fi return 1 } @@ -115,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