Files
bruno 52823109bc
CI / Lint (push) Failing after 9m35s
CI / Test (push) Failing after 6m4s
CI / Build (darwin/amd64) (push) Skipped
CI / Build (linux/amd64) (push) Skipped
CI / Build (windows/amd64) (push) Skipped
CI / Build (darwin/arm64) (push) Skipped
CI / Build (linux/arm64) (push) Skipped
CI / Build (windows/arm64) (push) Skipped
CI / Release (push) Skipped
fix: resolve latest release dynamically in installers (was hardcoded v0.2.0)
2026-08-14 11:32:19 -04:00

172 lines
5.4 KiB
Bash

#!/usr/bin/env bash
# clip-sync install.sh
# One-liner install: curl -sSL URL | bash
#
# Detects OS and architecture, downloads the correct binary,
# installs to ~/.local/bin/, and creates a default config.
set -euo pipefail
REPO="https://git.dracodev.net/Projets/clip-sync"
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() {
local os arch
case "$(uname -s)" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
*)
echo "clip-sync: unsupported OS: $(uname -s)"
exit 1
;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*)
echo "clip-sync: unsupported architecture: $(uname -m)"
exit 1
;;
esac
echo "${os}-${arch}"
}
# ── Download binary ────────────────────────────────────────────────────
download_binary() {
local platform="$1"
local bin_name="${BINARY}-${platform}"
local download_url="${REPO}/releases/download/${VERSION}/${bin_name}"
# Windows binary has .exe extension
if [[ "$platform" == windows-* ]]; then
bin_name="${bin_name}.exe"
download_url="${download_url}.exe"
fi
local out_path="${INSTALL_DIR}/${bin_name}"
echo "clip-sync: downloading ${download_url}..."
if command -v curl &>/dev/null; then
curl -fSL --progress-bar -o "${out_path}" "${download_url}" || {
echo "clip-sync: download failed. Try building from source:"
echo " git clone ${REPO} && cd clip-sync && make install"
exit 1
}
elif command -v wget &>/dev/null; then
wget -q --show-progress -O "${out_path}" "${download_url}" || {
echo "clip-sync: download failed. Try building from source:"
echo " git clone ${REPO} && cd clip-sync && make install"
exit 1
}
else
echo "clip-sync: curl or wget required for download"
exit 1
fi
chmod +x "${out_path}"
echo "clip-sync: installed to ${out_path}"
}
# ── Create default config ──────────────────────────────────────────────
create_config() {
if [ -f "${CONFIG_FILE}" ]; then
echo "clip-sync: config already exists at ${CONFIG_FILE} (skipping)"
return
fi
mkdir -p "${CONFIG_DIR}"
cat > "${CONFIG_FILE}" <<'EOF'
# clip-sync peers configuration
# ~/.config/clip-sync/peers.toml
#
# Environment overrides:
# CLIP_SYNC_PORT=9137 override daemon.port
# CLIP_SYNC_POLL_MS=500 override daemon.poll_interval_ms
# CLIP_SYNC_KEY=... override security.shared_key
[daemon]
port = 9137
poll_interval_ms = 500
# discovery = true # enable mDNS auto-discovery of peers
# notify = true # enable desktop notifications
# sync_images = true # sync images from the clipboard (PNG)
# receive_files = true # accept incoming file transfers
[security]
# shared_key = "..." # generate with: clip-sync --generate-key
# Add your peers here:
# [[peers]]
# name = "example"
# addr = "192.168.1.x:9137"
EOF
echo "clip-sync: created default config at ${CONFIG_FILE}"
echo "clip-sync: edit it to add your peers, then run: ${BINARY}"
}
# ── Main ────────────────────────────────────────────────────────────────
main() {
echo "clip-sync installer"
echo "==================="
echo ""
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
# Check if install dir is in PATH
if ! echo "${PATH}" | tr ':' '\n' | grep -qF "${INSTALL_DIR}"; then
echo ""
echo "clip-sync: NOTE: ${INSTALL_DIR} is not in your PATH."
echo " Add this to your shell config:"
echo " export PATH=\"\${HOME}/.local/bin:\${PATH}\""
fi
echo ""
echo "clip-sync: installation complete!"
echo " 1. Edit ${CONFIG_FILE} to add your peers"
echo " 2. Run: ${BINARY}"
echo ""
echo " For service installation, see README.md"
}
main