Skip to content

Commit 2068734

Browse files
author
Andreas Poulsen
committed
Merge branch 'feature/56040_rewrite_scripts_to_support_language_variability' into 'master'
Feature/56040 rewrite scripts to support language variability See merge request os2borgerpc/os2borgerpc-scripts!213
2 parents d99db10 + 169c664 commit 2068734

12 files changed

+138
-35
lines changed

common/fejlfinding/os2borgerpc_general_debug.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ text() {
1515
printf "\n%s\n" "### $MSG ###"
1616
}
1717

18+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
19+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
20+
# we run xdg-user-dirs-update, which generates it based on the environment variable
21+
# LANG. This variable is empty in lightdm so we first export it
22+
# based on the value stored in /etc/default/locale
23+
export "$(grep LANG= /etc/default/locale)"
24+
runuser -u user xdg-user-dirs-update
25+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
26+
1827
header "General info:"
1928

2029
text "Information about the computer model:"
@@ -39,10 +48,10 @@ text "Check permissions on files in /usr/share/os2borgerpc/bin/"
3948
ls -l /usr/share/os2borgerpc/bin/
4049

4150
text "List programs/files on the desktop:"
42-
ls -l /home/user/Skrivebord/
51+
ls -l /home/user/"$DESKTOP"/
4352

4453
text "Verify this matches what's in the user template (after logout):"
45-
ls -l /home/.skjult/Skrivebord/
54+
ls -l /home/.skjult/"$DESKTOP"/
4655

4756
text "Check the contents of /home/.skjult/"
4857
ls -la /home/.skjult/
@@ -94,13 +103,13 @@ text "Check chrome policies"
94103
cat /etc/opt/chrome/policies/managed/os2borgerpc-defaults.json
95104

96105
USER=".skjult"
97-
DESKTOP_FILE_1=/usr/share/applications/google-chrome.desktop
106+
DESKTOP_FILE_1="/usr/share/applications/google-chrome.desktop"
98107
# In case they've also added Chrome to their desktop
99-
DESKTOP_FILE_2=/home/$USER/Skrivebord/google-chrome.desktop
108+
DESKTOP_FILE_2="/home/$USER/$DESKTOP/google-chrome.desktop"
100109
# In case they've run chrome_autostart.sh.
101110
# The name is no mistake, that one is unfortunately not called google-chrome.desktop
102-
DESKTOP_FILE_3=/home/$USER/.config/autostart/chrome.desktop
103-
DESKTOP_FILE_4=/home/$USER/.local/share/applications/google-chrome.desktop
111+
DESKTOP_FILE_3="/home/$USER/.config/autostart/chrome.desktop"
112+
DESKTOP_FILE_4="/home/$USER/.local/share/applications/google-chrome.desktop"
104113

105114
text "File at $DESKTOP_FILE_1:"
106115
cat "$DESKTOP_FILE_1"

common/system/upgrade_client_and_settings.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ done
1818
# Set the correct, more restrictive permissions on all previous jobs
1919
chmod --recursive 700 /var/lib/os2borgerpc
2020

21+
# Determine the name of the superuser desktop directory.
22+
DESKTOP=$(runuser -u superuser xdg-user-dir DESKTOP)
23+
2124
# More restrictive permissions on /home/superuser
2225
chmod -R 700 /home/superuser
23-
chown -R superuser:superuser /home/superuser/Skrivebord
26+
chown -R superuser:superuser "$DESKTOP"
2427

2528
pip3 install --upgrade os2borgerpc-client

os2borgerpc/chrome/chrome_install.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ fi
6363
export DEBIAN_FRONTEND=noninteractive
6464
DESKTOP_FILE_PATH_1=/usr/share/applications/google-chrome.desktop
6565
# In case a Chrome shortcut has been added to the desktop
66-
DESKTOP_FILE_PATH_2=/home/$USER/Skrivebord/google-chrome.desktop
66+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
67+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
68+
# we run xdg-user-dirs-update, which generates it based on the environment variable
69+
# LANG. This variable is empty in lightdm so we first export it
70+
# based on the value stored in /etc/default/locale
71+
export "$(grep LANG= /etc/default/locale)"
72+
runuser -u user xdg-user-dirs-update
73+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
74+
DESKTOP_FILE_PATH_2=/home/$USER/$DESKTOP/google-chrome.desktop
6775
# In case chrome_autostart.sh has been executed
6876
DESKTOP_FILE_PATH_3=/home/$USER/.config/autostart/chrome.desktop
6977
FILES="$DESKTOP_FILE_PATH_1 $DESKTOP_FILE_PATH_2 $DESKTOP_FILE_PATH_3"

