#!/bin/sh set -eu # Must run as root if [ "$(id -u)" -ne 0 ]; then echo "Error: please run as root (e.g., sudo $0)" >&2 exit 1 fi URL="https://install.joingallop.com/gallop-agent" BIN="/usr/local/bin/gallop-agent" SERVICE="/etc/systemd/system/gallop-agent.service" # Pick downloader if command -v wget >/dev/null 2>&1; then DL_WGET=1 elif command -v curl >/dev/null 2>&1; then DL_WGET=0 else echo "Error: need wget or curl installed." >&2 exit 1 fi echo "Installing gallop-agent binary to $BIN..." if [ "$DL_WGET" -eq 1 ]; then wget -qO "$BIN" "$URL" else curl -fsSL -o "$BIN" "$URL" fi if [ ! -s "$BIN" ]; then echo "Error: download failed (file is empty)." >&2 exit 1 fi chmod 0755 "$BIN" # Create service user (optional but recommended) if ! id -u gallop-agent >/dev/null 2>&1; then useradd --system --no-create-home --shell /usr/sbin/nologin gallop-agent fi # Create systemd unit echo "Creating systemd service at $SERVICE..." cat > "$SERVICE" <<'EOF' [Unit] Description=Gallop Agent After=network-online.target Wants=network-online.target [Service] Type=simple User=root Group=root ExecStart=/usr/local/bin/gallop-agent Restart=always RestartSec=5 [Install] WantedBy=multi-user.target EOF # Create writable dirs referenced above install -d -m 0755 -o gallop-agent -g gallop-agent /var/lib/gallop-agent /var/log/gallop-agent # Reload and enable/start systemctl daemon-reload systemctl enable --now gallop-agent echo "Done." echo "Status:" systemctl --no-pager --full status gallop-agent || true echo "Logs:" echo " journalctl -u gallop-agent -f"