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.
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.
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.
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!
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"
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 .
But I'm so curious!
Just in case, if anyone has some free time to answer,() 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?
Arctica Greeter integrates completely with Ayatana Indicators; so there is now a consistent Indicator experience in the greeter and desktop environment.
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)
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.
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.
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