#!/usr/bin/env bash # Idempotent install of a persistent Herdr daemon for the current user. # Autodetects Linux (systemd --user) vs macOS (launchd LaunchAgent). # # Usage (locally): # ./install.sh # Usage (remote): # scp -r deploy/fleet/herdr-persistence :/tmp/ # ssh 'bash -lc "/tmp/herdr-persistence/install.sh"' # # Preconditions: `herdr` is installed at $HOME/.local/bin/herdr # (via `curl -fsSL https://herdr.dev/install.sh | sh`). set -euo pipefail here="$(cd "$(dirname "$0")" && pwd)" herdr="$HOME/.local/bin/herdr" if [ ! -x "$herdr" ]; then echo "herdr binary not found at $herdr — run the herdr install script first." >&2 exit 1 fi os="$(uname -s)" case "$os" in Linux) unit_dir="$HOME/.config/systemd/user" unit="$unit_dir/herdr.service" mkdir -p "$unit_dir" cp "$here/herdr.service" "$unit" # Enable lingering so the user's systemd manager runs without a # login session — otherwise the daemon dies at logout. if command -v loginctl >/dev/null 2>&1; then sudo loginctl enable-linger "$USER" 2>/dev/null || true fi systemctl --user daemon-reload systemctl --user enable --now herdr.service systemctl --user status --no-pager herdr.service | head -8 ;; Darwin) plist_dir="$HOME/Library/LaunchAgents" plist="$plist_dir/dev.herdr.server.plist" mkdir -p "$plist_dir" sed \ -e "s|__HERDR_BIN__|$herdr|g" \ -e "s|__HOME__|$HOME|g" \ "$here/dev.herdr.plist" > "$plist" # Unload first so a re-install replaces cleanly. launchctl unload "$plist" 2>/dev/null || true launchctl load -w "$plist" sleep 1 launchctl list | grep dev.herdr.server || echo "(agent not in list yet)" ;; *) echo "unsupported OS: $os" >&2 exit 2 ;; esac echo echo "herdr daemon persistence installed. Verify with: herdr status server"