BlueGit

timfa filemanager

Add optional root service install mode

The service installer now supports an explicit root-run mode via FILEMANAGER_SERVICE_RUN_AS_ROOT=1. In root mode it omits the User directive and enables recursive chmod-on-list via service environment settings so access repair works automatically on folder refresh.

timfa Tim Falken · pushed by timfa

Authored 2026-05-25 · 5 months ago

Hash
ebc01089251dddb19a51c5e43d6c1bf48eade542
Parent
79ac5be9
1 file changed +31 −4
installsystemdservice.sh +31 −4
@@ -19,9 +19,36 @@ KNOWN_PACKAGE_MANAGERS=(apt-get apt dnf yum pacman zypper apk)
19 19 # Resolve the user who owns the project directory (i.e. the user who cloned it,
20 20 # not root). Falls back to the SUDO_USER env var, then 'pi'.
21 21 RUN_AS="${SUDO_USER:-pi}"
22 SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT:-0}"
23
24 bool_is_true() {
25 case "${1,,}" in
26 1|true|yes|on)
27 return 0
28 ;;
29 *)
30 return 1
31 ;;
32 esac
33 }
34
35 SERVICE_USER_LINE="User=${RUN_AS}"
36 SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
37 SERVICE_ENV_LINE=""
38
39 if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
40 SERVICE_USER_LINE="# Running as root (User= omitted intentionally)"
41 SERVICE_CAPABILITY_LINES="# Root mode selected: privileged-port capability lines not required"
42 SERVICE_ENV_LINE="Environment=FILEMANAGER_LIST_ACCESS_CHMOD=1"
43 fi
22 44
23 45 echo "[install] Project directory : $SCRIPT_DIR"
24 echo "[install] Service will run as user: $RUN_AS"
46 if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
47 echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."
48 echo "[install] Enabling recursive chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
49 else
50 echo "[install] Service will run as user: $RUN_AS"
51 fi
25 52
26 53 log_warn() {
27 54 echo "[install][warn] $*" >&2
@@ -141,14 +168,14 @@ After=network.target
141 168
142 169 [Service]
143 170 Type=simple
144 User=${RUN_AS}
171 ${SERVICE_USER_LINE}
145 172 WorkingDirectory=${SCRIPT_DIR}
146 173 ExecStart=/bin/sh ${SCRIPT_DIR}/start.sh
147 174 Restart=always
148 175 RestartSec=5
149 176 # Allow binding to privileged ports (< 1024) without running as root.
150 AmbientCapabilities=CAP_NET_BIND_SERVICE
151 CapabilityBoundingSet=CAP_NET_BIND_SERVICE
177 ${SERVICE_CAPABILITY_LINES}
178 ${SERVICE_ENV_LINE}
152 179
153 180 [Install]
154 181 WantedBy=multi-user.target
@@ -19,9 +19,36 @@ KNOWN_PACKAGE_MANAGERS=(apt-get apt dnf yum pacman zypper apk)
19# Resolve the user who owns the project directory (i.e. the user who cloned it,
19# Resolve the user who owns the project directory (i.e. the user who cloned it,
20# not root). Falls back to the SUDO_USER env var, then 'pi'.
20# not root). Falls back to the SUDO_USER env var, then 'pi'.
21RUN_AS="${SUDO_USER:-pi}"
21RUN_AS="${SUDO_USER:-pi}"
22SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT:-0}"
23
24bool_is_true() {
25 case "${1,,}" in
26 1|true|yes|on)
27 return 0
28 ;;
29 *)
30 return 1
31 ;;
32 esac
33}
34
35SERVICE_USER_LINE="User=${RUN_AS}"
36SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
37SERVICE_ENV_LINE=""
38
39if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
40 SERVICE_USER_LINE="# Running as root (User= omitted intentionally)"
41 SERVICE_CAPABILITY_LINES="# Root mode selected: privileged-port capability lines not required"
42 SERVICE_ENV_LINE="Environment=FILEMANAGER_LIST_ACCESS_CHMOD=1"
43fi
22
44
23echo "[install] Project directory : $SCRIPT_DIR"
45echo "[install] Project directory : $SCRIPT_DIR"
24echo "[install] Service will run as user: $RUN_AS"
46if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
47 echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."
48 echo "[install] Enabling recursive chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
49else
50 echo "[install] Service will run as user: $RUN_AS"
51fi
25
52
26log_warn() {
53log_warn() {
27 echo "[install][warn] $*" >&2
54 echo "[install][warn] $*" >&2
@@ -141,14 +168,14 @@ After=network.target
141
168
142[Service]
169[Service]
143Type=simple
170Type=simple
144User=${RUN_AS}
171${SERVICE_USER_LINE}
145WorkingDirectory=${SCRIPT_DIR}
172WorkingDirectory=${SCRIPT_DIR}
146ExecStart=/bin/sh ${SCRIPT_DIR}/start.sh
173ExecStart=/bin/sh ${SCRIPT_DIR}/start.sh
147Restart=always
174Restart=always
148RestartSec=5
175RestartSec=5
149# Allow binding to privileged ports (< 1024) without running as root.
176# Allow binding to privileged ports (< 1024) without running as root.
150AmbientCapabilities=CAP_NET_BIND_SERVICE
177${SERVICE_CAPABILITY_LINES}
151CapabilityBoundingSet=CAP_NET_BIND_SERVICE
178${SERVICE_ENV_LINE}
152
179
153[Install]
180[Install]
154WantedBy=multi-user.target
181WantedBy=multi-user.target