os2borgerpc/chrome/chrome_start_maximized_fullscreen_kiosk.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ SETTING="$1"
2929
USER=".skjult"
3030
DESKTOP_FILE_1=/usr/share/applications/google-chrome.desktop
3131
# In case they've also added Chrome to their desktop
32-
DESKTOP_FILE_2=/home/$USER/Skrivebord/google-chrome.desktop
32+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
33+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
34+
# we run xdg-user-dirs-update, which generates it based on the environment variable
35+
# LANG. This variable is empty in lightdm so we first export it
36+
# based on the value stored in /etc/default/locale
37+
export "$(grep LANG= /etc/default/locale)"
38+
runuser -u user xdg-user-dirs-update
39+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
40+
DESKTOP_FILE_2=/home/$USER/$DESKTOP/google-chrome.desktop
3341
# TODO: Delete DESKTOP_FILE_3 later on as its now a symlink to DESKTOP_FILE_1 - as it should be
3442
# In case they've run chrome_autostart.sh.
3543
# The name is no mistake, that one is not called google-chrome.desktop

os2borgerpc/desktop/desktop_activate_shortcuts.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if get_os2borgerpc_config os2_product | grep --quiet kiosk; then
77
exit 1
88
fi
99

10-
USER=user
10+
USERNAME=user
1111
SHADOW=.skjult
1212
GIO_LAUNCHER=/usr/share/os2borgerpc/bin/gio-fix-desktop-file-permissions.sh
1313
GIO_SCRIPT=/usr/share/os2borgerpc/bin/gio-dbus.sh
@@ -25,7 +25,12 @@ cat << EOF > "$GIO_SCRIPT"
2525
export \$(dbus-launch)
2626
DBUS_PROCESS=\$\$
2727
28-
for FILE in /home/$USER/Skrivebord/*.desktop; do
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
2934
gio set "\$FILE" metadata::trusted true
3035
done
3136
@@ -37,16 +42,25 @@ EOF
3742
cat << EOF > "$GIO_LAUNCHER"
3843
#! /usr/bin/env sh
3944
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)
51+
runuser -u user xdg-user-dirs-update
52+
DESKTOP=\$(runuser -u $USERNAME xdg-user-dir DESKTOP)
53+
4054
# Gio expects the user to own the file so temporarily change that
41-
for FILE in /home/$USER/Skrivebord/*.desktop; do
42-
chown $USER:$USER \$FILE
55+
for FILE in \$DESKTOP/*.desktop; do
56+
chown $USERNAME:$USERNAME \$FILE
4357
done
4458
4559
su --login user --command $GIO_SCRIPT
4660
4761
# Now set the permissions back to their restricted form
48-
for FILE in /home/$USER/Skrivebord/*.desktop; do
49-
chown root:$USER "\$FILE"
62+
for FILE in \$DESKTOP/*.desktop; do
63+
chown root:$USERNAME "\$FILE"
5064
# In order for gio changes to take effect, it is necessary to update the file time stamp
5165
# This can be done with many commands such as chmod or simply touch
5266
# However, in some cases the files might not have execute permission so we add it with chmod
@@ -60,4 +74,6 @@ chmod +x "$GIO_SCRIPT"
6074
# Cleanup if there are previous entries of the gio fix script in the file
6175
sed --in-place "\@$GIO_LAUNCHER@d" $USER_CLEANUP
6276

63-
printf "%s\n" "$GIO_LAUNCHER" >> $USER_CLEANUP
77+
# Make sure to insert this line before the desktop is made immutable
78+
# in case desktop_toggle_writable has already been run
79+
sed -i "/chown -R \$USERNAME:\$USERNAME \/home\/\$USERNAME/a $GIO_LAUNCHER" $USER_CLEANUP

os2borgerpc/desktop/desktop_logout_button_icon.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@ SHORTCUT_NAME="$2"
1818
PROMPT=$3
1919
ICON_UPLOAD="$4"
2020

21-
OLD_DESKTOP_FILE=/home/.skjult/Skrivebord/Logout.desktop
22-
DESKTOP_FILE=/home/.skjult/Skrivebord/logout.desktop
21+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
22+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
23+
# we run xdg-user-dirs-update, which generates it based on the environment variable
24+
# LANG. This variable is empty in lightdm so we first export it
25+
# based on the value stored in /etc/default/locale
26+
export "$(grep LANG= /etc/default/locale)"
27+
runuser -u user xdg-user-dirs-update
28+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
29+
30+
OLD_DESKTOP_FILE=/home/.skjult/"$DESKTOP"/Logout.desktop
31+
DESKTOP_FILE=/home/.skjult/"$DESKTOP"/logout.desktop
2332

2433
rm --force "$OLD_DESKTOP_FILE"
2534

2635
if [ "$ACTIVATE" = 'True' ]; then
2736

28-
mkdir --parents "$(dirname $DESKTOP_FILE)"
37+
mkdir --parents "$(dirname "$DESKTOP_FILE")"
2938

3039
TO_PROMPT_OR_NOT=--no-prompt
3140

@@ -56,7 +65,7 @@ if [ "$ACTIVATE" = 'True' ]; then
5665
fi
5766
fi
5867

59-
cat <<- EOF > $DESKTOP_FILE
68+
cat <<- EOF > "$DESKTOP_FILE"
6069
[Desktop Entry]
6170
Version=1.0
6271
Type=Application

os2borgerpc/desktop/desktop_print_program_list.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@ find_desktop_files_path() {
2424

2525
LOCATION="$(lower "$1")"
2626

27-
SHADOW_DESKTOP=/home/.skjult/Skrivebord
27+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
28+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
29+
# we run xdg-user-dirs-update, which generates it based on the environment variable
30+
# LANG. This variable is empty in lightdm so we first export it
31+
# based on the value stored in /etc/default/locale
32+
export "$(grep LANG= /etc/default/locale)"
33+
runuser -u user xdg-user-dirs-update
34+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
35+
SHADOW_DESKTOP=/home/.skjult/$DESKTOP
2836
SNAP_DESKTOP_FILE_PATH="/var/lib/snapd/desktop/applications"
2937
APT_DESKTOP_FILE_PATH="/usr/share/applications"
3038

3139
if [ "$LOCATION" = "menu" ]; then
3240
# Print only the last line only and format it a bit more nicely
3341
tail -n 1 /etc/dconf/db/os2borgerpc.d/02-launcher-favorites | sed "s/favorite-apps=\[\|'\|\]\ \|.desktop//g" | tr ',' '\n'
3442
exit
35-
elif [ "$LOCATION" = "skrivebord" ]; then
43+
elif [ "$LOCATION" = "skrivebord" ] || [ "$LOCATION" = "$DESKTOP" ]; then
3644
PTH="$SHADOW_DESKTOP/"
3745
else
3846
PTH=$APT_DESKTOP_FILE_PATH/

os2borgerpc/desktop/desktop_program_shortcut.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Adds/Removes programs from the desktop in Ubuntu 20.04
44
# Author: mfm@magenta.dk
55
#
6-
# Note that this script currently assumes danish locale, where the 'Desktop' directory
7-
# is instead named 'Skrivebord'.
6+
# This script has been updated to automatically detect the name of
7+
# the 'Desktop' directory in the chosen locale.
88
#
99
# Arguments:
1010
# 1: Use a boolean to decide whether to add or remove the program shortcut
@@ -21,13 +21,22 @@ if get_os2borgerpc_config os2_product | grep --quiet kiosk; then
2121
exit 1
2222
fi
2323

24-
SHADOW_DESKTOP="/home/.skjult/Skrivebord"
24+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
25+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
26+
# we run xdg-user-dirs-update, which generates it based on the environment variable
27+
# LANG. This variable is empty in lightdm so we first export it
28+
# based on the value stored in /etc/default/locale
29+
export "$(grep LANG= /etc/default/locale)"
30+
runuser -u user xdg-user-dirs-update
31+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
32+
33+
SHADOW_DESKTOP="/home/.skjult/$DESKTOP"
2534
SNAP_DESKTOP_FILE_PATH="/var/lib/snapd/desktop/applications"
2635
APT_DESKTOP_FILE_PATH="/usr/share/applications"
2736

2837
# TODO?: Make it replace all desktop icons which are copies with symlinks?
2938

30-
mkdir --parents $SHADOW_DESKTOP
39+
mkdir --parents "$SHADOW_DESKTOP"
3140

3241
if [ "$ADD" = 'True' ]; then
3342
if [ -f "$SNAP_DESKTOP_FILE_PATH/${PROGRAM}_$PROGRAM.desktop" ]; then
@@ -39,7 +48,7 @@ if [ "$ADD" = 'True' ]; then
3948
# Remove it first as it may be a copy and not symlink (ln --force can't overwrite regular files)
4049
rm --force "$SHADOW_DESKTOP/$PROGRAM.desktop"
4150

42-
ln --symbolic --force "$DESKTOP_FILE" $SHADOW_DESKTOP/
51+
ln --symbolic --force "$DESKTOP_FILE" "$SHADOW_DESKTOP"/
4352
else
4453
if [ -f "$SHADOW_DESKTOP/${PROGRAM}_$PROGRAM.desktop" ]; then
4554
PROGRAM=${PROGRAM}_$PROGRAM

os2borgerpc/desktop/desktop_shortcut_to_directory.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ ADD="$1"
1818
DIRECTORY="$2"
1919
SHORTCUT_NAME="$3"
2020

21-
SHADOW_DESKTOP="/home/.skjult/Skrivebord"
21+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
22+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
23+
# we run xdg-user-dirs-update, which generates it based on the environment variable
24+
# LANG. This variable is empty in lightdm so we first export it
25+
# based on the value stored in /etc/default/locale
26+
export "$(grep LANG= /etc/default/locale)"
27+
runuser -u user xdg-user-dirs-update
28+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
2229

23-
mkdir --parents $SHADOW_DESKTOP
30+
SHADOW_DESKTOP="/home/.skjult/$DESKTOP"
31+
32+
mkdir --parents "$SHADOW_DESKTOP"
2433

2534
if [ "$ADD" = "True" ]; then
2635
# Note: "ln" doesn't care if the destination ($DIRECTORY) exists

os2borgerpc/desktop/desktop_url_shortcut.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ URL=$2
2525
SHORTCUT_NAME="$3"
2626
ICON_UPLOAD="$4"
2727

28+
# Determine the name of the user desktop directory. This is done via xdg-user-dir,
29+
# which checks the /home/user/.config/user-dirs.dirs file. To ensure this file exists,
30+
# we run xdg-user-dirs-update, which generates it based on the environment variable
31+
# LANG. This variable is empty in lightdm so we first export it
32+
# based on the value stored in /etc/default/locale
33+
export "$(grep LANG= /etc/default/locale)"
34+
runuser -u user xdg-user-dirs-update
35+
DESKTOP=$(basename "$(runuser -u user xdg-user-dir DESKTOP)")
36+
2837
SHADOW=".skjult"
29-
DESKTOP_FILE="/home/$SHADOW/Skrivebord/$SHORTCUT_NAME.desktop"
38+
DESKTOP_FILE="/home/$SHADOW/$DESKTOP/$SHORTCUT_NAME.desktop"
3039

3140
if [ "$ACTIVATE" = 'True' ]; then
3241

@@ -53,7 +62,7 @@ if [ "$ACTIVATE" = 'True' ]; then
5362
fi
5463
fi
5564

56-
mkdir --parents /home/$SHADOW/Skrivebord
65+
mkdir --parents /home/$SHADOW/"$DESKTOP"
5766

5867
# Originally used: Type=Link and URL=$URL and no Exec line, but seemingly that doesn't work in 20.04
5968
cat <<- EOF > "$DESKTOP_FILE"

0 commit comments

Comments
 (0)