Skip to content

Commit

Permalink
Update installation script with improved version fetching and error h…
Browse files Browse the repository at this point in the history
…andling
  • Loading branch information
XiaoConstantine committed Jul 3, 2024
1 parent 5f99c8e commit 3329e85
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
set -e

RELEASES_URL="https://github.com/XiaoConstantine/mycli/releases"
GITHUB_REPO="XiaoConstantine/mycli"
BINARY_NAME="mycli"

detect_platform() {
Expand Down Expand Up @@ -30,9 +30,23 @@ if [ "$PLATFORM" = "unsupported" ] || [ "$ARCH" = "unsupported" ]; then
exit 1
fi

VERSION=$(curl -sL ${RELEASES_URL}/latest | sed -n 's/.*tag\/\(.*\)".*/\1/p')
DOWNLOAD_URL="${RELEASES_URL}/download/${VERSION}/${BINARY_NAME}_${PLATFORM}_${ARCH}.tar.gz"
# Fetch the latest release version
VERSION=$(curl -s https://api.github.com/repos/${GITHUB_REPO}/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

if [ -z "$VERSION" ]; then
echo "Failed to fetch the latest version. Please check your internet connection or install manually."
exit 1
fi

DOWNLOAD_URL="https://github.com/${GITHUB_REPO}/releases/download/${VERSION}/${BINARY_NAME}_${PLATFORM}_${ARCH}.tar.gz"

echo "Downloading ${BINARY_NAME} version ${VERSION} for ${PLATFORM}_${ARCH}..."
curl -L "$DOWNLOAD_URL" | tar xz -C /tmp
if [ $? -ne 0 ]; then
echo "Failed to download or extract the binary. Please check the URL or install manually."
echo "Download URL: $DOWNLOAD_URL"
exit 1
fi

sudo mv /tmp/${BINARY_NAME} /usr/local/bin/
echo "Installation complete. You can now use '${BINARY_NAME}' command."

0 comments on commit 3329e85

Please sign in to comment.