There will always be a workaround when working with Linux. Things just don’t stay static and the idea of a walled garden for users isn’t much of an impediment to adaptation. As a Pop!_OS user, I’ve come to know the brown of the GDM login screen as a de-facto part of the OS. It’s okay and not awful, but it isn’t the most appealing color and doesn’t allow for choice.
Imagine my happiness to find a script out on github which promised to reset the GDM theme (image, color or gradient) on Github thanks to the team at UbuntuHandbook who delivered the news about this fine script from Pratak Kumar. Of course, the author went to pains to point out that the script only supported Ubuntu, and the script tested for that condition.
Unlike a lot of folks, I prefer to verify that scripts have only the intended outcome and use my Crash Test VM for all such scripting as I work my way through any modification when I find something interesting that can provide some joy. I never recommend running scripts without a sheep dip or crash test machine. Same holds for anything modifying kernels or untrusted sources.
However, a script can be torn down and reviewed, simply because you can read the source and alter as needed. If you aren’t aware of what a script does, don’t use it. Seriously.
Below is my modified script to set the GDM Background for Pop!_OS 22.04 Jammy Jellyfish. I modified the script and tested it out and it works well for me.
What not to expect: This will not change the background on the drive encryption screen. I wouldn’t even begin to want that to happen.
What to expect: This will allow you to change the default GDM login screen to something of your choosing. If using a background image, I suggest a hard-coded path to a locally stored image to ensure that nothing goes wrong. Relative paths or remote images do not work and may cause a broken login screen.
The script must be run with sudo privileges (you don’t run anything as root, right?) and you should read through it thoroughly to understand the options and recovery procedure. The main difference here is that you are calling the script pop-gdm-set-background NOT ubuntu-gdm-set-background and I have only written this for Pop!_OS 22.04, but you can expand it to include other releases if you wish.
So, without further ado, I give you pop-gdm-set-background:
#!/bin/bash
#Based off the work of Pratak Kumar for Ubuntu, but adapted specifically for Pop!_OS 22.04 Jammy
# Colors
Red='\e[0;31m';
BRed='\e[1;31m';
BIRed='\e[1;91m';
Gre='\e[0;32m';
BGre='\e[1;32m';
BBlu='\e[1;34m';
BWhi='\e[1;37m';
RCol='\e[0m';
codename=$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2)
osname=$(cat /etc/os-release | grep '="Pop!_OS"' | cut -d = -f 2)
if [ "$codename" == "jammy" ] && [ "$osname" == '"Pop!_OS"' ]; then
source="/usr/share/gnome-shell/theme/Pop/gnome-shell-theme.gresource"
GDM_RESOURCE_CONFIG_NAME="gdm"
else
echo -e "${Red}
------------------------------------------------------------------
Sorry, Script is only for Pop!_OS ${BWhi}22.04${Red} Only
Exiting...
------------------------------------------------------------------
${RCol}"
exit 1
fi
pkg=$(dpkg -l | grep libglib2.0-dev-bin >/dev/null && echo "yes" || echo "no")
if [ "$pkg" == "no" ]; then
echo -e "${Red}
-----------------------------------------------------------------------------------------------------
Sorry, the package ${BWhi}'libglib2.0-dev-bin'${Red} is not installed.
Run ${BGre}sudo apt-get install libglib2.0-dev-bin${Red} to install.
For now, Exiting...
-----------------------------------------------------------------------------------------------------${RCol}"
exit 1
fi
dest="/usr/local/share/gnome-shell/custom-gdm"
color='#456789'
###################################################
HELP() {
echo -e "
${BGre}pop-gdm-set-background${BGre} script (for changing Pop!_OS ${BWhi}22.04${RCol} GDM Background) HELP
there are four options
1. background with image
2. background with color
3. background with gradient horizontal ( requires two valid hex color inputs)
4. background with gradient vertical ( requires two valid hex color inputs)
${BWhi}Tip:${RCol} be ready with valid hex color code in place of below example like #aAbBcC or #dDeEfF. Change them to your preffered hex color codes.
you may choose colors from ${BBlu}https://www.color-hex.com/${RCol}
Example Commands:
1. ${BWhi}sudo ./pop-gdm-set-background --image ${BGre}/home/user/backgrounds/image.jpg${RCol}
2. ${BWhi}sudo ./pop-gdm-set-background --color \#aAbBcC${RCol}
3. ${BWhi}sudo ./pop-gdm-set-background --gradient horizontal \#aAbBcC \#dDeEfF${RCol}
4. ${BWhi}sudo ./pop-gdm-set-background --gradient vertical \#aAbBcC \#dDeEfF${RCol}
5. ${BWhi}sudo ./pop-gdm-set-background --reset${RCol}
6. ./pop-gdm-set-background --help
RESCUE_MODE, Example Commands:
1. ${BWhi}$ sudo ./pop-gdm-set-background --image ${BGre}/home/user/backgrounds/image.jpg ${BWhi}rescue${RCol}
2. ${BWhi}$ sudo ./pop-gdm-set-background --color \#aAbBcC rescue ${RCol}
3. ${BWhi}$ sudo ./pop-gdm-set-background --gradient horizontal \#aAbBcC \#dDeEfF rescue${RCol}
4. ${BWhi}$ sudo ./pop-gdm-set-background --gradient vertical \#aAbBcC \#dDeEfF rescue${RCol}
${BWhi}Why RESCUE_MODE?${RCol}
It is when you try to change the background with some other scripts and then interacted with this script,
there will be some conflicts. In case you ran other scripts to change the background and then tried this script,
found conflicts? then add 'rescue' to the end of the command as mentiond above.
${BRed}Please note that for 'RESCUE_MODE' active internet connection is necessary ${RCol}
"
}
###################################################
###################################################
ROUTINE_CHECK() {
if [ "$UID" != "0" ]; then
echo -e "${BRed}This script must be run with sudo${RCol}"
exit 1
fi
cd /tmp
if [ -d /tmp/theme/ ]; then
rm -r /tmp/theme
fi
if ! [ -d $dest ]; then
install -d $dest
fi
}
###################################################
###################################################
RESCUE_MODE() {
echo -e "
>>>>> Trying to ${BWhi}reinstall${RCol} the package yaru-theme-gnome-shell,
if the reinstallation of the package is succesful, background change will be done
otherwise No changes will be made <<<<<<<<<
"
apt install --reinstall yaru-theme-gnome-shell
if [ $? != 0 ]; then
echo -e "${BIRed}
SCRIPT COULD NOT FINISH THE JOB, FAILURE, NO CHANGES WERE DONE.${RCol}"
exit 1
fi
}
###################################################
###################################################
EXTRACT() {
for r in $(gresource list $source); do
t="${r/#\/org\/gnome\/shell\//}"
mkdir -p $(dirname $t)
gresource extract $source $r >$t
done
}
###################################################
###################################################
CREATE_XML() {
extractedFiles=$(find "theme" -type f -printf "%P\n" | xargs -i echo " <file>{}</file>")
cat <<EOF >"theme/custom-gdm-background.gresource.xml"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/shell/theme">
$extractedFiles
</gresource>
</gresources>
EOF
}
###################################################
###################################################
SET_GRESOURCE() {
cd $dest
update-alternatives --quiet --install /usr/share/gnome-shell/$GDM_RESOURCE_CONFIG_NAME-theme.gresource $GDM_RESOURCE_CONFIG_NAME-theme.gresource $dest/custom-gdm-background.gresource 0
update-alternatives --quiet --set $GDM_RESOURCE_CONFIG_NAME-theme.gresource $dest/custom-gdm-background.gresource
check=$(update-alternatives --query $GDM_RESOURCE_CONFIG_NAME-theme.gresource | grep Value | grep $dest/custom-gdm-background.gresource >/dev/null && echo "pass" || echo "fail")
if [ "$check" == "pass" ]; then
echo -e "
😕 ${BGre}Seems 'background change is successful'${RCol}
Changes will be effective after a Reboot (${BWhi}CTRL+ALT+F1${RCol} may show the changes immediately)
If something went wrong, log on to tty and run the below command
${BWhi}$ sudo update-alternatives --quiet --set $GDM_RESOURCE_CONFIG_NAME-theme.gresource /usr/share/gnome-shell/theme/Pop/gnome-shell-theme.gresource${RCol}
"
else
echo Failure
exit 1
fi
}
###################################################
############################################################################################
case "$1" in
--help)
HELP
exit 1
;;
--reset)
ROUTINE_CHECK
if ! [ -f $dest/custom-gdm-background.gresource ]; then
echo -e "
-----------------------------------------------------------------------------
No need, Already Reset. ${Red}(or unlikely background is not set using this Script.)${RCol}
-----------------------------------------------------------------------------"
exit 1
elif [ "$UID" != "0" ]; then
echo -e "${BRed}This Script must be run with sudo${RCol}"
exit 1
else
rm $dest/custom-gdm-background.gresource
update-alternatives --quiet --set $GDM_RESOURCE_CONFIG_NAME-theme.gresource "$source"
cd /usr/local/share
rmdir --ignore-fail-on-non-empty -p gnome-shell/custom-gdm
echo -e "${Gre}
---------------
|Reset Success|
---------------
Changes will be effective after a Reboot ${RCol}"
exit 1
fi
;;
--image)
if [ -z "$2" ]; then
echo -e "${BRed}Image path is not provided${RCol}"
exit 1
fi
if
file "$2" | grep -qE 'image|bitmap'
then
ROUTINE_CHECK
if [ "$3" == "rescue" ]; then
RESCUE_MODE
fi
EXTRACT
cd theme
cp "$2" ./gdm-background
mv $GDM_RESOURCE_CONFIG_NAME.css original.css
echo '@import url("resource:///org/gnome/shell/theme/original.css");
#lockDialogGroup {
background: '$color' url("resource:///org/gnome/shell/theme/gdm-background");
background-repeat: no-repeat;
background-size: cover;
background-position: center; }' >$GDM_RESOURCE_CONFIG_NAME.css
cd /tmp
CREATE_XML
cd theme
glib-compile-resources custom-gdm-background.gresource.xml
mv custom-gdm-background.gresource $dest
SET_GRESOURCE
exit 1
else
echo -e "${BRed}
Absolute path to image is neither provided nor is it valid.
see help with below command${BWhi}
$ ./pop-gdm-set-background --help${RCol}"
exit 1
fi
;;
--color)
if [ -z "$2" ]; then
echo -e "${Red}Color is not provided.
Use ${BWhi}\$ sudo ./pop-gdm-set-background --color #aee02a${RCol} to set ${BWhi}#aee02a${RCol} as the background color.${RCol}"
exit 1
fi
if ! [[ $2 =~ ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ ]]; then
echo -e "${BRed}Provided color is not a valid 'HEX Color Code'${RCol}
See help with below command
${BWhi}$ ./pop-gdm-set-background --help${RCol}"
exit 1
fi
ROUTINE_CHECK
if [ "$3" == 'rescue' ]; then
RESCUE_MODE
fi
EXTRACT
cd theme
mv $GDM_RESOURCE_CONFIG_NAME.css original.css
echo '@import url("resource:///org/gnome/shell/theme/original.css");
#lockDialogGroup {
background-color: '$2'; }' >$GDM_RESOURCE_CONFIG_NAME.css
cd /tmp
CREATE_XML
cd theme
glib-compile-resources custom-gdm-background.gresource.xml
mv custom-gdm-background.gresource $dest
SET_GRESOURCE
exit 1
;;
--gradient)
if [ "$2" == "horizontal" ] || [ "$2" == "vertical" ]; then
direction=$2
else
echo -e "${BRed}Gradient direction is not provided.${RCol}
Use ${BWhi}$ sudo ./pop-gdm-set-background --gradient horizontal \#aa03af \#afa0ee${RCol} OR
${BWhi}$ sudo ./pop-gdm-set-background --gradient vertical \#aa03af \#afa0ee${RCol} to set a vertical gradient.
See ${BWhi}./pop-gdm-set-background --help for more info${RCol}"
exit 1
fi
if [[ -z "$3" || -z "$4" ]]; then
echo -e "${BRed}color/colors is/are not provided${RCol}"
exit 1
fi
if ! [[ $3 =~ ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ ]] || ! [[ $4 =~ ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ ]]; then
echo -e "${BRed}Provided color/colors is/are not a valid 'HEX Color Code'${RCol}.
See help with below command
${BWhi}$ ./pop-gdm-set-background --help${RCol}"
exit 1
fi
ROUTINE_CHECK
if [ "$5" == "rescue" ]; then
RESCUE_MODE
fi
EXTRACT
cd theme
mv $GDM_RESOURCE_CONFIG_NAME.css original.css
echo '@import url("resource:///org/gnome/shell/theme/original.css");
#lockDialogGroup {
background-gradient-direction: '$direction';
background-gradient-start: '$3';
background-gradient-end: '$4'; }' >$GDM_RESOURCE_CONFIG_NAME.css
cd /tmp
CREATE_XML
cd theme
glib-compile-resources custom-gdm-background.gresource.xml
mv custom-gdm-background.gresource $dest
SET_GRESOURCE
exit 1
;;
*)
echo -e "Use the options ${BWhi}--image |--color | --gradient | --help | --reset${RCol}"
exit 1
;;
esac
exit
I do hope that you find this useful if you are a fan of Pop!_OS like I am. I’m on my fourth System 76 machine and still a huge fan of System 76.
Have a nice day. Don’t worry, be happy!
Thanks for the script, Chuck. All options including gradients are working on my Pop 22.04
Super! Thanks!
excuse me, I’m new, how I can run this pop-gdm?
Sorry I did not reply sooner – work gets in the way. This is a bash script. Copy the script, name it as you choose. Let’s just call it mybackground.sh for ease here. Copy it wherever you keep your scripts. Make it executable:
chmod 700 mybackground.sh
Then execute with sudo privileges:
sudo ./mybackground.sh $mypicture.jpg
Where $mypicture.jpg is the picture you choose.