|
| 1 | +#! /usr/bin/env sh |
| 2 | + |
| 3 | +# Adds/Removes programs from the desktop in Ubuntu 20.04 |
| 4 | +# Author: mfm@magenta.dk |
| 5 | +# |
| 6 | +# This script has been updated to automatically detect the name of |
| 7 | +# the 'Desktop' directory in the chosen locale. |
| 8 | +# |
| 9 | +# Arguments: |
| 10 | +# 1: Use a boolean to decide whether to add or remove the program shortcut |
| 11 | +# 2: This argument should specify the name of a program (.desktop-file) |
| 12 | +# under /usr/share/applications/ or /var/lib/snapd/desktop/applications/ |
| 13 | +# This parameter IS case-sensitive as some applications have |
| 14 | +# capitalized characters in their filename. |
| 15 | + |
| 16 | +ADD="$1" |
| 17 | +PROGRAM="$2" |
| 18 | + |
| 19 | +if get_os2borgerpc_config os2_product | grep --quiet kiosk; then |
| 20 | + echo "Dette script er ikke designet til at blive anvendt på en kiosk-maskine." |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 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 | tr -d '"')" |
| 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" |
| 34 | +SNAP_DESKTOP_FILE_PATH="/var/lib/snapd/desktop/applications" |
| 35 | +APT_DESKTOP_FILE_PATH="/usr/share/applications" |
| 36 | + |
| 37 | +# TODO?: Make it replace all desktop icons which are copies with symlinks? |
| 38 | + |
| 39 | +mkdir --parents "$SHADOW_DESKTOP" |
| 40 | + |
| 41 | +# They can type in chrome, but the desktop file is called google-chrome |
| 42 | +# They can type in edge, but the desktop file is called microsoft-edge |
| 43 | +# They can also type in okular, but the desktop file is called okularApplication_kimgio |
| 44 | +if [ "$PROGRAM" = "chrome" ]; then |
| 45 | + PROGRAM="google-chrome" |
| 46 | +elif [ "$PROGRAM" = "edge" ]; then |
| 47 | + PROGRAM="microsoft-edge" |
| 48 | +elif [ "$PROGRAM" = "okular" ]; then |
| 49 | + PROGRAM="okularApplication_kimgio" |
| 50 | +fi |
| 51 | + |
| 52 | +if [ "$ADD" = 'True' ]; then |
| 53 | + if [ -f "$SNAP_DESKTOP_FILE_PATH/${PROGRAM}_$PROGRAM.desktop" ]; then |
| 54 | + ORIGINAL_FILE=$SNAP_DESKTOP_FILE_PATH/${PROGRAM}_$PROGRAM.desktop |
| 55 | + else |
| 56 | + ORIGINAL_FILE=$APT_DESKTOP_FILE_PATH/$PROGRAM.desktop |
| 57 | + fi |
| 58 | + # Check that the program actually exists and exit if it doesn't |
| 59 | + if [ ! -f "$ORIGINAL_FILE" ]; then |
| 60 | + echo "The chosen program name did not match any installed programs. Exiting." |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + # Remove it first as it may be a copy and not symlink (ln --force can't overwrite regular files) |
| 64 | + rm --force "$SHADOW_DESKTOP/$(basename "$ORIGINAL_FILE")" |
| 65 | + |
| 66 | + # Ensure that the local copy exists |
| 67 | + LOCAL_FILE_COPY="/home/.skjult/.local/share/applications/$(basename "$ORIGINAL_FILE")" |
| 68 | + mkdir --parents "$(dirname "$LOCAL_FILE_COPY")" |
| 69 | + if [ ! -f "$LOCAL_FILE_COPY" ]; then |
| 70 | + cp "$ORIGINAL_FILE" "$LOCAL_FILE_COPY" |
| 71 | + fi |
| 72 | + |
| 73 | + ln --symbolic --force "$LOCAL_FILE_COPY" "$SHADOW_DESKTOP"/ |
| 74 | +else |
| 75 | + if [ -f "$SHADOW_DESKTOP/${PROGRAM}_$PROGRAM.desktop" ]; then |
| 76 | + PROGRAM=${PROGRAM}_$PROGRAM |
| 77 | + fi |
| 78 | + rm --force "$SHADOW_DESKTOP/$PROGRAM.desktop" |
| 79 | +fi |
0 commit comments