#!/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" 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" # ── 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 if [ "$VERSION" = "latest" ]; then # Try latest release download_url="${REPO}/releases/download/latest/${bin_name}" else download_url="${REPO}/releases/download/${VERSION}/${bin_name}" fi # Windows binary has .exe extension if [[ "$platform" == windows-* ]]; then bin_name="${bin_name}.exe" download_url="${download_url}.exe" fi echo "clip-sync: downloading ${download_url}..." if command -v curl &>/dev/null; then curl -fSL --progress-bar -o "${INSTALL_DIR}/${BINARY}" "${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 "${INSTALL_DIR}/${BINARY}" "${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 "${INSTALL_DIR}/${BINARY}" echo "clip-sync: installed to ${INSTALL_DIR}/${BINARY}" } # ── 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 [daemon] port = 9137 poll_interval_ms = 500 # 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}" local platform platform=$(detect_platform) echo "clip-sync: detected platform: ${platform}" 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