Bonjour,
Je propose ici une manière simple de
changer le fond d'écran de GDM en se servant de
zenity. Ce dernier est présent sur les distributions qui sont prises en charge par le programme.
Tout ce qu'il y a faire est de copier/coller ce qui suit dans fichier que vous nommez comme vous voulez, rendre exécutable ce fichier, cliquer sur celui ci et suivre les instructions.
C'est une première ébauche, fonctionnelle mais certainement bourrée de coquilles et autres erreurs de code, alors n'hésitez pas à faire part de vos remarques et suggestions. 🙂
Actuellement, sont prises en charge les distributions suivantes :
Edit 01 :
Ajout du support pour Arch Linux
Edit 02 :
Ajout du support pour Mageia 7
Edit 03 :
Ajout du support pour Ubuntu 16.04 --> Bien évidemment, il faut au préalable avoir remplacé lightdm par gdm... 😛
Edit 04 :
Ajout du support pour CentOS 8 + correction sur contrôle des dépendances
Edit 05 :
Ajout du support pour Pop!_OS 20.04
Edit 06 :
Ajout du support pour PureOS 9.0 + correction sur contrôle du nom et de la version du système d'exploitation
Edit 07 :
Ajout du support pour Kali Linux 2020.2
Edit 08 :
Ajout du support pour EndeavourOS
Edit 09 :
Ajout du support pour OpenSUSE 15.1
Edit 10 :
Ajout du support pour Manjaro Linux
Edit 11 :
Ajout du support pour Zorin-OS 15.2
Edit 12 :
Ajout du support pour ArcoLinuxB-Gnome --> Bien que ce soit une version Gnome, lightdm est le gestionnaire de session par défaut... Il faut donc pensé à remplacer lightdm par gdm.
Edit 13 :
Ajout du support pour Trisquel 8.0
#!/bin/bash
## This script allows to replace easily the GDM login wallpaper and
## also may restore the default values.
##
## It uses Zenity program which is installed by default on
## the O.S versions for which it is supposed to work.
##
## If necessary, it will be proposed the installation of
## certain glib libraries essential to the continuation of the script.
##
## by lynn
## version 1.0.1
##
## Licence : https://www.gnu.org/licenses/gpl-3.0.html
# Constants
supported_os=( 'Ubuntu 16.04' 'Ubuntu 18.04' 'Ubuntu 20.04' 'Ubuntu 20.10' 'Ubuntu 21.04' 'Debian 10' 'Fedora 32' 'Arch Linux' 'Mageia 7' 'CentOS 8' 'Pop!_OS 20.04' 'PureOS 9.0' 'Kali 2020.2' 'EndeavourOS' 'openSUSE 15.1' 'Manjaro' 'Zorin 15' 'ArcoLinuxB-gnome' 'Trisquel 8.0' ) # Supported O.S version
required_packages='glib-compile-resources' # Dependencies
workdir=/tmp # Set place to create work directory
# Set O.S name and version
case $(. /etc/os-release; echo "$ID") in
ubuntu|pureos|fedora|mageia|pop|debian|centos|kali|opensuse-leap|zorin|trisquel )
os_version=$(. /etc/os-release; echo "${PRETTY_NAME%% *}" "${VERSION_ID%% *}");;
arch|manjaro|arcolinux )
os_version=$(. /etc/os-release; echo "${NAME%% *}");;
* )
zenity --warning \
--width="300" \
--height="100" \
--ok-label="Ok" \
--title="GDM Background Changer" \
--text="\n<b>Unable to determine your operating system!</b>" || exit 1;;
esac
# Check supported O.S
[[ ! "${supported_os[@]}" =~ ${os_version}*.? ]] && \
zenity --info \
--width="400" \
--height="100" \
--ok-label="Quit program" \
--title="GDM Background Changer" \
--text="<b>Your current operating system is not supported\!</b> \n\n<u>Only these versions are:</u>\n\n<b>Ubuntu 16.04\nUbuntu 18.04\nUbuntu 20.04\nUbuntu 20.10\nDebian Buster\nFedora 32\nArch Linux\nMageia 7\nCentOS 8\nPop\!_OS 20.04\nPureOS 9.0\nKali Linux 2020.2\nEndeavourOS\nOpenSUSE 15.1\nManjaro Linux\nZorin 15\nArcoLinux\nTrisquel 8.0</b>" && exit 1;
# Check display manager
shopt -s nocasematch
[[ ! $XDG_CURRENT_DESKTOP =~ gnome ]] && \
zenity --info \
--width="400" \
--height="100" \
--ok-label="Quit program" \
--title="GDM Background Changer" \
--text="\n<b>Your current display manager is not GDM\!</b>" && exit 1;
# Check dependencies
[[ "$(command -v $required_packages)" == "" ]] && { \
zenity --question \
--title="GDM Background Changer" \
--width="400" \
--height="100" \
--ok-label="Yes" \
--cancel-label="Quit program" \
--text="<b>Additional glib libraries need to be installed\n\nProceed?</b>" || \
exit 1; } && { \
if [[ "$os_version" =~ ^(Fedora|CentOS)$*.? ]]; then
pkexec yum install -y glib2-devel
elif [[ "$os_version" =~ openSUSE ]]; then
pkexec zypper install -y glib2-devel
elif [[ "$os_version" =~ ^(Ubuntu|Zorin)$*.? ]]; then
pkexec apt install -y libglib2.0-dev-bin
fi
};
# Set some variables according to O.S version used
case "${os_version}" in
'CentOS 8'|'Fedora 32'|'Debian 10'|'Arch Linux'|'Mageia 7'|'Ubuntu 16.04'|'PureOS 9.0'|'Kali 2020.2'|'EndeavourOS'|'openSUSE 15.1'|'Manjaro'|'ArcoLinuxB-gnome'|'Trisquel 8.0' )
gdm_gresource=/usr/share/gnome-shell/gnome-shell-theme.gresource
css=gnome-shell.css;;
'Ubuntu 18.04' )
gdm_gresource=/usr/share/gnome-shell/gnome-shell-theme.gresource
custom_css=/usr/share/gnome-shell/theme/ubuntu.css
css=gnome-shell.css;;
'Zorin 15' )
gdm_gresource=/usr/share/gnome-shell/gnome-shell-theme.gresource
custom_css=/usr/share/themes/ZorinBlue-Dark/gnome-shell/gnome-shell.css
css=gnome-shell.css;;
'Ubuntu 20.'*|'Ubuntu 21.04' )
gdm_gresource=/usr/share/gnome-shell/theme/Yaru/gnome-shell-theme.gresource
css=gdm3.css;;
'Pop!_OS 20.04' )
gdm_gresource=/usr/share/gnome-shell/theme/Pop/gnome-shell-theme.gresource
css=gdm3.css;;
* )
zenity --warning \
--width="200" \
--height="100" \
--title="GDM Background Changer" \
--ok-label="Quit program" \
--text="\nUnable to assign variables!" && exit 1;;
esac
while :; do
main_window=$(zenity --width="350" \
--height="180" \
--title="GDM Background Changer" \
--list \
--text="<b>What do you want to do?</b>" \
--radiolist \
--column="Select" \
--column="Choice" \
--ok-label="Next" \
--cancel-label="Quit program" \
FALSE "Change GDM background" FALSE "Restore default settings") || exit 1;
case $main_window in
"Change GDM background")
# Image file selection
zenity --info \
--width="250" \
--height="100" \
--ok-label="Ok" \
--title "GDM Background Changer" \
--text="\n<b>Please, select an image file.</b>" || exit 1;
while :; do
background_file=$(zenity --title="GDM Background Changer" \
--file-selection) || exit 1;
[[ -z $(file ${background_file} | grep -Eoi "*.g image data") ]] &&
{ zenity --error \
--width="300" \
--height="100" \
--title="GDM Background Changer" \
--text="<b>${background_file##*/}</b> is not a valid format picture! \n\n<b><i>Please select another one to continue.</i></b>" \
--ok-label="OK" && continue || exit 1; } || \
break;
done
# Set background-repeat value
zenity --question \
--width="300" \
--height="100" \
--title="GDM Background Changer" \
--text="\n<b>Do you use more than one screen?</b>" \
--cancel-label="No" \
--ok-label="Yes" && \
background_repeat="repeat" || \
background_repeat="no-repeat"
# Backup gnome-shell-theme.gresource file
[[ ! -f ${gdm_gresource}_bak ]] && { \
cp ${gdm_gresource} $workdir/${gdm_gresource##*/}_bak;
gdm_gresource_bak=$workdir/${gdm_gresource##*/}_bak; } || \
gdm_gresource_bak=${gdm_gresource}_bak
# For distribution custom css, backup custom_css file
[[ -f ${custom_css} ]] && [[ ! -f ${custom_css}_bak ]] && { \
cp $custom_css $workdir/${custom_css##*/}_bak
custom_css_bak=$workdir/${custom_css##*/}_bak; } || \
custom_css_bak=${custom_css}_bak
# Create the work directory from resource, extract theme and copy selected image into it
for r in `gresource list $gdm_gresource_bak`; do
f=$r
r=${r#\/org\/gnome\/shell/}
[ ! -d $workdir/${r%/*} ] && mkdir -p $workdir/${r%/*};
gresource extract $gdm_gresource_bak $f >$workdir/$r
done
# For Opensuse only, copy background as noise-texture.png otherwise, it does not work
[[ "$os_version" =~ openSUSE ]] && {
cp "$background_file" $workdir/${r%%/*}/noise-texture.png;
background_file=noise-texture.png; } || \
cp "$background_file" $workdir/${r%%/*};
# Apply replacing css file text
original="#lockDialogGroup \{.*?\}"
modified="#lockDialogGroup {
background: url(resource:\/\/\/org\/gnome\/shell\/theme\/${background_file##*/});
background-repeat: $background_repeat;
background-size: cover; }"
perl -i -0777 -pe "s/$original/$modified/s" $workdir/${r%%/*}/$css
# Create gresource xml file
files=$(find $workdir/${r%%/*} -type f -printf "%P\n" | xargs -i echo " <file>{}</file>")
cat <<-EOF >"$workdir/${r%%/*}/${gdm_gresource##*/}.xml"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/shell/theme">
$files
</gresource>
</gresources>
EOF
# Compile gresources
cd $workdir/${r%%/*}
glib-compile-resources ${gdm_gresource##*/}.xml
# Should we keep the working directory?
zenity --question \
--width="400" \
--height="100" \
--cancel-label="No" \
--ok-label="Yes" \
--title="GDM Background Changer" \
--text="A temporary working directory was created during operation.\n\n<b>Would you like to keep it?</b>" && \
cp -r $workdir/${r%%/*} $HOME/GDM_workdir_$(date +"%Y%m%d%H%M%S") && \
zenity --info \
--width="400" \
--height="100" \
--ok-label="Ok" \
--title="GDM Background Changer" \
--text="\nWork directory has been copied in your personnal folder as \n\n<b>GDM_WORKDIR_{<i>date</i>}</b>."
# Does the computer / GDM service have to restart?
while :; do
[[ "$css" =~ gnome-shell ]] &&
{ zenity --question \
--width="420" \
--height="100" \
--cancel-label="No" \
--ok-label="Yes" \
--title="GDM Background Changer" \
--text="For the changes to take effect, you will need to restart your pc.\n\n<b>Choose to restart after modifications?</b>" && \
{
end_cmd="reboot";
} || {
end_cmd="rm -rf $workdir/theme"; break;
};
} || \
{ zenity --question \
--width="440" \
--height="100" \
--cancel-label="No" \
--ok-label="Yes" \
--title="GDM Background Changer" \
--text="For the changes to take effect, you will need to restart GDM service.\n\n<b>Choose to restart GDM service after modifications?</b>" && \
{
end_cmd="rm -rf $workdir/theme; service gdm restart";
} || {
end_cmd="rm -rf $workdir/theme"; break;
};
} || rm -rf $workdir/theme $gdm_gresource_bak
break
done
# Apply modifications as root
zenity --question \
--width="400" \
--height="100" \
--cancel-label="Quit program" \
--ok-label="Proceed" \
--title="GDM Background Changer" \
--text="\n<b>Entering your password is necessary to apply changes.</b>" &&
pkexec bash -c "[ ! -f ${gdm_gresource}_bak ] && mv $gdm_gresource_bak ${gdm_gresource}_bak;
[ ! -z $custom_css ] && [ ! -f ${custom_css}_bak ] && mv $custom_css_bak ${custom_css}_bak;
cp $workdir/${r%%/*}/${gdm_gresource##*/} ${gdm_gresource};
[ ! -z $custom_css ] && perl -i -0644 -pe 's/$original/$modified/s' $custom_css;
$end_cmd"; exit 0 || exit 1;
;;
"Restore default settings")
# If existing *_bak file(s), set variables and functions
[[ -f ${gdm_gresource}_bak ]] && \
restore=( "ggre" )
ggre() {
echo mv ${gdm_gresource}_bak $gdm_gresource;
}
[[ -f ${custom_css}_bak ]] && \
restore+=( "ucss" )
ucss() {
echo mv ${custom_css}_bak $custom_css;
}
# Main restore command
case ${restore[@]} in
# If empty *_bak file, nothing to restore
"" )
zenity --info \
--title="GDM Background Restore" \
--width="200" \
--height="100" \
--ok-label="Back" \
--text="\n<b>Nothing to restore yet \!</b>" || exit 1;
;;
# Does the computer / GDM service have to restart?
[a-z]* )
while :; do
[[ "$css" =~ gnome-shell ]] &&
{ zenity --question \
--width="460" \
--height="100" \
--cancel-label="No" \
--ok-label="Yes" \
--title="GDM Background Restore" \
--text="For the changes to take effect, you will need to restart your computer.\n\n<b>Choose to restart after modifications ?</b>" && \
{
end_cmd="reboot"; break;
} || {
end_cmd="rm -rf $workdir/theme"; break;
};
} || \
{ zenity --question \
--width="440" \
--height="100" \
--cancel-label="No" \
--ok-label="Yes" \
--title="GDM Background Restore" \
--text="For the changes to take effect, you will need to restart GDM service.\n\n<b>Choose to restart GDM service after modifications ?</b>" && \
{
end_cmd="rm -rf $workdir/theme; service gdm restart"; break;
} || {
end_cmd="rm -rf $workdir/theme"; break;
};
};
break
done
# Apply modifications as root
zenity --question \
--width="400" \
--height="100" \
--cancel-label="Quit program" \
--ok-label="Proceed" \
--title="GDM Background Restore" \
--text="You will restore the original GDM files.\n\n<b>Entering your password is necessary to apply changes.</b>" &&
pkexec bash -c "`ggre`; `ucss`; $end_cmd" && exit 0 || exit 1
;;
* )
zenity --warning \
--width="150" \
--height="100" \
--ok-label="Quit program" \
--title="GDM Background Restore" \
--text="Unknown error !" && exit 1;
;;
esac
;;
*)
zenity --error \
--width="250" \
--height="100" \
--title="GDM Background Changer" \
--text="<b>Missing selection ! </b>\n\nClick <b>OK</b> to choose again." \
--ok-label="Ok" || exit 1;
;;
esac
done