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

A GUI to change the login-screen background.
( bash script, using zenity )

#!/bin/bash

mybg="/usr/share/backgrounds/mybackground"
schemadir="/usr/share/glib-2.0/schemas"
configfile="$schemadir/30_ubuntu-mate.gschema.override"

tmpfile="$XDG_RUNTIME_DIR/wallpaper$$"
trap "rm $tmpfile &>/dev/null" INT TERM EXIT

if ! grep "background='$mybg'" "$configfile" &>/dev/null
then
	pkexec sed -i "s|background=.*|background='$mybg'|g" "$configfile"
	pkexec glib-compile-schemas "$schemadir/."
fi

eom "$mybg" &

sleep 1
cp "$(zenity --title LoginBackgroundSelector --file-selection )" "$tmpfile" || exit
pkexec cp "$tmpfile" "$mybg"

eom "$mybg"

It works perfectly but I am not completely satisfied with my use of 'pkexec' here. Any suggestions are welcome.

2 Likes

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

Marvellous! Thanks ! Oh yes, that was exactly what I needed, you're awesome :smiley:

EDIT: improved code

#!/bin/bash

exec &>/dev/null
source "$HOME/.config/user-dirs.dirs"

text1="Login Background Changer"
text2="Select Background for Login"
mybg="/usr/share/backgrounds/mybackground"
schemadir="/usr/share/glib-2.0/schemas"
configfile="$schemadir/30_ubuntu-mate.gschema.override"

tmpfile="$XDG_RUNTIME_DIR/delete_me_$$"
cleanup()
{
	rm $tmpfile
	sudo -k
}
trap "cleanup" INT TERM EXIT

zenity --title="$text1" --password | sudo -S true || exit

if ! grep "background='$mybg'" "$configfile"
then
	sudo sed -i "s|background=.*|background='$mybg'|g" "$configfile"
	sudo glib-compile-schemas "$schemadir/."
fi

eom "$mybg" &

