154 lines
4.7 KiB
Bash
154 lines
4.7 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"
|
|
VERSION="${CLIP_SYNC_VERSION:-v0.2.0}"
|
|
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="${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}"
|
|
|
|
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
|