2023-01-09 21:06:46 -08:00
|
|
|
{{- if (eq .host.distro.family "linux") -}}
|
2023-01-09 12:47:23 -08:00
|
|
|
#!/usr/bin/env bash
|
2023-04-11 20:26:25 -07:00
|
|
|
# @file GNOME Extension Settings
|
|
|
|
# @brief Applies GNOME extension settings from various data sources.
|
|
|
|
# @description
|
|
|
|
# This script ensures your GNOME extensions come pre-configured to your liking. It provides the ability
|
|
|
|
# to automatically install a configurable list of GNOME extensions as well as apply your preferred settings.
|
2023-01-09 12:47:23 -08:00
|
|
|
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
|
|
|
|
# extension config hash: {{ include (joinPath .host.home ".config" "desktop" "gnome.yml") | sha256sum }}
|
|
|
|
|
|
|
|
### Ensure /tmp/install-gnome-extensions.txt is not present on the system
|
|
|
|
if [ -f /tmp/install-gnome-extensions.txt ]; then
|
|
|
|
rm -f /tmp/install-gnome-extensions.txt
|
|
|
|
fi
|
|
|
|
|
2023-01-12 06:33:12 -08:00
|
|
|
### Register temporary file for gnome.yml JSON
|
2023-08-07 22:29:21 -07:00
|
|
|
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/desktop/gnome.yml" ]; then
|
2023-01-12 06:33:12 -08:00
|
|
|
TMP_YQ="$(mktemp)"
|
2023-08-07 22:29:21 -07:00
|
|
|
cat "${XDG_CONFIG_HOME:-$HOME/.config}/desktop/gnome.yml" | yq e -o=j '.' > "$TMP_YQ"
|
2023-01-12 06:33:12 -08:00
|
|
|
fi
|
|
|
|
|
2023-01-09 12:47:23 -08:00
|
|
|
### Populate /tmp/install-gnome-extensions.txt with GNOME extensions that need to be installed
|
2023-08-07 22:29:21 -07:00
|
|
|
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/desktop/gnome.yml" ]; then
|
2023-01-12 06:33:12 -08:00
|
|
|
cat "$TMP_YQ" | jq -c '.default_gnome_extensions[] | tojson' | while read EXT; do
|
|
|
|
TMP="$(mktemp)"
|
|
|
|
echo "$EXT" | sed 's/^.\(.*\).$/\1/' > "$TMP"
|
|
|
|
EXT_URL="$(cat "$TMP" | jq -r '.url')"
|
|
|
|
EXT_ID="$(cat "$TMP" | jq -r '.regex')"
|
2023-01-09 12:47:23 -08:00
|
|
|
echo "$EXT_URL" >> /tmp/install-gnome-extensions.txt
|
2023-01-24 00:05:20 -08:00
|
|
|
if [ ! -d "${XDG_DATA_HOME:-$HOME/.local/share}/gnome-shell/extensions" ]; then
|
|
|
|
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/gnome-shell/extensions"
|
|
|
|
fi
|
2023-01-12 06:33:12 -08:00
|
|
|
find "${XDG_DATA_HOME:-$HOME/.local/share}/gnome-shell/extensions" -mindepth 1 -maxdepth 1 -type d | while read EXT_FOLDER; do
|
|
|
|
if [[ "$EXT_FOLDER" == *"$EXT_ID"* ]] && [ -f /tmp/install-gnome-extensions.txt ]; then
|
|
|
|
TMP_EXT="$(mktemp)"
|
2023-01-09 12:47:23 -08:00
|
|
|
head -n -1 /tmp/install-gnome-extensions.txt > "$TMP_EXT"
|
2023-01-12 06:33:12 -08:00
|
|
|
mv -f "$TMP_EXT" /tmp/install-gnome-extensions.txt > /dev/null
|
2023-01-09 12:47:23 -08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
else
|
2023-11-04 18:46:18 -07:00
|
|
|
logg warn 'The ~/.config/desktop/gnome.yml file is missing so GNOME extension install orders cannot be calculated'
|
2023-01-09 12:47:23 -08:00
|
|
|
fi
|
|
|
|
|
2023-01-12 06:33:12 -08:00
|
|
|
### Remove /tmp/install-gnome-extensions.txt if it is empty
|
|
|
|
if [ "$(cat /tmp/install-gnome-extensions.txt)" == "" ]; then
|
|
|
|
rm -f /tmp/install-gnome-extensions.txt > /dev/null
|
|
|
|
fi
|
|
|
|
|
2023-01-09 12:47:23 -08:00
|
|
|
### Install the GNOME extensions using the `install-gnome-extensions` script
|
|
|
|
if command -v install-gnome-extensions > /dev/null; then
|
|
|
|
if [ -f /tmp/install-gnome-extensions.txt ]; then
|
2023-11-04 18:46:18 -07:00
|
|
|
logg info 'Running the install-gnome-extensions script'
|
2023-01-24 00:05:20 -08:00
|
|
|
cd /tmp
|
2023-01-09 12:47:23 -08:00
|
|
|
install-gnome-extensions --enable --overwrite --file /tmp/install-gnome-extensions.txt
|
|
|
|
rm -f /tmp/install-gnome-extensions.txt
|
|
|
|
logg success 'Finished installing the GNOME extensions'
|
|
|
|
else
|
|
|
|
logg info 'No new GNOME extensions to install'
|
|
|
|
fi
|
|
|
|
else
|
2023-11-04 18:46:18 -07:00
|
|
|
logg warn 'Cannot install GNOME extensions because the install-gnome-extensions script is missing from ~/.local/bin'
|
2023-01-09 12:47:23 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
### Apply plugin gsettings
|
2023-08-07 22:29:21 -07:00
|
|
|
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/desktop/gnome.yml" ]; then
|
2023-01-12 06:33:12 -08:00
|
|
|
cat "$TMP_YQ" | jq -c '.default_gnome_extensions[] | tojson' | while read EXT; do
|
2023-01-10 02:07:53 -08:00
|
|
|
if [ "$DEBUG_MODE" == 'true' ]; then
|
|
|
|
logg info 'Extension data:'
|
|
|
|
echo "$EXT"
|
|
|
|
fi
|
2023-01-12 06:33:12 -08:00
|
|
|
TMP="$(mktemp)"
|
|
|
|
echo "$EXT" | sed 's/^.\(.*\).$/\1/' > "$TMP"
|
|
|
|
EXT_URL="$(cat "$TMP" | jq -r '.url')"
|
|
|
|
EXT_ID="$(cat "$TMP" | jq -r '.regex')"
|
2023-01-10 02:07:53 -08:00
|
|
|
if [ "$DEBUG_MODE" == 'true' ]; then
|
|
|
|
logg info 'Extension ID:'
|
|
|
|
echo "$EXT_ID"
|
|
|
|
fi
|
2023-01-12 06:33:12 -08:00
|
|
|
EXT_SETTINGS_TYPE="$(cat "$TMP" | jq -r '.settings | type')"
|
|
|
|
EXT_SETTINGS="$(cat "$TMP" | jq -r '.settings')"
|
2023-01-09 12:47:23 -08:00
|
|
|
if [ "$EXT_SETTINGS" != 'null' ]; then
|
2023-11-04 18:46:18 -07:00
|
|
|
logg info 'Evaluating extension settings for '"$EXT_ID"''
|
2023-01-09 20:59:51 -08:00
|
|
|
if [ "$EXT_SETTINGS_TYPE" == 'array' ]; then
|
2023-01-12 06:33:12 -08:00
|
|
|
cat "$TMP" | jq -r '.settings[]' | while read EXT_SETTING; do
|
2023-01-09 21:02:31 -08:00
|
|
|
logg info 'Applying following extension setting:'
|
2023-01-09 20:59:51 -08:00
|
|
|
echo "$EXT_SETTING"
|
|
|
|
eval "$EXT_SETTING"
|
|
|
|
done
|
|
|
|
else
|
2023-01-09 21:02:31 -08:00
|
|
|
logg info 'Applying following extension setting:'
|
2023-01-09 20:59:51 -08:00
|
|
|
echo "$EXT_SETTINGS"
|
|
|
|
eval "$EXT_SETTINGS"
|
|
|
|
fi
|
2023-11-04 18:46:18 -07:00
|
|
|
logg success 'Applied gsettings configuration for the '"$EXT_ID"' GNOME extension'
|
2023-01-09 12:47:23 -08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
{{- end }}
|