|
| 1 | +#! /usr/bin/env sh |
| 2 | + |
| 3 | + |
| 4 | +# |
| 5 | +# Arguments: |
| 6 | +# 1: Whether to add or delete the shortcut from the desktop. |
| 7 | +# 'nej' or 'falsk' removes it. |
| 8 | +# 2: The name the button should have on the desktop. |
| 9 | +# If you choose deletion, the contents of the name argument does not matter. |
| 10 | +# 3: Whether to prompt for restart or not |
| 11 | +# 4: The icon to use for the button. Ideally SVG, but PNG works as well. |
| 12 | +# If you choose deletion, which file you add here doesn't matter. |
| 13 | + |
| 14 | +set -x |
| 15 | + |
| 16 | +lower() { |
| 17 | + echo "$@" | tr '[:upper:]' '[:lower:]' |
| 18 | +} |
| 19 | + |
| 20 | +NAME=$1 |
| 21 | +PROMPT="$(lower "$2")" |
| 22 | +ICON_UPLOAD=$3 |
| 23 | + |
| 24 | +FILE_PATH=/home/.skjult/Skrivebord/Logout.desktop |
| 25 | + |
| 26 | +TO_PROMPT_OR_NOT=--no-prompt |
| 27 | + |
| 28 | +if [ "$PROMPT" != 'false' ] && [ "$PROMPT" != 'falsk' ] && \ |
| 29 | + [ "$PROMPT" != 'no' ] && [ "$PROMPT" != 'nej' ]; then |
| 30 | + # If they DO want the prompt |
| 31 | + unset TO_PROMPT_OR_NOT |
| 32 | +fi |
| 33 | + |
| 34 | +# HANDLE ICON HERE |
| 35 | +if ! echo "$ICON_UPLOAD" | grep --quiet '.png\|.svg'; then |
| 36 | + printf "Fejl: Kun .svg og .png understøttes som ikon-formater." |
| 37 | + exit 1 |
| 38 | +else |
| 39 | + ICON_BASE_PATH=/usr/local/share/icons/ |
| 40 | + mkdir --parents "$ICON_BASE_PATH" |
| 41 | + # Copy icon from the default destination to where it should actually be |
| 42 | + cp "$ICON_UPLOAD" $ICON_BASE_PATH |
| 43 | + # A .desktop file apparently expects an icon without an extension |
| 44 | + ICON_NAME="$(basename "$ICON_UPLOAD" | sed -e 's/.png|.svg//')" |
| 45 | + |
| 46 | + update-icon-caches $ICON_BASE_PATH |
| 47 | +fi |
| 48 | + |
| 49 | +cat << EOF > $FILE_PATH |
| 50 | + [Desktop Entry] |
| 51 | + Version=1.0 |
| 52 | + Type=Application |
| 53 | + Name=$NAME |
| 54 | + Comment=Logud |
| 55 | + Icon=$ICON_BASE_PATH$ICON_NAME |
| 56 | + Exec=gnome-session-quit --logout $TO_PROMPT_OR_NOT |
| 57 | +EOF |
0 commit comments