Skip to content

Commit 695fa74

Browse files
author
Marcus Funch
committed
Merge branch 'feature/53348_more_polkit_policy_shutdown_variability' into 'master'
Modify polkit policy shutdown for more variability via input parameters See merge request os2borgerpc/os2borgerpc-scripts!165
2 parents 4950523 + 40ff7b7 commit 695fa74

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

os2borgerpc/desktop/polkit_policy_shutdown.sh

+41-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@
77
#+ polkit_policy_shutdown.sh [ENFORCE]
88
#%
99
#% DESCRIPTION
10-
#% This script installs a mandatory PolicyKit policy that prevents the
11-
#% "user" or "lightdm" users from sleeping, hibernating, restarting or
12-
#% shutting down the system.
10+
#% This script installs a mandatory PolicyKit policy that either prevents
11+
#% the "user" or "lightdm" users from suspending the system,
12+
#% prevents the "user" or "lightdm" users from restarting/shutting down
13+
#% the system or prevents both.
1314
#%
14-
#% It takes one optional parameter: whether or not to enforce this policy.
15-
#% Use a boolean to decide whether to enforce the policy or not. A checked box
16-
#% enforces the policy and an unchecked removes it
15+
#% It takes two optional parameters: whether to prevent suspending the system
16+
#% and whether to prevent restart/shutdown.
17+
#% 1. Use a boolean to decide whether or not to prevent the "user" from
18+
#% suspending the system. A checked box prevents suspend and an
19+
#% unchecked box allows it
20+
#% 2. Use a boolean to decide whether or not to prevent the "user" from
21+
#% restarting/shutting down the system. A checked box prevents
22+
#% restart/shutdown and an unchecked box allows it
1723
#%
1824
#================================================================
1925
#- IMPLEMENTATION
2026
#- version polkit_policy_shutdown.sh (magenta.dk) 1.0.0
2127
#- author Alexander Faithfull
28+
#- modified by Andreas Poulsen
2229
#- copyright Copyright 2019, 2020 Magenta ApS
2330
#- license GNU General Public License
2431
@@ -27,6 +34,9 @@
2734
# HISTORY
2835
# 2019/09/25 : af : dconf_policy_shutdown.sh created
2936
# 2020/01/27 : af : This script created based on dconf_policy_shutdown.sh
37+
# 2022/11/01 : ap : This script modified to always disable hibernating/sleeping
38+
# 2022/12/12 : ap : This script modified to allow separately
39+
# disabling restart/shutdown or hibernating/sleeping
3040
#
3141
#================================================================
3242
# END_OF_HEADER
@@ -36,14 +46,32 @@ set -x
3646

3747
POLICY="/etc/polkit-1/localauthority/90-mandatory.d/10-os2borgerpc-no-user-shutdown.pkla"
3848

39-
if [ "$1" = "False" ]; then
40-
rm -f "$POLICY"
41-
else
42-
if [ ! -d "$(dirname "$POLICY")" ]; then
43-
mkdir "$(dirname "$POLICY")"
44-
fi
49+
if [ ! -d "$(dirname "$POLICY")" ]; then
50+
mkdir "$(dirname "$POLICY")"
51+
fi
4552

46-
cat > "$POLICY" <<END
53+
if [ "$1" = "False" ] && [ "$2" = "False" ]; then
54+
rm -f "$POLICY"
55+
elif [ "$1" = "True" ] && [ "$2" = "False" ]; then
56+
cat > "$POLICY" <<END
57+
[Restrict system shutdown]
58+
Identity=unix-user:user;unix-user:lightdm
59+
Action=org.freedesktop.login1.hibernate*;org.freedesktop.login1.suspend*;org.freedesktop.login1.lock-sessions
60+
ResultAny=no
61+
ResultActive=no
62+
ResultInactive=no
63+
END
64+
elif [ "$1" = "False" ] && [ "$2" = "True" ]; then
65+
cat > "$POLICY" <<END
66+
[Restrict system shutdown]
67+
Identity=unix-user:user;unix-user:lightdm
68+
Action=org.freedesktop.login1.power-off*;org.freedesktop.login1.reboot*;org.freedesktop.login1.lock-sessions;org.freedesktop.login1.set-reboot*
69+
ResultAny=no
70+
ResultActive=no
71+
ResultInactive=no
72+
END
73+
else
74+
cat > "$POLICY" <<END
4775
[Restrict system shutdown]
4876
Identity=unix-user:user;unix-user:lightdm
4977
Action=org.freedesktop.login1.hibernate*;org.freedesktop.login1.power-off*;org.freedesktop.login1.reboot*;org.freedesktop.login1.suspend*;org.freedesktop.login1.lock-sessions;org.freedesktop.login1.set-reboot*

0 commit comments

Comments
 (0)