1 #!/bin/bash
 2 
 3 ###################################################################
 4 # GDM Log-in Screen Background Image Replacer Script
 5 ###################################################################
 6 # Extract the system's current GNOME Shell Theme and replace
 7 # that hideously awful default static noise login background image
 8 # with a nicer image of your choosing.
 9 #
10 # Every GDM update will restore the default background image.
11 # To automatically replace it with your preferred image,
12 # you can create a hook for your package manager that runs
13 # this script each time GDM is updated.
14 ###################################################################
15 # made with <3 by ~inthreedee ( https://tilde.town/~inthreedee/ )
16 ###################################################################
17 
18 gst="/usr/share/gnome-shell/gnome-shell-theme.gresource"
19 workdir="/tmp/shell-theme"
20 xml="$workdir/theme/gnome-shell-theme.gresource.xml"
21 newimagedir="$HOME/Pictures"
22 newimage="binary-arch-dual.png"
23 
24 
25 # Perform some checks
26 if [ "$(id -u)" -eq 0 ]; then
27        echo "Do not run this script as root; it will ask when needed"
28 elif [ ! -f "$newimagedir/$newimage" ]; then
29     echo "Image file not found: $newimagedir/$newimage"
30 elif [ ! -f "$gst" ]; then
31     echo "File not found: $gst"
32 elif [ ! -d "/tmp" ]; then
33     echo "Directory not found: /tmp"
34 else
35 
36     # Continue
37     echo "Using the following image for the login background:"
38     echo "$newimagedir/$newimage"
39 
40 
41     # Extract the theme
42     echo "Extracting the current theme..."
43     for r in `gresource list $gst`; do
44         r="${r#\/org\/gnome\/shell/}"
45         if [ ! -d "$workdir/${r%/*}" ]; then
46             mkdir -p "$workdir/${r%/*}"
47         fi
48     done
49 
50     for r in `gresource list $gst`; do
51         gresource extract "$gst" "$r" > "$workdir/${r#\/org\/gnome\/shell/}"
52     done
53 
54 
55     # Copy in the new image
56     echo "Copying replacement image..."
57     cp "$newimagedir/$newimage" "$workdir/theme/"
58 
59 
60     # Create the required xml file
61     echo "Creating xml file..."
62     echo '<?xml version="1.0" encoding="UTF-8"?>
63 <gresources>
64   <gresource prefix="/org/gnome/shell/theme">' > "$xml"
65 
66     find "$workdir/theme" -type f | sed "s|^$workdir/theme/||" | sort | sed 's|^|    <file>|' | sed 's|$|</file>|' >> "$xml"
67 
68     echo "  </gresource>
69 </gresources>" >> "$xml"
70 
71 
72     # Add the replacement image to #lockDialogGroup in gnome-shell.css
73     echo "Modifying css file..."
74     perl -i -p0e "s|#lockDialogGroup {.*?}|#lockDialogGroup {\n  background: #41494c url(resource:///org/gnome/shell/theme/$newimage);\n  background-size: 3840px 1080px;\n  background-repeat: no-repeat; }|s" "$workdir/theme/gnome-shell.css"
75 
76 
77     # Compile the theme and copy it into place
78     echo "Recompiling theme..."
79     cd "$workdir/theme"
80     glib-compile-resources gnome-shell-theme.gresource.xml
81     echo "Copying theme file into place..."
82     sudo cp "$workdir/theme/gnome-shell-theme.gresource" /usr/share/gnome-shell/
83 
84     # Clean up
85     echo "Cleaning up..."
86     rm -r "$workdir"
87     echo "Done.  Log out and restart GDM to complete."
88 fi