Hello World,
If you are a regular reader of this blog, you probably remember that some time ago, we wanted to customize the GDM3 login manager background image as the default one was not fitting our needs (and needs of some of our customers and friends). Before Ubuntu 17.10, the login manager used was lightdm and customizing the background image at login screen was really easy. Since Canonical decided to drop Unity and Lightdm packages in Ubuntu 17.10 and later, changing the background image for login scree was not that straight forward as in the past. However, the change was not that difficult either because the gdm login screen is controlled via css file basically.
In one of our previous post, we have explained and demonstrated how to customize the login screen. The procedure described involved manually editing some css file and update them with the correct information. Then, because we like automation and play around with Linux scripting, we came up with a basic bash script that could update the login screen in a easier way. The script is really basic and only perform one action (and only one time) : it updates the css file
In this post, we spend some time in improving the script and we are sharing it here… So, let’s see what’s new…..
Change-GDM-Background Script – Version 2.0
Overview
The version 1.0 of the script was really really basic and was developed to run only once with no error handling process either. The version 2.0 has been improved but again it’s has not developed to meet all possible scenario. No error handling is included in this version. However, some new features have been added into the script which are listed hereafter
- support Ubuntu 17.10, Ubuntu 18.04 and Ubuntu 18.10
- can run multiple times
- Zenity scripting has been used to provide some basic GUI dialog boxes
- pressing cancel button in the image selection dialog box will stop script execution
- code re-writing to ease maintenance for future updates (if any)
Again, even if this version of the script has been improved, it provides a limited set of functionalities. The script will basically update the css file used to control the gdm login background settings. The script expect to use a picture to be used as a background.
Important Note :
If you copy/paste the script, you might encounter some issues because font formatting might be not maintained during the copy/paste operation. Please ensure that format is accurate before launching the script. A downloadable version of the script is available at the bottom of the post
Disclaimer : As usual, use this at your own risk !!
#!/bin/bash ########################################################################## # Script_Name : Change-Gdm-Background-2.0.sh # # Description : Change background image of the GDM Login screen # # on ubuntu 17.10 and later # # Date : November 2018 # # written by : Griffon # # Web Site :http://www.c-nergy.be - http://www.c-nergy.be/blog # # Version : 2.0 # # Disclaimer : Script provided AS IS. Use it at your own risk.... # ########################################################################## #---------------------------------------------------# # Script Version information Displayed # #---------------------------------------------------# echo /bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;36m ! Change-Gdm-Background script - Ver 2.0 !\e[0m" /bin/echo -e "\e[1;36m ! Written by Griffon - November 2018 - www.c-nergy.be !\e[0m" /bin/echo -e "\e[1;36m !-------------------------------------------------------------!\e[0m" echo #--------------------------------------------------------------------------# # -----------------------Function Section - DO NOT MODIFY -----------------# #--------------------------------------------------------------------------# #--------------------------------------------------------------------# # Function 1 - Update css file on Ubuntu 17.10,18.04 # #--------------------------------------------------------------------# ubuntu_css() { echo /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;32m ! Check if script has been run already !\e[0m" /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" if [ -f /usr/share/gnome-shell/theme/ubuntu.css.griffon ] then sudo rm /usr/share/gnome-shell/theme/ubuntu.css sudo mv /usr/share/gnome-shell/theme/ubuntu.css.griffon /usr/share/gnome-shell/theme/ubuntu.css fi echo /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;32m ! Updating the ubuntu.css file....proceeding !\e[0m" /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" sudo cp /usr/share/gnome-shell/theme/ubuntu.css /usr/share/gnome-shell/theme/ubuntu.css.griffon sudo sed -i "/#lockDialogGroup/a background: #2c001e url(file:///usr/share/backgrounds/${fname});\nbackground-repeat: no-repeat;\nbackground-size: cover;\nbackground-position: center;\n}\nByGriffon" /usr/share/gnome-shell/theme/ubuntu.css sudo sed -i '/ByGriffon/,+2d' /usr/share/gnome-shell/theme/ubuntu.css } #--------------------------------------------------------------------# # Function 2 - Update css file on Ubuntu 18.10 # #--------------------------------------------------------------------# gdm_css() { echo /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;32m ! Check if script has been run already !\e[0m" /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" if [ -f /usr/share/gnome-shell/theme/Yaru/gnome-shell.css.griffon ] then sudo rm /usr/share/gnome-shell/theme/Yaru/gnome-shell.css sudo mv /usr/share/gnome-shell/theme/Yaru/gnome-shell.css.griffon /usr/share/gnome-shell/theme/Yaru/gnome-shell.css fi echo /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;32m ! Updating the gnome-shell.css file....proceeding !\e[0m" /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" echo sudo cp /usr/share/gnome-shell/theme/Yaru/gnome-shell.css /usr/share/gnome-shell/theme/Yaru/gnome-shell.css.griffon sudo sed -i "/#lockDialogGroup/a background: #2c001e url(file:///usr/share/backgrounds/${fname});\nbackground-repeat: no-repeat;\nbackground-size: cover;\nbackground-position: center;\n}\nByGriffon" /usr/share/gnome-shell/theme/Yaru/gnome-shell.css sudo sed -i '/ByGriffon/,+5d' /usr/share/gnome-shell/theme/Yaru/gnome-shell.css } #---------------------------------------------------# # Function 3 - Dialog Box select image... # #---------------------------------------------------# call_gui() { echo /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;32m ! Selecting an image...Proceeding !\e[0m" /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" echo pix=$(zenity --file-selection --title="select the new login image") if [ $? -eq 1 ] then echo /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;32m ! No image selected...Quitting !\e[0m" /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" echo exit fi # get just name of the file fname=$(basename $pix) # Next Step - Copy file to correct location echo /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;32m ! Copy image to correct location....proceeding !\e[0m" /bin/echo -e "\e[1;32m !--------------------------------------------------------!\e[0m" echo sudo cp $pix /usr/share/backgrounds/ } #--------------------------------------------------------------------------# # -----------------------END Function Section -----------------# #--------------------------------------------------------------------------# #--------------------------------------------------------------------------# #------------ MAIN SCRIPT SECTION -------------------# #--------------------------------------------------------------------------# #---------------------------------------------------# #-- Step 0 - Try to Detect Ubuntu Version.... #---------------------------------------------------# version=$(lsb_release -sd) codename=$(lsb_release -sc) echo /bin/echo -e "\e[1;33m |-| Detecting Ubuntu version \e[0m" if [[ "$version" = *"Ubuntu 17.10"* ]]; then /bin/echo -e "\e[1;32m |-| Ubuntu Version : $version\e[0m" call_gui ubuntu_css echo elif [[ "$version" = *"Ubuntu 18.04"* ]]; then /bin/echo -e "\e[1;32m |-| Ubuntu Version : $version\e[0m" echo call_gui ubuntu_css elif [[ "$version" = *"Ubuntu 18.10"* ]]; then /bin/echo -e "\e[1;32m |-| Ubuntu Version : $version\e[0m" call_gui gdm_css echo else /bin/echo -e "\e[1;31m !------------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;31m ! Your system is not running Ubuntu 18.04 Edition and later !\e[0m" /bin/echo -e "\e[1;31m ! The script has been tested only on Ubuntu 18.04 and later !\e[0m" /bin/echo -e "\e[1;31m ! The script is exiting... !\e[0m" /bin/echo -e "\e[1;31m !------------------------------------------------------------!\e[0m" echo exit fi #---------------------------------------------------# # Step 0 - Credits .... # #---------------------------------------------------# /bin/echo -e "\e[1;36m !--------------------------------------------------------!\e[0m" /bin/echo -e "\e[1;36m ! Change-Gdm-Background-2.0.sh !\e[0m" /bin/echo -e "\e[1;36m ! Version : 2.0 - November 2018 !\e[0m" /bin/echo -e "\e[1;36m ! Written By - Griffon !\e[0m" /bin/echo -e "\e[1;36m ! !\e[0m" /bin/echo -e "\e[1;36m ! Web :www.c-nergy.be - www.c-nergy.be/blog !\e[0m" /bin/echo -e "\e[1;36m !--------------------------------------------------------!\e[0m" echo #---------------------------------------------------# # Step 4 - Ask User to reboot system #---------------------------------------------------# echo echo "Need to reboot your machine to see the changes....:-)" echo zenity --info --title "Reboot needed" --text "A reboot of the machine is needed in order to apply the changes. Please Reboot your machine" --width=400
How to Use the Script
Set Execute Right on the script
After downloading the script and extracting from the zip, open a Terminal console. From the Terminal console, we will mark the script as executable. To mark the script as executable, you simply navigate to the location where the script is located and you issue the following command
chmod +x Change-Gdm-Background-2.0.sh
Click on picture for better Resolution
Execute the script
In the Terminal console, Browse to the location where the script has been stored and then issue the following command
./Change-Gdm-Background-2.0.sh
Depending how fast the script runs, you will see some information in the Terminal Console. In the screenshot below, you can see that the Ubuntu version is 18.04.1.
Click on picture for better Resolution
The script will ask you to select an image. Using the Zenity scripting engine, you will see a file browser dialog box opening. From this windows go to the location where the image you want to use is located
Click on picture for better Resolution
If you click on Cancel button in this dialog box, you will see that the script will stop executing an no changes to your system will be made. This is a new feature that we have added into the script in order to avoid misconfiguration in the css file.
Click on picture for better Resolution
If you have selected an image, the script will proceed and the correct css file will be updated. The script will prompt you for credentials. Provide them in order to proceed with the changes
Click on picture for better Resolution
When the change has been applied, a dialog box will appear reminding you to reboot the machine in order to apply the changes to your system and enjoy your new login background image
Click on picture for better Resolution
Press OK on the Dialog box and when ready, reboot your system.
The screenshot below shows the same process executed but on Ubuntu 18.10 system. When the script execute on Ubuntu 18.10, a window will open that will allow you to locate the image you want to use
Click on picture for better Resolution
Then, provide credentials if required
Click on picture for better Resolution
Finally, the reminder to reboot the system is displayed.
Click on picture for better Resolution
Because Ubuntu 18.10 is using a new theme, we had to add a new section in the script that would update the corresponding css file for this new gtk theme….
After the reboot, you should see the new login background displayed on your computer. The screenshot below shows the login screen we have configured in order to write this post… This is a cool one, isn’t it ?
Click on picture for better Resolution
Configure the Shield (lock screen)
At this stage, you have only configured the background image for the login screen. GDM has also a shield picture. This is the picture you see when your system is locked and you have to drag up to access the login page. (see screenshot below).
Click on picture for better Resolution
The script is not changing or configuring the shield picture. If you want to have really a consistent look n feel and use the same picture for the shield, you can manually set the picture through the change background settings. So right-click on the desktop anywhere and select the option change background settings
Click on picture for better Resolution
In the Background settings section, click on the lock background image, select your image
Click on picture for better Resolution
Note :
If you want to have a really full consistent user experience, you should also set the background image to the one used for the login screen and the lock screen. This is up to you. In some corporate environment, these settings are set to the same picture….
So, you should see something like this. Press OK to close everything
Click on picture for better Resolution
Now, lock your workstation and check that the shield picture (lock screen) is set accordingly
Click on picture for better Resolution
Download the Script
Please download the script : Change-Gdm-Background-2.0.sh.zip
Final Notes
Voila ! This is it for this post !
We had some fun in writing this little script and we hope that this utility can be useful to some people out there.. Using this little script, it should be easy to modify the login screen background picture. In the next post, we will still be discussing about the GDM background picture. There is a small utility out there that can perform the change as well.
Till next time
See ya