install-agent.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
  4. AGENT_DIR="$REPO_DIR/apps/device-agent"
  5. SERVICE_FILE="$AGENT_DIR/systemd/timelapse-agent.service"
  6. log() { echo "[install-agent] $*"; }
  7. if [[ "$EUID" -ne 0 ]]; then
  8. echo "Please run as root: sudo bash apps/device-agent/scripts/install-agent.sh"
  9. exit 1
  10. fi
  11. log "Installing Python dependencies..."
  12. python3 -m pip install --upgrade pip
  13. python3 -m pip install requests
  14. log "Creating /etc/timelapse/agent.env if missing..."
  15. mkdir -p /etc/timelapse
  16. if [[ ! -f /etc/timelapse/agent.env ]]; then
  17. cat > /etc/timelapse/agent.env <<'EOF'
  18. TL_SERVER_URL=http://localhost:3001
  19. TL_DEVICE_NAME=
  20. TL_SERIAL_NO=
  21. TL_HEARTBEAT_INTERVAL=30
  22. TL_CLAIM_POLL_INTERVAL=10
  23. TL_CONFIG_DIR=/boot/timelapse
  24. EOF
  25. chmod 600 /etc/timelapse/agent.env
  26. fi
  27. log "Installing systemd service..."
  28. cp "$SERVICE_FILE" /etc/systemd/system/timelapse-agent.service
  29. systemctl daemon-reload
  30. systemctl enable timelapse-agent.service
  31. systemctl restart timelapse-agent.service
  32. log "Done. Check status with:"
  33. log " systemctl status timelapse-agent.service"
  34. log " journalctl -u timelapse-agent.service -f"