diff --git a/scripts/install.sh b/scripts/install.sh index 260ad82..405627b 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -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() { @@ -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."