1

I've written a simple script for our Ubuntu machines at college which sets some dconf overrides to set the theme, background etc. However I cannot seem to get it to correctly set the login screen background.

Section of the script for this purpose:

#Set login background and remove dots
echo "Setting lightdm dconf settings"
xhost +SI:localuser:lightdm
su lightdm -c "gsettings set com.canonical.unity-greeter background '/background.png'"
su lightdm -c "gsettings set com.canonical.unity-greeter draw-grid false"

These same commands work if inputted directly into a terminal that is logged in as the lightdm user, for example:

sudo su lightdm -s /bin/bash
gsettings set com.canonical.unity-greeter background '/background.png'
gsettings set com.canonical.unity-greeter draw-grid false

Sets the wallpaper fine

Any ideas as to why the commands work but not the script?

Thanks

1 Answer 1

1

Here's how I solved it, instead of running "sudo bash" or in your case running "sudo -c" (which either makes your script pause when changing user or simply doesn't work) I run three small scripts.

(Don't forget to make each of the scripts executable with "chmod +x script_name.sh")

First script is my install.sh:

sudo cp third_script.sh /tmp         # Copy third_script to tmp for easier access
sudo chmod 0755 /tmp/third_script.sh # This needs to be executable by lightdm
sudo bash second_script.sh           # Runs next file
sudo rm /tmp/third_script.sh         # Now we can remove the third script

Then in second_script.sh I add lightdm to xhost and run the third script file as the lightdm-user:

#!/bin/bash
echo "$USER"                         # To see if root is running the script
xhost +SI:localuser:lightdm
su lightdm -s /tmp/third_script.sh

And the third_script is where the magic happens:

#!/bin/bash
echo "$USER"                         # To see if lightdm is running the script
gsettings set com.canonical.unity-greeter background '/background.png'
gsettings set com.canonical.unity-greeter draw-grid false

This works for me! Let me know if there is any easier way.

2
  • You log in as user ligthdm? With what pw?
    – Frank N
    Sep 10, 2022 at 12:08
  • @FrankNocke As I recall it the su command will ask for the super user password
    – Tuxedo Joe
    Oct 7, 2022 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .