#!/usr/bin/env bash # NodeMesh Agent Installer # Usage: curl -sSL https://nodemesh.app/install.sh | bash -s -- --token YOUR_TOKEN # or: bash install.sh --token YOUR_TOKEN # # This script: # 1. Detects the host OS/arch # 2. Downloads the nodemesh-agent binary # 3. Creates the config at /etc/nodemesh/agent.env # 4. Installs and starts a systemd service set -euo pipefail BACKEND_ADDR="${NODEMESH_BACKEND_ADDR:-api.nodemesh.app:9000}" DOWNLOAD_BASE="${NODEMESH_DOWNLOAD_BASE:-https://nodemesh.app/releases}" INSTALL_DIR="/usr/local/bin" CONFIG_DIR="/etc/nodemesh" DATA_DIR="/opt/nodemesh/data/instances" SERVICE_FILE="/etc/systemd/system/nodemesh-agent.service" TOKEN="" # ── parse flags ─────────────────────────────────────────────────────────────── while [[ $# -gt 0 ]]; do case "$1" in --token) TOKEN="$2" shift 2 ;; --backend) BACKEND_ADDR="$2" shift 2 ;; --data-dir) DATA_DIR="$2" shift 2 ;; *) echo "Unknown flag: $1" >&2 exit 1 ;; esac done if [[ -z "$TOKEN" ]]; then echo "NodeMesh Agent Installer" echo "" read -rp "Paste your pairing token: " TOKEN fi if [[ -z "$TOKEN" ]]; then echo "Error: pairing token is required." >&2 exit 1 fi # ── detect platform ─────────────────────────────────────────────────────────── OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" case "$ARCH" in x86_64) ARCH="amd64" ;; aarch64) ARCH="arm64" ;; armv7l) ARCH="arm" ;; *) echo "Unsupported architecture: $ARCH" >&2 exit 1 ;; esac if [[ "$OS" != "linux" ]]; then echo "Only Linux is supported by the NodeMesh agent." >&2 exit 1 fi BINARY="nodemesh-agent-linux-${ARCH}" DOWNLOAD_URL="${DOWNLOAD_BASE}/${BINARY}" # ── check for systemd ───────────────────────────────────────────────────────── if ! command -v systemctl &>/dev/null; then echo "Error: systemd is required to install the NodeMesh agent service." >&2 exit 1 fi # ── download binary ─────────────────────────────────────────────────────────── echo "→ Downloading NodeMesh agent (${ARCH})…" TMP="$(mktemp)" if command -v curl &>/dev/null; then curl -sSL "$DOWNLOAD_URL" -o "$TMP" elif command -v wget &>/dev/null; then wget -qO "$TMP" "$DOWNLOAD_URL" else echo "Error: curl or wget is required." >&2 exit 1 fi chmod +x "$TMP" mv "$TMP" "${INSTALL_DIR}/nodemesh-agent" echo " ✓ Installed to ${INSTALL_DIR}/nodemesh-agent" # ── create config ───────────────────────────────────────────────────────────── echo "→ Writing config to ${CONFIG_DIR}/agent.env…" mkdir -p "$CONFIG_DIR" cat > "${CONFIG_DIR}/agent.env" < "$SERVICE_FILE" <