88 lines
2.2 KiB
Bash
88 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
# GitHub repository information
|
|
REPO_OWNER="Warky-Devs"
|
|
REPO_NAME="go-mdtopdf-helper"
|
|
GITHUB_API="https://api.github.com"
|
|
|
|
# Determine OS and architecture
|
|
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
|
ARCH=$(uname -m)
|
|
|
|
# Convert architecture names to match release naming
|
|
case "${ARCH}" in
|
|
x86_64)
|
|
ARCH="x86_64"
|
|
;;
|
|
aarch64|arm64)
|
|
ARCH="arm64"
|
|
;;
|
|
*)
|
|
echo "Unsupported architecture: ${ARCH}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Convert OS names to match release naming
|
|
case "${OS}" in
|
|
linux)
|
|
OS="Linux"
|
|
;;
|
|
darwin)
|
|
OS="Darwin"
|
|
;;
|
|
mingw*|msys*|cygwin*)
|
|
OS="Windows"
|
|
;;
|
|
*)
|
|
echo "Unsupported operating system: ${OS}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Get the latest release information
|
|
echo "Fetching latest release information..."
|
|
LATEST_RELEASE=$(curl -s "${GITHUB_API}/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest")
|
|
VERSION=$(echo "${LATEST_RELEASE}" | grep -o '"tag_name": "[^"]*' | cut -d'"' -f4)
|
|
VERSION=${VERSION#v} # Remove 'v' prefix if present
|
|
|
|
if [ -z "${VERSION}" ]; then
|
|
echo "Failed to get latest version"
|
|
exit 1
|
|
fi
|
|
|
|
# Construct the asset name
|
|
if [ "${OS}" = "Windows" ]; then
|
|
ASSET_NAME="${REPO_NAME}_${VERSION}_${OS}_${ARCH}.zip"
|
|
else
|
|
ASSET_NAME="${REPO_NAME}_${VERSION}_${OS}_${ARCH}.tar.gz"
|
|
fi
|
|
|
|
# Get the download URL for the asset
|
|
ASSET_URL=$(echo "${LATEST_RELEASE}" | grep -o "\"browser_download_url\": \"[^\"]*${ASSET_NAME}\"" | cut -d'"' -f4)
|
|
|
|
if [ -z "${ASSET_URL}" ]; then
|
|
echo "Failed to find download URL for ${ASSET_NAME}"
|
|
echo "Looking for asset: ${ASSET_NAME}"
|
|
exit 1
|
|
fi
|
|
|
|
# Create bin directory if it doesn't exist
|
|
mkdir -p bin
|
|
|
|
# Download and extract the release
|
|
echo "Downloading ${ASSET_NAME}..."
|
|
if [ "${OS}" = "Windows" ]; then
|
|
curl -L "${ASSET_URL}" -o "bin/${ASSET_NAME}"
|
|
cd bin && unzip "${ASSET_NAME}" && rm "${ASSET_NAME}"
|
|
else
|
|
curl -L "${ASSET_URL}" | tar xz -C bin
|
|
fi
|
|
|
|
# Make the binary executable on Unix-like systems
|
|
if [ "${OS}" != "Windows" ]; then
|
|
chmod +x "bin/go-mdtopdf-helper"
|
|
fi
|
|
|
|
echo "Successfully downloaded and installed go-mdtopdf-helper ${VERSION}"
|
|
echo "Binary location: bin/go-mdtopdf-helper" |