7
7
# + polkit_policy_shutdown.sh [ENFORCE]
8
8
# %
9
9
# % 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.
13
14
# %
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
17
23
# %
18
24
# ================================================================
19
25
# - IMPLEMENTATION
20
26
# - version polkit_policy_shutdown.sh (magenta.dk) 1.0.0
21
27
# - author Alexander Faithfull
28
+ # - modified by Andreas Poulsen
22
29
# - copyright Copyright 2019, 2020 Magenta ApS
23
30
# - license GNU General Public License
24
31
27
34
# HISTORY
28
35
# 2019/09/25 : af : dconf_policy_shutdown.sh created
29
36
# 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
30
40
#
31
41
# ================================================================
32
42
# END_OF_HEADER
@@ -36,14 +46,32 @@ set -x
36
46
37
47
POLICY=" /etc/polkit-1/localauthority/90-mandatory.d/10-os2borgerpc-no-user-shutdown.pkla"
38
48
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
45
52
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
47
75
[Restrict system shutdown]
48
76
Identity=unix-user:user;unix-user:lightdm
49
77
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