|
| 1 | +#! /usr/bin/env sh |
| 2 | + |
| 3 | +set -x |
| 4 | + |
| 5 | +if get_os2borgerpc_config os2_product | grep --quiet kiosk; then |
| 6 | + echo "Dette script er ikke designet til at blive anvendt på en kiosk-maskine." |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +USERNAME=user |
| 11 | +SHADOW=.skjult |
| 12 | +GIO_LAUNCHER=/usr/share/os2borgerpc/bin/gio-fix-desktop-file-permissions.sh |
| 13 | +GIO_SCRIPT=/usr/share/os2borgerpc/bin/gio-dbus.sh |
| 14 | +USER_CLEANUP=/usr/share/os2borgerpc/bin/user-cleanup.bash |
| 15 | + |
| 16 | +# Cleanup if they've run previous versions of this script. Suppress deletion errors. |
| 17 | +rm --force /home/$SHADOW/.config/autostart/gio-fix-desktop-file-permissions.desktop |
| 18 | + |
| 19 | +# Script that actually runs gio as the user and kills the dbus session it creates to do so |
| 20 | +# afterwards |
| 21 | +cat << EOF > "$GIO_SCRIPT" |
| 22 | +#! /usr/bin/env sh |
| 23 | +
|
| 24 | +# gio needs to run as the user + dbus-launch, we have this script to create it and kill it afterwards |
| 25 | +export \$(dbus-launch) |
| 26 | +DBUS_PROCESS=\$\$ |
| 27 | +
|
| 28 | +# Determine the name of the user desktop directory. This can be done simply |
| 29 | +# because this file is run as user during the execution of GIO_LAUNCHER |
| 30 | +# which already makes sure that /home/user/.config/user-dirs.dirs exists |
| 31 | +DESKTOP=\$(xdg-user-dir DESKTOP) |
| 32 | +
|
| 33 | +for FILE in \$DESKTOP/*.desktop; do |
| 34 | + gio set "\$FILE" metadata::trusted true |
| 35 | +done |
| 36 | +
|
| 37 | +kill \$DBUS_PROCESS |
| 38 | +EOF |
| 39 | + |
| 40 | +# Script to activate programs on the desktop |
| 41 | +# (equivalent to right-click -> Allow Launching) |
| 42 | +cat << EOF > "$GIO_LAUNCHER" |
| 43 | +#! /usr/bin/env sh |
| 44 | +
|
| 45 | +# Determine the name of the user desktop directory. This is done via xdg-user-dir, |
| 46 | +# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists, |
| 47 | +# we run xdg-user-dirs-update, which generates it based on the environment variable |
| 48 | +# LANG. This variable is empty in lightdm so we first export it |
| 49 | +# based on the value stored in /etc/default/locale |
| 50 | +export \$(grep LANG= /etc/default/locale | tr -d '"') |
| 51 | +runuser -u user xdg-user-dirs-update |
| 52 | +DESKTOP=\$(runuser -u $USERNAME xdg-user-dir DESKTOP) |
| 53 | +
|
| 54 | +# Gio expects the user to own the file so temporarily change that |
| 55 | +for FILE in \$DESKTOP/*.desktop; do |
| 56 | + chown $USERNAME:$USERNAME \$FILE |
| 57 | +done |
| 58 | +
|
| 59 | +su --login user --command $GIO_SCRIPT |
| 60 | +
|
| 61 | +# Now set the permissions back to their restricted form |
| 62 | +for FILE in \$DESKTOP/*.desktop; do |
| 63 | + chown root:$USERNAME "\$FILE" |
| 64 | + # In order for gio changes to take effect, it is necessary to update the file time stamp |
| 65 | + # This can be done with many commands such as chmod or simply touch |
| 66 | + # However, in some cases the files might not have execute permission so we add it with chmod |
| 67 | + chmod ug+x "\$FILE" |
| 68 | +done |
| 69 | +EOF |
| 70 | + |
| 71 | +chmod u+x "$GIO_LAUNCHER" |
| 72 | +chmod +x "$GIO_SCRIPT" |
| 73 | + |
| 74 | +# Cleanup if there are previous entries of the gio fix script in the file |
| 75 | +sed --in-place "\@$GIO_LAUNCHER@d" $USER_CLEANUP |
| 76 | + |
| 77 | +# Make sure to insert this line before the desktop is made immutable |
| 78 | +# in case desktop_toggle_writable has already been run |
| 79 | +# Also make sure to only insert the line once |
| 80 | +sed -i "0,\@chown -R \$USERNAME:\$USERNAME /home/\$USERNAME@ s@@&\n$GIO_LAUNCHER@" $USER_CLEANUP |
0 commit comments