|
| 1 | +#! /usr/bin/env sh |
| 2 | + |
| 3 | +# Chrome launch maximized, fullscreen or kiosk by default |
| 4 | +# Applies to both the general .desktop file, |
| 5 | +# the .desktop file that may have been added to the desktop |
| 6 | +# and the .desktop file that may be used to autostart chrome. |
| 7 | +# |
| 8 | +# Arguments: |
| 9 | +# 1: |
| 10 | +# 0: Disable all three (default for Chrome) |
| 11 | +# 1: Maximized |
| 12 | +# 2: Full screen |
| 13 | +# 3: Kiosk |
| 14 | +# |
| 15 | +# |
| 16 | +# Takes effect after logout / restart. |
| 17 | +# |
| 18 | + |
| 19 | + |
| 20 | +set -x |
| 21 | + |
| 22 | +SETTING="$1" |
| 23 | + |
| 24 | +USER=".skjult" |
| 25 | +DESKTOP_FILE_PATH=/usr/share/applications/google-chrome.desktop |
| 26 | +# In case they've also added Chrome to their desktop |
| 27 | +DESKTOP_FILE_PATH2=/home/$USER/Skrivebord/google-chrome.desktop |
| 28 | +# In case they've run chrome_autostart.sh |
| 29 | +DESKTOP_FILE_PATH3=/home/$USER/.config/autostart/chrome.desktop |
| 30 | +FILES="$DESKTOP_FILE_PATH $DESKTOP_FILE_PATH2 $DESKTOP_FILE_PATH3" |
| 31 | + |
| 32 | +# Takes a parameter to add to Chrome and a list of .desktop files to add it to |
| 33 | +add_to_desktop_files() { |
| 34 | + PARAMETER="$1" |
| 35 | + shift # Now remove the parameter so we can loop over what remains: The files |
| 36 | + for FILE in "$@"; do |
| 37 | + # Only continue if the particular file exists |
| 38 | + if [ -f "$FILE" ]; then |
| 39 | + # Don't add the parameter multiple times |
| 40 | + if ! grep -q -- "$PARAMETER" "$FILE"; then |
| 41 | + sed -i "s,\(Exec=/usr/bin/google-chrome-stable\)\(.*\),\1 $PARAMETER\2," "$FILE" |
| 42 | + fi |
| 43 | + fi |
| 44 | + done |
| 45 | +} |
| 46 | + |
| 47 | +# Takes a parameter to remove and a list of .desktop files to remove it from |
| 48 | +remove_from_desktop_files() { |
| 49 | + PARAMETER="$1" |
| 50 | + shift # Now remove the parameter so we can loop over what remains: The files |
| 51 | + for FILE in "$@"; do |
| 52 | + # Only continue if the particular file exists |
| 53 | + if [ -f "$FILE" ]; then |
| 54 | + sed -i "s/ $PARAMETER//g" "$FILE" |
| 55 | + fi |
| 56 | + done |
| 57 | +} |
| 58 | + |
| 59 | +case "$SETTING" in |
| 60 | + 0) # Disable all three |
| 61 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 62 | + remove_from_desktop_files "--start-maximized" $FILES |
| 63 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 64 | + remove_from_desktop_files "--start-fullscreen" $FILES |
| 65 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 66 | + remove_from_desktop_files "--kiosk" $FILES |
| 67 | + ;; |
| 68 | + 1) # MAXIMIZE |
| 69 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 70 | + add_to_desktop_files "--start-maximized" $FILES |
| 71 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 72 | + remove_from_desktop_files "--start-fullscreen" $FILES |
| 73 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 74 | + remove_from_desktop_files "--kiosk" $FILES |
| 75 | + ;; |
| 76 | + 2) # FULLSCREEN |
| 77 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 78 | + remove_from_desktop_files "--start-maximized" $FILES |
| 79 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 80 | + add_to_desktop_files "--start-fullscreen" $FILES |
| 81 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 82 | + remove_from_desktop_files "--kiosk" $FILES |
| 83 | + ;; |
| 84 | + 3) # KIOSK |
| 85 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 86 | + remove_from_desktop_files "--start-maximized" $FILES |
| 87 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 88 | + remove_from_desktop_files "--start-fullscreen" $FILES |
| 89 | + # shellcheck disable=SC2086 # We want to split the files back into separate arguments |
| 90 | + add_to_desktop_files "--kiosk" $FILES |
| 91 | + ;; |
| 92 | + *) |
| 93 | + printf "%s |
| 94 | + " "Ugyldigt parameter: Det skal være enten 0 (alle slået fra), 1 (maksimeret), 2 (fuld skærm) eller 3 (kiosk)." |
| 95 | + exit 1 |
| 96 | + ;; |
| 97 | +esac |
0 commit comments