Skip to content

Instantly share code, notes, and snippets.

@Tazeg
Last active September 9, 2021 11:45
Show Gist options
  • Save Tazeg/aad2bc12616fab6795816bcc70eb459e to your computer and use it in GitHub Desktop.
Save Tazeg/aad2bc12616fab6795816bcc70eb459e to your computer and use it in GitHub Desktop.
Bash script to change the Gnome 3 GDM background
#!/bin/sh -e
#------------------------------------------------------------------------------------
# Change the GDM background.
# based on https://wiki.archlinux.org/index.php/GDM
# by https://twitter.com/jeffprod
#
# If you have dual screens, you should copy your current settings to gdm
# so that the image is not reversed right-left :
# sudo cp ~/.config/monitors.xml ~gdm/.config
#
# If you have dual screen, the image should be for example : 3840x1080
#
# USAGE
# chmod +x gdmbackground.sh
# ./gdmbackground.sh <path-to-image-filename>
#
# EXEMPLE
# ./gdmbackground.sh ~/wallpaper.jpg
#------------------------------------------------------------------------------------
if [ -z "$1" ]; then
echo "USAGE:"
echo "./gdmbackground.sh <path-to-image-filename>"
exit 0
fi
extractDir="$(pwd)/extract"
echo "Extracting /usr/share/gnome-shell/gnome-shell-theme.gresource to ${extractDir}"
gst=/usr/share/gnome-shell/gnome-shell-theme.gresource
for r in `gresource list $gst`; do
r=${r#\/org\/gnome\/shell/}
if [ ! -d $extractDir/${r%/*} ]; then
mkdir -p $extractDir/${r%/*}
fi
done
for r in `gresource list $gst`; do
gresource extract $gst $r >$extractDir/${r#\/org\/gnome\/shell/}
done
echo "Copy $1 ${extractDir}/theme"
cp "$1" "${extractDir}/theme"
filename=$(basename $1)
cat > "${extractDir}/theme/gnome-shell-theme.gresource.xml" << EOL
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/shell/theme">
<file>calendar-today.svg</file>
<file>checkbox-focused.svg</file>
<file>checkbox-off-focused.svg</file>
<file>checkbox-off.svg</file>
<file>checkbox.svg</file>
<file>dash-placeholder.svg</file>
<file>gnome-shell.css</file>
<file>gnome-shell-high-contrast.css</file>
<file>icons/message-indicator-symbolic.svg</file>
<file>icons/pointer-double-click-symbolic.svg</file>
<file>icons/pointer-drag-symbolic.svg</file>
<file>icons/pointer-primary-click-symbolic.svg</file>
<file>icons/pointer-secondary-click-symbolic.svg</file>
<file>key-enter.svg</file>
<file>key-hide.svg</file>
<file>key-layout.svg</file>
<file>key-shift-latched-uppercase.svg</file>
<file>key-shift.svg</file>
<file>key-shift-uppercase.svg</file>
<file>no-events.svg</file>
<file>noise-texture.png</file>
<file>${filename}</file>
<file>no-notifications.svg</file>
<file>pad-osd.css</file>
<file>process-working.svg</file>
<file>toggle-off-dark.svg</file>
<file>toggle-off-hc.svg</file>
<file>toggle-off.svg</file>
<file>toggle-on-dark.svg</file>
<file>toggle-on-hc.svg</file>
<file>toggle-on.svg</file>
</gresource>
</gresources>
EOL
echo "Modifying ${extractDir}/theme/gnome-shell.css"
sed -i -e "/#lockDialogGroup *{/,/}/c#lockDialogGroup { background: url($filename); background-repeat: no-repeat; }" "${extractDir}/theme/gnome-shell.css"
echo "Compiling"
cd "${extractDir}/theme"
glib-compile-resources gnome-shell-theme.gresource.xml
echo "Copy gnome-shell-theme.gresource to /usr/share/gnome-shell"
sudo cp gnome-shell-theme.gresource /usr/share/gnome-shell
echo "Clean up"
/bin/rm -rf ${extractDir}
echo "You may now reboot, or restart GDM (this will log you out!) :"
echo "sudo systemctl restart gdm.service"
@terencode
Copy link

Hey, just some thoughts :

echo "You may now reboot, or restart GDM (this will log you out!) :"
echo "sudo systemctl restart gdm.service"

It'd be better if it would ask if you want to restart gdm now and not force you to do it.

echo "Clean up"
/bin/rm -rf ${extractDir}

Why /bin/rm and not just rm?

currentDir="$(pwd)"

I don't see why you would assign this as a new variable.

@Tazeg
Copy link
Author

Tazeg commented Nov 15, 2019

Thanks for you feedback.
I don't force to restart gdm, the command is printed with echo.
I use /bin/rm because i made an alias on my system : alias rm=trash in the bashrc so that files go to the trash instead of beeing removed definitly.
You are right, currentDir was useless, i removed it.

@terencode
Copy link

Oups yeah for some reason my brain skipped the "echo" thanks.
Ah interesting concept for rm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment