@@ -11,43 +11,57 @@ set -x
11
11
# Why not use a .config/autostart file? Because the user isn't allowed to chown to root
12
12
# ...even if they are the current owner.
13
13
14
+ # chattr on DESKTOP is to prevent mv'ing DESKTOP to another name, and then creating a new one
15
+ # which they DO have write permissions to
16
+ # Another option considered was chowning /home/user itself (not recursively),
17
+ # but then login didn't work. (maybe due to .xauthority?)
18
+
14
19
if get_os2borgerpc_config os2_product | grep --quiet kiosk; then
15
20
echo " Dette script er ikke designet til at blive anvendt på en kiosk-maskine."
16
21
exit 1
17
22
fi
18
23
19
- USER=" user"
20
- DESKTOP=" Skrivebord"
24
+ USERNAME=" user"
25
+ # Determine the name of the user desktop directory. This is done via xdg-user-dir,
26
+ # which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
27
+ # we run xdg-user-dirs-update, which generates it based on the environment variable
28
+ # LANG. This variable is empty in lightdm so we first export it
29
+ # based on the value stored in /etc/default/locale
30
+ export " $( grep LANG= /etc/default/locale) "
31
+ runuser -u $USERNAME xdg-user-dirs-update
32
+ DESKTOP=$( basename " $( runuser -u $USERNAME xdg-user-dir DESKTOP) " )
21
33
USER_CLEANUP=/usr/share/os2borgerpc/bin/user-cleanup.bash
22
- SET_USER_DESKTOP_MUTABLE=" chattr -i /home/$USER /$DESKTOP "
23
- SET_USER_DESKTOP_ROOT_OWNED=" chown -R root:user /home/$USER /$DESKTOP "
24
- # This is to prevent mv'ing Skrivebord to another name, and then creating a new one
25
- # which they DO have write permissions to
26
- # Another option considered was chowning /home/user itself (not recursively),
27
- # but then login didn't work. (maybe due to .xauthority?)
28
- SET_USER_DESKTOP_IMMUTABLE=" chattr +i /home/$USER /$DESKTOP "
34
+ COMMENT=" # Make the desktop read only to user"
29
35
30
36
ACTIVATE=$1
31
37
32
38
make_desktop_writable () {
33
- sed -i " \@$SET_USER_DESKTOP_MUTABLE @d" $USER_CLEANUP
34
- sed -i " \@$SET_USER_DESKTOP_ROOT_OWNED @d" $USER_CLEANUP
35
- sed -i " \@$SET_USER_DESKTOP_IMMUTABLE @d" $USER_CLEANUP
36
- chattr -i /home/$USER /$DESKTOP
39
+ # All of the matched lines are deleted. This function thus serves to undo write access removal
40
+ # shellcheck disable=SC2016
41
+ sed --in-place --expression " /chattr [-+]i/d" --expression " /chown -R root:/d" \
42
+ --expression " /$COMMENT /d" --expression ' /runuser/d' --expression ' /export/d' $USER_CLEANUP
43
+ chattr -i " $DESKTOP "
37
44
}
38
45
39
- # Make sure that /home/.skjult/Skrivebord exists as otherwise this script will not work correctly
40
- mkdir --parents /home/.skjult/Skrivebord
46
+ # Make sure that DESKTOP dir exists under .skjult as otherwise this script will not work correctly
47
+ mkdir --parents " /home/.skjult/$( basename " $DESKTOP " ) "
41
48
42
- # Undo write access removal.
43
- # We always do this to prevent adding the same lines multiple times (idempotency)
49
+ # Undo write access removal - always do this to prevent adding the same lines multiple times (idempotency)
44
50
make_desktop_writable
45
51
46
52
if [ " $ACTIVATE " = ' True' ]; then
47
- # Temporarily set it mutable before copying new files in, as otherwise that will fail
48
- sed -i " /USERNAME=\" user\" /a $SET_USER_DESKTOP_MUTABLE " $USER_CLEANUP
53
+ # Prepend temporarily setting DESKTOP mutable before copying new files in, as otherwise that will fail
54
+ # We first determine the name of the user desktop directory as before
55
+ sed -i " /USERNAME=\" $USERNAME \" /a \
56
+ export \$ (grep LANG= \/etc\/default\/locale)\n\
57
+ runuser -u $USERNAME xdg-user-dirs-update\n\
58
+ DESKTOP=\$ (runuser -u $USERNAME xdg-user-dir DESKTOP)\n\
59
+ chattr -i \$ DESKTOP" $USER_CLEANUP
60
+
61
+ # Append setting the more restrictive permissions
49
62
cat << - EOF >> $USER_CLEANUP
50
- $SET_USER_DESKTOP_ROOT_OWNED
51
- $SET_USER_DESKTOP_IMMUTABLE
63
+ $COMMENT
64
+ chown -R root:\$ USERNAME \$ DESKTOP
65
+ chattr +i \$ DESKTOP
52
66
EOF
53
67
fi
0 commit comments