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.
@@ -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'.21
RUN_AS="${SUDO_USER:-pi}"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
bool_is_true() {24
bool_is_true() {25
case "${1,,}" in25
case "${1,,}" in@@ -32,6 +32,32 @@ bool_is_true() {32
esac32
esac33
}33
}34
34
35
confirm_root_service_mode() {36
if [[ ! -t 0 ]]; then37
echo "[install] Non-interactive shell detected; defaulting to non-root service mode." >&238
return 139
fi40
41
local reply42
read -r -p "[install] Run the filemanager service as root? [y/N] " reply43
case "${reply,,}" in44
y|yes)45
return 046
;;47
*)48
return 149
;;50
esac51
}52
53
if [[ -n "${FILEMANAGER_SERVICE_RUN_AS_ROOT:-}" ]]; then54
SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT}"55
elif confirm_root_service_mode; then56
SERVICE_RUN_AS_ROOT="1"57
else58
SERVICE_RUN_AS_ROOT="0"59
fi60
35
SERVICE_USER_LINE="User=${RUN_AS}"61
SERVICE_USER_LINE="User=${RUN_AS}"36
SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'62
SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'37
SERVICE_ENV_LINE=""63
SERVICE_ENV_LINE=""@@ -45,7 +71,7 @@ fi45
echo "[install] Project directory : $SCRIPT_DIR"71
echo "[install] Project directory : $SCRIPT_DIR"46
if bool_is_true "$SERVICE_RUN_AS_ROOT"; then72
if bool_is_true "$SERVICE_RUN_AS_ROOT"; then47
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"49
else75
else50
echo "[install] Service will run as user: $RUN_AS"76
echo "[install] Service will run as user: $RUN_AS"51
fi77
fi