Skip to content

Fix install script #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://github.com/api/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