#!/usr/bin/env bash set -euo pipefail REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" AGENT_DIR="$REPO_DIR/apps/device-agent" SERVICE_FILE="$AGENT_DIR/systemd/timelapse-agent.service" log() { echo "[install-agent] $*"; } if [[ "$EUID" -ne 0 ]]; then echo "Please run as root: sudo bash apps/device-agent/scripts/install-agent.sh" exit 1 fi log "Installing Python dependencies..." python3 -m pip install --upgrade pip python3 -m pip install requests log "Creating /etc/timelapse/agent.env if missing..." mkdir -p /etc/timelapse if [[ ! -f /etc/timelapse/agent.env ]]; then cat > /etc/timelapse/agent.env <<'EOF' TL_SERVER_URL=http://localhost:3001 TL_DEVICE_NAME= TL_SERIAL_NO= TL_HEARTBEAT_INTERVAL=30 TL_CLAIM_POLL_INTERVAL=10 TL_CONFIG_DIR=/boot/timelapse EOF chmod 600 /etc/timelapse/agent.env fi log "Installing systemd service..." cp "$SERVICE_FILE" /etc/systemd/system/timelapse-agent.service systemctl daemon-reload systemctl enable timelapse-agent.service systemctl restart timelapse-agent.service log "Done. Check status with:" log " systemctl status timelapse-agent.service" log " journalctl -u timelapse-agent.service -f"