diff --git a/install.ps1 b/install.ps1 index eebb648..f4635be 100644 --- a/install.ps1 +++ b/install.ps1 @@ -8,8 +8,21 @@ $ErrorActionPreference = 'Stop' -$Version = if ($env:CLIP_SYNC_VERSION) { $env:CLIP_SYNC_VERSION } else { 'v0.2.0' } +$Version = if ($env:CLIP_SYNC_VERSION) { $env:CLIP_SYNC_VERSION } else { 'latest' } $Repo = 'https://git.dracodev.net/Projets/clip-sync' +$ApiBase = 'https://git.dracodev.net/api/v1/repos/Projets/clip-sync' + +# ── Resolve version ─────────────────────────────────────────────────── + +if ($Version -eq 'latest') { + try { + $release = Invoke-RestMethod "$ApiBase/releases/latest" -UseBasicParsing + $Version = $release.tag_name + if (-not $Version) { throw 'no tag_name' } + } catch { + throw "clip-sync: no release found. Publish one (git tag v0.2.0 && git push origin v0.2.0), or build from source: git clone $Repo && cd clip-sync && make install" + } +} # ── Detect architecture ─────────────────────────────────────────────── diff --git a/install.sh b/install.sh index db891bf..6cf0fd5 100644 --- a/install.sh +++ b/install.sh @@ -8,12 +8,27 @@ set -euo pipefail REPO="https://git.dracodev.net/Projets/clip-sync" -VERSION="${CLIP_SYNC_VERSION:-v0.2.0}" +API_BASE="https://git.dracodev.net/api/v1/repos/Projets/clip-sync" +VERSION="${CLIP_SYNC_VERSION:-latest}" BINARY="clip-sync" INSTALL_DIR="${HOME}/.local/bin" CONFIG_DIR="${HOME}/.config/clip-sync" CONFIG_FILE="${CONFIG_DIR}/peers.toml" +# ── Resolve version ──────────────────────────────────────────────────── + +resolve_version() { + if [ "$VERSION" = "latest" ]; then + VERSION="$(curl -fsSL "${API_BASE}/releases/latest" \ + | sed -n 's/.*"tag_name":"\([^"]*\)".*/\1/p' | head -n1)" + if [ -z "$VERSION" ]; then + echo "clip-sync: no release found. Publish one (git tag v0.2.0 && git push origin v0.2.0)" >&2 + echo " or build from source: git clone ${REPO} && cd clip-sync && make install" >&2 + exit 1 + fi + fi +} + # ── Detect platform ──────────────────────────────────────────────────── detect_platform() { @@ -127,9 +142,12 @@ main() { mkdir -p "${INSTALL_DIR}" + resolve_version + local platform platform=$(detect_platform) echo "clip-sync: detected platform: ${platform}" + echo "clip-sync: version: ${VERSION}" download_binary "${platform}" create_config