Последняя активность 1 week ago

anduin's Avatar anduin ревизий этого фрагмента 1 week ago. К ревизии

1 file changed, 104 insertions

switch_wallpaper.sh(файл создан)

@@ -0,0 +1,104 @@
1 + #!/bin/bash
2 + set -e
3 +
4 + # Help function
5 + usage() {
6 + echo "Usage: sudo $0 <path-to-image>"
7 + echo "Changes the GDM background to the specified image."
8 + echo "Note: This script must be run as root."
9 + exit 1
10 + }
11 +
12 + # Check for root
13 + if [ "$EUID" -ne 0 ]; then
14 + echo "Error: This script must be run as root."
15 + exit 1
16 + fi
17 +
18 + # Check arguments
19 + TARGET_IMAGE="$1"
20 + if [ -z "$TARGET_IMAGE" ]; then
21 + usage
22 + fi
23 +
24 + if [ ! -f "$TARGET_IMAGE" ]; then
25 + echo "Error: Image file '$TARGET_IMAGE' not found."
26 + exit 1
27 + fi
28 +
29 + # Check dependencies
30 + if ! command -v glib-compile-resources &> /dev/null; then
31 + echo "Error: 'glib-compile-resources' is not installed."
32 + echo "Please install 'libglib2.0-dev-bin' (Ubuntu/Debian) or 'glib2-devel' (Fedora)."
33 + exit 1
34 + fi
35 +
36 + # Define Paths
37 + REPO_DIR="$(dirname "$(readlink -m "${0}")")"
38 + THEME_ASSETS_DIR="${REPO_DIR}/other/gdm/theme"
39 + XML_FILE="${REPO_DIR}/other/gdm/gnome-shell-theme.gresource.xml"
40 + WORK_DIR="/tmp/gdm-switch-wallpaper-work"
41 +
42 + # Targeted GDM theme files (Priority order based on lib-core.sh)
43 + POP_OS_GR_FILE="/usr/share/gnome-shell/theme/Pop/gnome-shell-theme.gresource"
44 + YARU_GR_FILE="/usr/share/gnome-shell/theme/Yaru/gnome-shell-theme.gresource"
45 + ZORIN_GR_DARK_FILE="/usr/share/gnome-shell/theme/ZorinBlue-Dark/gnome-shell-theme.gresource"
46 + ZORIN_GR_LIGHT_FILE="/usr/share/gnome-shell/theme/ZorinBlue-Light/gnome-shell-theme.gresource"
47 + MISC_GR_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource"
48 +
49 + # Find which theme file is in use
50 + TARGET_FILE=""
51 + if [ -f "$POP_OS_GR_FILE" ]; then
52 + TARGET_FILE="$POP_OS_GR_FILE"
53 + elif [ -f "$YARU_GR_FILE" ]; then
54 + TARGET_FILE="$YARU_GR_FILE"
55 + elif [ -f "$ZORIN_GR_DARK_FILE" ]; then
56 + TARGET_FILE="$ZORIN_GR_DARK_FILE"
57 + elif [ -f "$ZORIN_GR_LIGHT_FILE" ]; then
58 + TARGET_FILE="$ZORIN_GR_LIGHT_FILE"
59 + elif [ -f "$MISC_GR_FILE" ]; then
60 + TARGET_FILE="$MISC_GR_FILE"
61 + else
62 + echo "Error: Could not find any supported GDM theme .gresource file."
63 + exit 1
64 + fi
65 +
66 + echo "Target GDM theme file: $TARGET_FILE"
67 +
68 + # Prepare Workspace
69 + echo "Preparing temporary workspace at $WORK_DIR..."
70 + rm -rf "$WORK_DIR"
71 + mkdir -p "$WORK_DIR"
72 +
73 + # Copy base theme assets
74 + if [ ! -d "$THEME_ASSETS_DIR" ]; then
75 + echo "Error: Theme assets not found at $THEME_ASSETS_DIR"
76 + exit 1
77 + fi
78 + cp -r "$THEME_ASSETS_DIR"/* "$WORK_DIR/"
79 +
80 + # Copy and rename the new background image
81 + echo "Processing background image..."
82 + cp "$TARGET_IMAGE" "$WORK_DIR/background.png"
83 +
84 + # Backup existing theme file
85 + if [ ! -f "${TARGET_FILE}.bak" ]; then
86 + echo "Backing up original theme to ${TARGET_FILE}.bak..."
87 + cp "$TARGET_FILE" "${TARGET_FILE}.bak"
88 + else
89 + echo "Backup already exists at ${TARGET_FILE}.bak, skipping backup."
90 + fi
91 +
92 + # Compile Resources
93 + echo "Compiling GDM resources..."
94 + glib-compile-resources \
95 + --sourcedir="$WORK_DIR" \
96 + --target="$TARGET_FILE" \
97 + "$XML_FILE"
98 +
99 + # Cleanup
100 + rm -rf "$WORK_DIR"
101 +
102 + echo "Success! GDM background has been updated."
103 + echo "You may need to restart GDM or reboot to see the changes."
104 + echo " - To restart GDM: sudo systemctl restart gdm"
Новее Позже