sleep 1
cp "$(zenity --title="$text2" --file-selection --filename="$XDG_PICTURES_DIR/*")" "$tmpfile" || exit
sudo cp "$tmpfile" "$mybg"

eom "$mybg"

P.S.:
b.t.w. are you the same misko that composed my favourite laptopbackground ?
(i've gratefully been using this for years now) :slight_smile:

3 Likes

Oh, I'm famous now, ha, ha.
Such a good surprise today, I'm so glad you like the background.
My sister also has it on laptop for years.
Other people told me the kids usually ask why is the fox sleeping. :slightly_smiling_face:

2 Likes

Oh, before I forget:
At anyone following this thread, the best solution (much better than my hack) is to revert from arctica-greeter to the old tried en tested (and working) slick-greeter.

1 Like

Thanks tkn for a great script.

I learned some new techniques from the script as well.

1 Like

An easier way...Remove arctica greeter...install slick greeter...install lightdm settings...then go to system/admin and open Login Window app and change background to whatever you like!

3 Likes

Welcome @garmich50 to the community!

Just tried on Ubuntu MATE v22.10.
It works.
I saved your code into a file with nano and ran with source command. Named "MATE-Background-Changer" :grin:
I didn't give the file any suffix. Isn't it better to have a .sh suffix?
By the way, it doesn't run through file explorer - caja by the time - I could only run it through terminal by source or .

Well it's a few steps longer right?
B.T.W, I thought MATE is already using lightdm?
Isn't it?

Technically it doesn't matter at all, but as a reminder for yourself that a file is a script it is absolutely helpful.

You will need to make the file executable by means of caja (properties) or the command chmod a+x

By the way, although this script of mine does work for anyone who wants to keep 'arctica-greeter', it might be better to replace the lightdm-greeter 'arctica' for 'slickgreeter' which will give you the official 'loginscreen' customizing options.
This link shows you how to do that (including settings):
Replace arctica-greeter back to slick-greeter on 20.10 for better compatibilty with other desktop environments

2 Likes

Yep, Thank you!

But I'm so curious!
Just in case, if anyone has some free time to answer,(:pray:) I'm so curious why it's installed by default?
If slick-greeter is more useful and more compatible with other desktops, then why arctica-greeter is installed by default in Ubuntu-MATE? Is it default with Gnome and/or Ubuntu itself? Is it more compatible with MATE except not having the option to change login screen? Or since slick-greeter has some bugs or any problems so we prefer artica to be the default?

Sorry if I'm noob

2 Likes

That is absolutely a very good and very valid question.
To be honest, I don't know :man_shrugging:
I am also a bit curious about that.

The desktop team might have had its reasons.
Maybe @franksmcb or @vkareh know on which technical merits this decision was taken.

2 Likes

The decision to switch to arctica-greeter was made by Wimpy along with the switch to Ayatana Indicators

His explanation for this is in the 22.10 Release Notes

@Norbert_X's how-to posting is still a solid work-around. Replace arctica-greeter back to slick-greeter

4 Likes

To cite the part about Arctica greeter:

  • We’ve switched from Slick Greeter to Arctica Greeter (both forks of Unity Greeter)
    • Arctica Greeter integrates completely with Ayatana Indicators; so there is now a consistent Indicator experience in the greeter and desktop environment.
4 Likes

It also says at first:

Ubuntu MATE 20.10 is our first release to feature Ayatana Indicators and as such there are a couple of drawbacks; there is no messages indicator and no graphical tool to configure the display manager greeter (login window) :disappointed:

Both will return in a future release and the greeter can be configured using dconf-editor in the meantime.

Seems that I already can configure Arctica Greeter after installing dconf-editor, Does anyone have any experience with it?

Edit: I have installed it and you easily can change your logo or background with it, and many others.

Hi @tkn,

When I see something good, I like to make it more "user-protective" and verbose. So, to that end, here is my adaptation of your script. Maybe it will be more to the liking of the "skittish" or "newbies" out there. :slight_smile:

I also incorporated @anon94368460 's code segment for the EUID context switch.

#!/bin/bash

### REF:	https://ubuntu-mate.community/t/gui-to-change-background-arctica-greeter-login-screen-on-ubuntu-mate-22-04/25508/2

cleanup()
{
	rm -fv "${tmpfile}"
	sudo -k
}
trap "cleanup" INT TERM EXIT


create_schema_override()
{
	if [ ${mode} -eq 2 ]
	then
		${prefix} cp -pv "${configfile}.Oasis" "${configfile}"
	else
		sudo sed -i "s|background=.*|background='${mybg}'|g" "${configfile}"
	fi

	${prefix} glib-compile-schemas "${schemadir}/."
	printf "[msg] Schemas under '${schemadir}' have been recompiled ...\n\n"
}


mode=2
while [ $# -gt 0 ]
do
	case "${1}" in
		--mode_tkn ) mode=1 ; shift ;;
		--mode_em )  mode=2 ; shift ;;
		* ) printf "\n Invalid parameter specified on command line.\n Bye!\n" ; exit 1 ;;
	esac
done

text1="Login Background Changer"
text2="Select Background for login screen"

schemadir="/usr/share/glib-2.0/schemas"
configfile="${schemadir}/40_ubuntu-mate.gschema.override"

if [ ${mode} -eq 2 ]
then
	bgdir="/Local"
	mybg="${bgdir}/BG__Login_00__Ubuntu-MATE_WordMark_Modifiedv2_1440x900.png"

	tmpdir="/tmp"
	tmpfile="${tmpdir}/delete_me_$$"

	localidentifier="Oasis"
	localcustom="${configfile}.${localidentifier}"
else
	exec &>/dev/null
	source "${HOME}/.config/user-dirs.dirs"

	mybg="/usr/share/backgrounds/mybackground"
	tmpfile="${XDG_RUNTIME_DIR}/delete_me_$$"

	localidentifier=""
	localcustom=""
fi


if [ \( ${mode} -eq 2 \) -a \( -s "${mybg}" \) ]
then
	eom "${mybg}" &

	### FUTURE:  add preserve yes/no dialog for backup action
	cp -pv "${mybg}" "${mybg}.bak"
fi


if [[ "${EUID}" = 0 ]]
then
	echo "already root"
	prefix=""
else
	prefix="sudo"
	#${prefix} -k # make sure to ask for password on next sudo
	#if $(zenity --password | ${prefix} -k -S true )
	if $(zenity --width=600 --title="${text1}" --password | ${prefix} -S true )
	then
		printf "\n[msg] Password correct!  Proceeding ...\n"
	else
		printf "\n[msg] Password incorrect!  Abandoning ...\n"
		exit 1
	fi
fi


if [ ${mode} -eq 2 ]
then
	test -s "${localcustom}" && ${prefix} chown 1000:1000 "${localcustom}"
fi

${prefix} cat >"${localcustom}" <<EnDoFiNpUt
[org.ArcticaProject.arctica-greeter]
background='${mybg}'
EnDoFiNpUt


#${prefix} rm -fv "${configfile}"

if [ ! -s "${configfile}" ]
then
	printf "[msg] Will create new file '${configfile}' ...\n\n"
	create_schema_override
else
	if [ -n "$(grep "background='${mybg}'" "${configfile}" )" ]
	then
		printf "[msg] Background is already set to '${mybg}'\n\n"
	else
		create_schema_override
	fi
fi

sleep 1

if [ ${mode} -eq 2 ]
then
	selected="$(zenity --width=600 --title="${text2}" --file-selection --filename="${bgdir}/*" )"
else
	selected="$(zenity --title="${text2}" --file-selection --filename="${XDG_PICTURES_DIR}/*")"
fi

if [ -z "${selected}" ]
then
	printf "[msg] Process abandoned!\n\n" ; exit 1
fi

${prefix} cp "${selected}" "${tmpfile}" || exit 1


${prefix} cp "${tmpfile}" "${mybg}"

if [ $? -eq 0 ]
then
	eom "${mybg}" &
else
	printf "[msg] FAILED to copy  '${tmpfile}'  to  '${mybg}' ...\n"
	if [ -s  "${mybg}.bak" ]
	then
		printf "[msg] REVERTING to earlier Login background ...\n"
		${prefix} mv -fv "${mybg}.bak" "${mybg}"
		ls -l "${mybg}"
	fi
fi


3 Likes