#!/usr/bin/env bash # installsystemdservice.sh — Installs filemanager as a systemd service. # Must be run as root: sudo ./installsystemdservice.sh set -euo pipefail if [[ "$(id -u)" -ne 0 ]]; then echo "Error: this script must be run as root (use sudo)." >&2 exit 1 fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SERVICE_NAME="filemanager" SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" # Resolve the user who owns the project directory (i.e. the user who cloned it, # not root). Falls back to the SUDO_USER env var, then 'pi'. RUN_AS="${SUDO_USER:-pi}" echo "[install] Project directory : $SCRIPT_DIR" echo "[install] Service will run as user: $RUN_AS" # Make sure start.sh is executable chmod +x "$SCRIPT_DIR/start.sh" cat > "$SERVICE_FILE" <