BlueGit

timfa filemanager

Prompt for root service mode

The installer now asks whether to run the service as root using a y/N prompt. For automation and non-interactive installs, FILEMANAGER_SERVICE_RUN_AS_ROOT still works as an explicit override.

timfa Tim Falken · pushed by timfa

Authored 2026-05-25 · 5 months ago

Hash
7a14be1be0c320613a766949cbffc255c49e7cd7
Parent
e2b05e95
1 file changed +28 −2
installsystemdservice.sh +28 −2
@@ -19,7 +19,7 @@ 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}"
22 SERVICE_RUN_AS_ROOT=""
23 23
24 24 bool_is_true() {
25 25 case "${1,,}" in
@@ -32,6 +32,32 @@ bool_is_true() {
32 32 esac
33 33 }
34 34
35 confirm_root_service_mode() {
36 if [[ ! -t 0 ]]; then
37 echo "[install] Non-interactive shell detected; defaulting to non-root service mode." >&2
38 return 1
39 fi
40
41 local reply
42 read -r -p "[install] Run the filemanager service as root? [y/N] " reply
43 case "${reply,,}" in
44 y|yes)
45 return 0
46 ;;
47 *)
48 return 1
49 ;;
50 esac
51 }
52
53 if [[ -n "${FILEMANAGER_SERVICE_RUN_AS_ROOT:-}" ]]; then
54 SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT}"
55 elif confirm_root_service_mode; then
56 SERVICE_RUN_AS_ROOT="1"
57 else
58 SERVICE_RUN_AS_ROOT="0"
59 fi
60
35 61 SERVICE_USER_LINE="User=${RUN_AS}"
36 62 SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
37 63 SERVICE_ENV_LINE=""
@@ -45,7 +71,7 @@ fi
45 71 echo "[install] Project directory : $SCRIPT_DIR"
46 72 if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
47 73 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"
74 echo "[install] Enabling chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
49 75 else
50 76 echo "[install] Service will run as user: $RUN_AS"
51 77 fi
@@ -19,7 +19,7 @@ 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}"
22SERVICE_RUN_AS_ROOT=""
23
23
24bool_is_true() {
24bool_is_true() {
25 case "${1,,}" in
25 case "${1,,}" in
@@ -32,6 +32,32 @@ bool_is_true() {
32 esac
32 esac
33}
33}
34
34
35confirm_root_service_mode() {
36 if [[ ! -t 0 ]]; then
37 echo "[install] Non-interactive shell detected; defaulting to non-root service mode." >&2
38 return 1
39 fi
40
41 local reply
42 read -r -p "[install] Run the filemanager service as root? [y/N] " reply
43 case "${reply,,}" in
44 y|yes)
45 return 0
46 ;;
47 *)
48 return 1
49 ;;
50 esac
51}
52
53if [[ -n "${FILEMANAGER_SERVICE_RUN_AS_ROOT:-}" ]]; then
54 SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT}"
55elif confirm_root_service_mode; then
56 SERVICE_RUN_AS_ROOT="1"
57else
58 SERVICE_RUN_AS_ROOT="0"
59fi
60
35SERVICE_USER_LINE="User=${RUN_AS}"
61SERVICE_USER_LINE="User=${RUN_AS}"
36SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
62SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
37SERVICE_ENV_LINE=""
63SERVICE_ENV_LINE=""
@@ -45,7 +71,7 @@ fi
45echo "[install] Project directory : $SCRIPT_DIR"
71echo "[install] Project directory : $SCRIPT_DIR"
46if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
72if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
47 echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."
73 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"
74 echo "[install] Enabling chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
49else
75else
50 echo "[install] Service will run as user: $RUN_AS"
76 echo "[install] Service will run as user: $RUN_AS"
51fi
77fi