Skip to content

Commit

Permalink
Fix install script (#8)
Browse files Browse the repository at this point in the history
* Update install_libchdb.sh

* Update install_libchdb.sh

* Update install_libchdb.sh

* Update install_libchdb.sh
  • Loading branch information
auxten authored Jul 19, 2024
1 parent a400fd0 commit 7d4cab9
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions install_libchdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/')

Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7d4cab9

Please sign in to comment.