GUI to Change Background Arctica Greeter (Login Screen) on Ubuntu-MATE 22.04

Ah zenity... I haven't run zenity a loooong time.

You can use sudo and zenity to ask for password.

zenity --password | sudo -S "command"

-S read from stdin

In a script something like this:

if [[ "$EUID" = 0 ]]; then
    echo "already root"
else
    sudo -k # make sure to ask for password on next sudo
    if zenity --password | sudo -S true; then
        echo "correct password"
    else
        echo "wrong password"
        exit 1
    fi
fi
# Do your sudo stuff here. Password will not be asked again due to caching.
sudo sed -i "s|background=.*|background='$mybg'|g" "$configfile"
sudo glib-compile-schemas "$schemadir/."

sudo -k # make sure to ask for password on next sudo

Also have a look at this in the manual

man sudo
.......
-E, --preserve-env
Indicates to the security policy that the user wishes to pre‐
serve their existing environment variables. The security
policy may return an error if the user does not have permis‐
sion to preserve the environment.

3 Likes