Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 24/04/2020, à 13:21

biokiller16

20.04: Changement fond d'écran de lancement & de connexion

Bonjour à tous,

Comme certains j'ai installé la nouvelle version ce jour, et je suis en cours de paramétrage de mon environnement de bureau. Je dois être efficace car mon pc me sert à gérer mon entreprise, cependant j'aime bien personnaliser mon environnement. big_smile

Donc comme j'avais pu faire sur 19.04 j'ai changé le fond d'écran lors dur lancement d'ubuntu et du gestionnaire de connexion. Cependant je n'arrive plus à retrouver comment faire.

Quelqu'un sait t'il quel technique utiliser?

Merci beaucoup à vous par avance.

Nor'blette from La ferme ô VR

Hors ligne

#2 Le 27/04/2020, à 10:10

yo57

Re : 20.04: Changement fond d'écran de lancement & de connexion

je cherche depuis un moment pas encore trouvé, le fichier de config GDM à l'air compilé il faut donc sans doute un outil ; je ne comprend pas pourquoi ils n'ajouter pas ça dans la config des fonds d'écran; depuis le temps

Hors ligne

#3 Le 27/04/2020, à 10:36

michcauch

Re : 20.04: Changement fond d'écran de lancement & de connexion

Bonjour,
Il faut installer "Ajustements" qui est indispensable pour la gestion du bureau Gnome 3.
Le changement de fond d'écran est dans la rubrique apparence.

Dernière modification par michcauch (Le 27/04/2020, à 10:37)


Cordialement
Michel
___
Ubuntu 22.04 sur Clevo N141WU

Hors ligne

#4 Le 27/04/2020, à 11:39

Roschan

Re : 20.04: Changement fond d'écran de lancement & de connexion

L'écran de connexion étant par nature affiché et géré par aucun utilisateur, c'est assez compliqué de l'intégrer aux paramètres d'un utilisateur...

D'autant que c'est une partie très sensible en termes de sécurité, et en autoriser la modification "facilement" est donc très risqué. Sachant qu'on le voit 3 secondes par jour, personne parmi les responsables de cette partie du système n'a été particulièrement intéressé à l'idée de prendre un tel risque pour si peu de bénéfice. Remarque que ça reste techniquement possible, et même si il est sans doute obsolète, j'avais écrit un tuto pour faire cette manip dans le wiki

Edit : quelqu'un l'a un peu mis à jour... mais maintenant il est mal structuré et totalement incompréhensible, avec des centaines de lignes de bash dénuées d'explications qui obstruent la lecture de la page. Version 2017 : https://doc.ubuntu-fr.org/tutoriel/chan … 1508499805 Version actuelle (testée en février, je suppose sur GNOME 3.34) : https://doc.ubuntu-fr.org/tutoriel/chan … e_plan_gdm
Pour 3.36, à toi de voir si ça marche ou pas

michcauch a écrit :

Bonjour,
Il faut installer "Ajustements" qui est indispensable pour la gestion du bureau Gnome 3.
Le changement de fond d'écran est dans la rubrique apparence.

Non, s'il te plaît informe toi avant de répondre, tu racontes littéralement n'importe quoi. Ce dont tu parles c'est l'écran de verrouillage sur les versions 17.10 à 19.10, et ça se gère très bien sans "Ajustements", c'était au contraire affiché de manière énorme dans les paramètres système. Et ça n'existe plus sur 20.04 (la valeur proposée dans "Ajustements" est obsolète et n'a aucun effet) puisque maintenant l'écran de verrouillage est une version lourdement floutée du fond d'écran de l'utilisateur.

Dernière modification par Roschan (Le 27/04/2020, à 11:50)

Hors ligne

#5 Le 27/04/2020, à 19:25

biokiller16

Re : 20.04: Changement fond d'écran de lancement & de connexion

michcauch a écrit :

Bonjour,
Il faut installer "Ajustements" qui est indispensable pour la gestion du bureau Gnome 3.
Le changement de fond d'écran est dans la rubrique apparence.

Merci pour ta réponse michcauch,

Cependant je parle de l'écran de progression quand ton ubuntu se lance au démarrage et celui de l'écran de login.

J'avais réussi à le faire sur 19.04, mais je n'ai pas retrouvé comment je m'y était pris.

Hors ligne

#6 Le 27/04/2020, à 19:37

biokiller16

Re : 20.04: Changement fond d'écran de lancement & de connexion

Roschan a écrit :

L'écran de connexion étant par nature affiché et géré par aucun utilisateur, c'est assez compliqué de l'intégrer aux paramètres d'un utilisateur...

D'autant que c'est une partie très sensible en termes de sécurité, et en autoriser la modification "facilement" est donc très risqué. Sachant qu'on le voit 3 secondes par jour, personne parmi les responsables de cette partie du système n'a été particulièrement intéressé à l'idée de prendre un tel risque pour si peu de bénéfice. Remarque que ça reste techniquement possible, et même si il est sans doute obsolète, j'avais écrit un tuto pour faire cette manip dans le wiki

Edit : quelqu'un l'a un peu mis à jour... mais maintenant il est mal structuré et totalement incompréhensible, avec des centaines de lignes de bash dénuées d'explications qui obstruent la lecture de la page. Version 2017 : https://doc.ubuntu-fr.org/tutoriel/chan … 1508499805 Version actuelle (testée en février, je suppose sur GNOME 3.34) : https://doc.ubuntu-fr.org/tutoriel/chan … e_plan_gdm
Pour 3.36, à toi de voir si ça marche ou pas

michcauch a écrit :

Bonjour,
Il faut installer "Ajustements" qui est indispensable pour la gestion du bureau Gnome 3.
Le changement de fond d'écran est dans la rubrique apparence.

Non, s'il te plaît informe toi avant de répondre, tu racontes littéralement n'importe quoi. Ce dont tu parles c'est l'écran de verrouillage sur les versions 17.10 à 19.10, et ça se gère très bien sans "Ajustements", c'était au contraire affiché de manière énorme dans les paramètres système. Et ça n'existe plus sur 20.04 (la valeur proposée dans "Ajustements" est obsolète et n'a aucun effet) puisque maintenant l'écran de verrouillage est une version lourdement floutée du fond d'écran de l'utilisateur.


Merci d'avoir pris du temps pour me répondre.

Oui, je suis bien tombé sur tes topics pendant mes recherches, mais, j'ai bien l'impression que ça ne fonctionne pas. Je vais réessayer.

Je comprends bien ce que tu dit sur le fait de l'utilité réel de faire cette action ou même de la rendre possible à l'utilisateur. Mais bon mon petit côté geek ressort sûrement.

Nor'blette

Hors ligne

#7 Le 28/04/2020, à 02:03

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Bonjour,

Je me suis fait un petit script pour modifier le fond d'écran de l'écran de connexion de GDM. Il fonctionne bien sur Ubuntu 20.04.
Il y a besoin d'installer un paquet (libglib2.0-dev-bin) et il faut s'assurer que l'image qui servira de fond d'écran pour GDM soit placée au même endroit que le script et qu'elle soit renommer en : noise-texture.png.
J'ai fait en sorte que mon image soit dans le format PNG puisque le nom est noise-texture.png. Je suppose qu'on peut mettre du JPG mais dans ce cas, dans le script, il faut penser à changer le nom de l'extension dans la variable en fonction du format de votre image.

Si l'image a une extension en .jpg.
wallpaper=noise-texture.png
devient
wallpaper=noise-texture.jpg

Également, la taille de mon image est de 1920x1080px. Il est tout à fait possible d'en choisir une autre mais il faut penser à renseigner les valeurs souhaitées dans le script, vers le début dans la partie modified_part (par exemple : 1680 px 1050 px ou 1024 px 768 px etc).

J'ai appelé mon script custom_gdm3.sh. Ne pas oublier de le rendre exécutable (chmod +x custom_gdm3.sh). Il se lance en tant qu'utilisateur normal (non root) mais demandera une élévation des privilèges à la fin, pour copier les fichiers nécessaires dans les répertoires concernés, à savoir :
/usr/share/gnome-shell
/usr/share/gnome-shell/theme

ainsi que pour exécuter la commande
update-alternatives gdm3-theme.gresource


#!/bin/bash

## Add personal wallpaper to gdm3 login screen
## Tested with Ubuntu 20.04
## 
## Needs the following package : libglib2.0-dev-bin
#
if [ ! $(command -v glib-compile-resources) ]; then
 printf '%s\n' "The following package must be installed to continue : libglib2.0-dev-bin
You can run the following command to a terminal :
sudo apt install libglib2.0-dev-bin"; exit 1
fi   

workdir=${PWD}
wallpaper=noise-texture.png # Place your picture in ${wordir} and rename it to 'noise-texture.png'
gst=/usr/share/gnome-shell/gnome-shell-theme.gresource
css=gdm3.css
original_part="#lockDialogGroup {\n  background-color: #41494c; }"
modified_part="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${wallpaper});\n  background-size: 1920 px 1080 px;\n  background-repeat: none; }"

# If not present, create 'theme' directory
#
if test ! -d ${workdir}/theme; then
  mkdir -p ${workdir}/theme
fi

# Copying Yaru-dark theme to 'theme' directory
#
if test -d /usr/share/themes/Yaru-dark; then
 cp /usr/share/themes/Yaru-dark/gnome-shell/* ${workdir}/theme/
else
 printf '%s\n' "No Yaru-dark directory found!
Maybe your operating system is not Ubuntu..?"; exit 1
fi

# gdm3 picture file 'noise-texture.png' must be found in ${workdir} directory
# 
if test -f ${workdir}/${wallpaper}; then
 cp -vf ${workdir}/${wallpaper} ${workdir}/theme/${wallpaper} 
else 
 printf '%s\n' "'${wallpaper}' file not found!"; exit 1
fi

# Extract resources
#
for r in `gresource list $gst`; do
        gresource extract $gst $r 2>/dev/null >$workdir/${r#\/org\/gnome\/shell/}
done

# Apply customization to 'gdm3.css' file
#
sed -i -z "s%${original_part}%${modified_part}%" "${workdir}/theme/${css}"

# Make "gnome-shell-theme.gresource.xml" file
#
FILES=$(find "theme" -type f -printf "%P\n" | xargs -i echo "    <file>{}</file>")
cat <<EOF >"${workdir}/theme/gnome-shell-theme.gresource.xml"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gnome/shell/theme">
${FILES}
  </gresource>
</gresources>
EOF

# Compile gresource file
#
printf '%s\n' "Compile gnome-shell-theme.gresource"
cd ${workdir}/theme
glib-compile-resources gnome-shell-theme.gresource.xml && \
printf '%s\n' "The file 'gnome-shell-theme.gresource' was successfully created!


"

###
## The following operations will be done with administrator rights
#
printf '%s\n' "#####
### The following operations will be done with administrator rights
#####

"

# Save original 'gnome-shell-theme.gresource'
#
printf '%s\n' "Saving original 'gnome-shell-theme.gresource' to 'gnome-shell-theme.gresource.backup'"
if test -f /usr/share/gnome-shell/gnome-shell-theme.gresource; then
 sudo cp /usr/share/gnome-shell/gnome-shell-theme.gresource{,.backup}
printf '%s\n' "Done !

"
fi

# Copy your picture renamed 'noise-texture.png' to /usr/share/gnome-shell/theme
#
printf '%s\n' "Copy your picture as 'noise-texture.png' to /usr/share/gnome-shell/theme"
 sudo cp ${wallpaper} /usr/share/gnome-shell/theme &&
printf '%s\n' "Done !

"

# Copy the custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell 
#
printf '%s\n' "Copy the custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell/theme"
 sudo cp ${workdir}/theme/gnome-shell-theme.gresource /usr/share/gnome-shell &&
printf '%s\n' "Done !

"

# Make new gnome-shell-theme.gresource as default alternative
#
printf '%s\n' "Make new gdm3.css the new default alternative"
 sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource >/dev/null &&
printf '%s\n' "Done !

"

# End operations
printf '%s\n' "Restart you pc and enjoy :)"


Normalement, il ne devrait pas y avoir de problème. Au cas où, on peut toujours restaurer le fichier original avec cette commande :

sudo cp /usr/share/gnome-shell/gnome-shell-theme.gresource.backup /usr/share/gnome-shell/gnome-shell-theme.gresource 

et éventuellement, si on veut retrouver les couleurs originales d'Ubuntu :

sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/theme/Yaru/gnome-shell-theme.gresource

Voila ! Si ça peut servir à quelqu'un. N'hésiter pas à l'améliorer ; je sais que dans le coin, il y a des pros du bash. tongue


«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#8 Le 28/04/2020, à 11:55

yo57

Re : 20.04: Changement fond d'écran de lancement & de connexion

@lynn merci pour ton script !
je viens de l'essayer, ça marche presque bien ....
je suis sur ubuntu 20.04, le script s'est bien déroulé mais je n'ai le fond choisi que sur un écran, pas les 2 et en particulier pas celui qui propose les utilisateur qui reste en fond uni gris tout moche
une idée ?

j'ai essayer :
- de virer la partie #41494C, pas mieux
- de virer la partie repeat : none, pas mieux

Dernière modification par yo57 (Le 28/04/2020, à 12:03)

Hors ligne

#9 Le 28/04/2020, à 12:03

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

yo57 a écrit :

je suis sur ubuntu 20.04, le script s'est bien déroulé mais je n'ai le fond choisi que sur un écran, pas les 2 et en particulier pas celui qui propose les utilisateur qui reste en fond uni

Je n'ai pas tout compris... tu as deux écrans ou tu parles des fonds d'écran (l'image) ?


«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#10 Le 28/04/2020, à 12:22

yo57

Re : 20.04: Changement fond d'écran de lancement & de connexion

en réalité, j'ai 3 écrans connectés à 2 cartes graphique nvidia.
au moment de la connexion, j'ai l'écran proposant les utilisateur avec le fond gris, le 2ème écran de la 1ère carte avec le bon fond choisi et le dernier avec  le fond gris aussi...
==> l'image choisi ne se met pas sur tous les écrans
-------------            -----------------          ---------------------
|  écran   |           |    écran      |          | écran de cnx |
|   gris     |           |   ok (img)   |          |   fond gris      |
-------------           -----------------           --------------------

Hors ligne

#11 Le 28/04/2020, à 12:40

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Je ne sais pas faire avec plusieurs écrans ; Peut-être que quelqu'un d'autre pourra t'apporter une solution...


«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#12 Le 28/04/2020, à 18:13

Roschan

Re : 20.04: Changement fond d'écran de lancement & de connexion

Je suppose que la règle "background-repeat: none;" est en cause, je ne sais pas ce qu'on peut mettre comme alternative (GNOME ne comprenant pas aussi bien le CSS qu'un navigateur web classique)

À la place de none, tu peux tester repeat-x, ou space ?

Lynn ton script est sur un github/gitlab quelque part ?

Hors ligne

#13 Le 28/04/2020, à 18:17

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Roschan a écrit :

Lynn ton script est sur un github/gitlab quelque part ?

Ah non pas du tout... c'est juste un truc vite fait.


«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#14 Le 28/04/2020, à 18:26

Roschan

Re : 20.04: Changement fond d'écran de lancement & de connexion

Je peux le mettre sur github sous licence GPL3 ? ce serait pour mettre le lien dans le tuto du wiki, au lieu du script géant qui encombre actuellement la page

Hors ligne

#15 Le 28/04/2020, à 18:34

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Pas de problème, sens-toi libre de faire comme bon te semble. smile


«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#16 Le 28/04/2020, à 19:04

Roschan

Re : 20.04: Changement fond d'écran de lancement & de connexion

jl'ai mis là https://github.com/maoschanz/change-gdm … background

je modifierais un jour je pense (pour donner l'image en paramètre par exemple), mais je veux tester sur 18.04 avant de modifier le wiki

Hors ligne

#17 Le 28/04/2020, à 20:09

yo57

Re : 20.04: Changement fond d'écran de lancement & de connexion

@Roschan : j'ai essayé les 2  options sans succès : la couleur par defaut (ici noir) est bien prise en compte sur les 2 écrans sans fond mais pas moyen d'avoir l'image sur les 3 écrans. Merci pour cette suggestion.

#lockDialogGroup {
  background: #000000 url(file:///usr/share/gnome-shell/theme/FD.jpg);
  background-size: 1920px 1080px;
  background-repeat: repeat-x}

et

#lockDialogGroup {
  background: #000000 url(file:///usr/share/gnome-shell/theme/FD.jpg);
  background-size: 1920px 1080px;
  background-repeat: space}

Hors ligne

#18 Le 28/04/2020, à 20:31

Roschan

Re : 20.04: Changement fond d'écran de lancement & de connexion

que l'option soit la bonne où non, je suis à peu près sûr qu'elle ne sera pas prise en compte si tu oublies le point virgule à la fin de la règle

Essaye aussi de mettre une largueur 3 fois plus grande pour la size

Dernière modification par Roschan (Le 28/04/2020, à 20:32)

Hors ligne

#19 Le 28/04/2020, à 22:47

yo57

Re : 20.04: Changement fond d'écran de lancement & de connexion

yes !
pas moyen de lui faire répéter l'image mais en lui mettant une image 3 x plus large et la config suivante, ça marche !

#lockDialogGroup {
  background: #000000 url(file:///usr/share/gnome-shell/theme/FD2.jpg);
  background-size: 5760px 1080px;
  background-repeat: repeat-x; }

Hors ligne

#20 Le 04/05/2020, à 18:49

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Quelques petites modifications pour être utilisable avec Ubuntu 18.04 et 20.04... J'ai repris en partie ce que Roschan a corrigé sur son github.
L'utilisation se fait en passant l'image voulue comme paramètre au script. Également, si l'image choisie est différente d'un format png, elle sera convertie automatiquement et renommée en noise-texture.png.

Utilisation: ./change-background /le/chemin/vers/mon/image.jpeg
#!/bin/bash

## Add personal background to gdm3 login screen
## Tested with Ubuntu 18.04 & 20.04
##
## Needs the following package : libglib2.0-dev-bin libxml2-utils
##
command -v xmllint glib-compile-resources &>/dev/null
[ $? -ne "0" ] && \
 {
   echo "You must to have installed the following packages to continue: libglib2.0-dev-bin libxml2-utils";
   echo ""
   echo "For proceed, you can copy / paste this command in a window terminal:" 
   echo "sudo apt install -y libglib2.0-dev-bin libxml2-utils";
   exit 1;
 }

################################################################################
# Constants ####################################################################

GST=/usr/share/gnome-shell/gnome-shell-theme.gresource

WORKDIR=theme

BACKGROUND_TARGET_NAME=noise-texture.png
BACKGROUND_WIDTH=1920
BACKGROUND_HEIGHT=1080

ORIGINAL_BACKGROUND_20_04="#lockDialogGroup {\n  background-color: #41494c; }"
EDITED_BACKGROUND_20_04="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"
ORIGINAL_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(resource:///org/gnome/shell/theme/noise-texture.png);\n  background-repeat: repeat; }"
EDITED_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"



################################################################################
# Functions ####################################################################

extract_current_theme() {
	# If not present, create 'theme' directory
	if test ! -d ${WORKDIR}; then
		mkdir -p ${WORKDIR}
	fi

	# Extract resources
        for r in `gresource list $GST`; do
                gresource extract $GST $r > ${WORKDIR}/${r##*/}
        done
}

edit_css_content() {
	if test -f ${WORKDIR}/gdm3.css; then
		css_file=gdm3.css
		ORIGINAL_BACKGROUND=${ORIGINAL_BACKGROUND_20_04}
		EDITED_BACKGROUND=${EDITED_BACKGROUND_20_04}
	elif test -f ${WORKDIR}/gnome-shell.css; then
		css_file=gnome-shell.css
		ORIGINAL_BACKGROUND=${ORIGINAL_BACKGROUND_18_04}
		EDITED_BACKGROUND=${EDITED_BACKGROUND_18_04}
	else
		echo "No css file found!"
		exit 1
	fi

	# Apply customization to the .css file
	sed -i -z "s%${ORIGINAL_BACKGROUND}%${EDITED_BACKGROUND}%" "theme/${css_file}"
}

create_new_gresource() {
	echo "Writing a new version of gnome-shell-theme.gresource.xml..."

	# Write a new "gnome-shell-theme.gresource.xml" file
	FILES=$(find "${WORKDIR}" -type f -printf "%P\n" | xargs -i echo "    <file>{}</file>")
	cat <<EOF >"${WORKDIR}/gnome-shell-theme.gresource.xml"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gnome/shell/theme">
${FILES}
  </gresource>
</gresources>
EOF
	# Add personal wallpaper to ${WORKDIR}
	cp -vf ${wallpaper} ${WORKDIR}/${BACKGROUND_TARGET_NAME}

	# Compile this XML file into a new gresource file
	echo "Compiling gnome-shell-theme.gresource..."
	cd ${WORKDIR}
	glib-compile-resources gnome-shell-theme.gresource.xml && \
	echo "The file 'gnome-shell-theme.gresource' has been successfully created!"
	cd ..
}

install_new_theme() {
	# Copy your background file to /usr/share/gnome-shell/theme
	echo "Copy your background file to /usr/share/gnome-shell/theme"
	sudo cp ${wallpaper} /usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME} && echo "Done !"

	# Make a backup of 'gnome-shell-theme.gresource' file to be able to restore in case of problem
	echo "Saving original 'gnome-shell-theme.gresource' to 'gnome-shell-theme.gresource.backup'"
	if test -f $GST; then
	sudo cp $GST{,.backup} && echo "Done !"
	fi

	# Copy the custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell
	echo "Copy the custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell/theme"
	sudo cp ${WORKDIR}/gnome-shell-theme.gresource /usr/share/gnome-shell && echo "Done !"
}


help() {
       echo "You must selected your background file..."
       echo "-----------------------------------------"
       echo "Use : bash `basename $0` /path/to/my/picture/file"
       echo ""
       echo "All pictures other than PNG format will be converted to PNG"  
}

################################################################################
# "Main" part of the script ####################################################

# Test if background picture is passed to parameter
if [ "${#1}" -eq "0" ]; then
	help
	exit 1
# Convert picture formats if needed and set variable ${wallpaper}
elif [ "$(mimetype -b $1)" = "image/png" ]; then
   wallpaper=$1
else
   convert $1 &>/dev/null "${1%%.*}.png"
   wallpaper=${1%%.*}.png
fi

extract_current_theme

edit_css_content

create_new_gresource

echo
echo "####################################################"
echo "# The next operations require superuser privileges #"
echo "####################################################"

install_new_theme

# Make new gnome-shell-theme.gresource as default alternative
case `lsb_release -rs` in
	18.04) test $(update-alternatives --list gdm3.css|wc -l) -gt 1 && { sudo update-alternatives --set gdm3.css /usr/share/gnome-shell/theme/gnome-shell.css >/dev/null && echo -e "Making new CSS alternative... \n\nDone !"; };;
	20.04) test $(update-alternatives --list gdm3-theme.gresources|wc -l) -gt 1 && { sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource >/dev/null && echo -e "Making new CSS alternative... \nDone !"; };;
esac

echo
echo "Restart your computer and enjoy :)"
echo "(you can delete the directory '${PWD}/${WORKDIR}')"

################################################################################

Avis aux testeurs. smile


«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#21 Le 05/05/2020, à 00:49

Roschan

Re : 20.04: Changement fond d'écran de lancement & de connexion

je connais pas la syntaxe en bash mais évite de faire des "case in" sans valeur par défaut

Hors ligne

#22 Le 08/05/2020, à 01:15

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Nouvelle version.

  • Prise en charge pour Ubuntu 18.04 20.04 et 20.10 avec vérification

  • Teste si fichier image est valide et passé en argument

  • Conversion du fichier image en PNG avant utilisation

#!/bin/bash

## Add personal background to gdm3 login screen
## Tested with Ubuntu 18.04, 20.04 and 20.10
## Requires : libglib2.0-dev-bin '(glib-compile-resources)' libxml2-utils '(xmllint)' imagemagick '(convert)'
## script version : 0.3

################################################################################
# Constants ####################################################################
UBUNTU_VERSION=$(lsb_release -rs)
SUPPORTED_VERSION="18.04 20.04 20.10"

GST=/usr/share/gnome-shell/gnome-shell-theme.gresource

WORKDIR=theme

BACKGROUND_TARGET_NAME=noise-texture.png
BACKGROUND_WIDTH=1920
BACKGROUND_HEIGHT=1080


ORIGINAL_BACKGROUND_20_10="#lockDialogGroup {\n  background-color: #41494c; }"
EDITED_BACKGROUND_20_10="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"
ORIGINAL_BACKGROUND_20_04="#lockDialogGroup {\n  background-color: #41494c; }"
EDITED_BACKGROUND_20_04="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"
ORIGINAL_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(resource:///org/gnome/shell/theme/noise-texture.png);\n  background-repeat: repeat; }"
EDITED_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"



################################################################################
# Functions ####################################################################


supported_ubuntu_version() {
	retVal=0
	for version in ${SUPPORTED_VERSION}; do 
		[ "${version}" == "${UBUNTU_VERSION}" ] && \
   	{ retVal=1 ; break; }
 	done
		[ $retVal -eq 0 ] && \
  	        { echo "Your Ubuntu version (${UBUNTU_VERSION}) is not supported !";
    	  	  echo;
    	  	  echo "Be sure to use Ubuntu 18.04 LTS, Ubuntu 20.04 LTS or Ubuntu 20.10.";
    	  	  exit 1; }
}


required_packages() {
	command -v xmllint glib-compile-resources convert &>/dev/null
		[[ $? -ne "0" ]] && \
 	{
   		echo "'libglib2.0-dev-bin', 'libxml2-utils' and 'imagemagick' packages must be installed to continue!"
   		echo
   		echo "You can copy/paste the following command in a terminal:" 
   		echo "sudo apt install libglib2.0-dev-bin libxml2-utils imagemagick"
   		exit 1
 	}
}


extract_current_theme() {
        for r in `gresource list "${GST}"`; do
                gresource extract "${GST}" "$r" > "${WORKDIR}"/"${r##*/}"
        done
}

create_new_gresource() {
	# Write a new "gnome-shell-theme.gresource.xml" file
	FILES=$(find "${WORKDIR}" -type f -printf "%P\n" | xargs -i echo "    <file>{}</file>")
	cat <<EOF >"${WORKDIR}/gnome-shell-theme.gresource.xml"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gnome/shell/theme">
${FILES}
  </gresource>
</gresources>
EOF

	# Compile this XML file into a new gresource file
		echo "Compiling gnome-shell-theme.gresource..."
	cd "${WORKDIR}"
	glib-compile-resources gnome-shell-theme.gresource.xml
		echo "The file 'gnome-shell-theme.gresource' has been successfully created!"
		echo
	cd ..
}


edit_css_content() {
	if test -f "${WORKDIR}"/gnome-shell.css; then
		css_file=gnome-shell.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_18_04}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_18_04}"
	elif test -f "${WORKDIR}"/gdm3.css; then
		css_file=gdm3.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_20_04}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_20_04}"
	elif test -f "${WORKDIR}"/gdm3.css; then
		css_file=gdm3.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_20_10}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_20_10}"
	else
		echo "No css file found!"
		exit 1
	fi

	# Apply customization to the .css file
		sed -i -z "s%${ORIGINAL_BACKGROUND}%${EDITED_BACKGROUND}%" "theme/${css_file}"
}


install_new_theme() {
	# Copy your background file to /usr/share/gnome-shell/theme
		echo "Copy your background file to /usr/share/gnome-shell/theme"
		sudo cp "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}" /usr/share/gnome-shell/theme/"${BACKGROUND_TARGET_NAME}"
		echo "Done !"
		echo
	# Make a backup of 'gnome-shell-theme.gresource' file to be able to restore in case of problem
	# or install a new gdm3 background 
		echo "Saving original 'gnome-shell-theme.gresource' to 'gnome-shell-theme.gresource.backup'"
	if test -f "${GST}".backup; then
		sudo cp "${GST}".backup "${GST}"
		echo "Done !" 
	else
		sudo cp "${GST}"{,.backup}
		echo "Done !"
		echo
	fi
	# Now, copy your custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell
		echo "Copy your custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell"
		sudo cp "${WORKDIR}"/gnome-shell-theme.gresource /usr/share/gnome-shell
		echo "Done !"
		echo
}


apply_new_alternative_gresource() {
	if [[ "${UBUNTU_VERSION}" =~ "18.04" ]]; then
		sudo update-alternatives --set gdm3.css /usr/share/gnome-shell/theme/gnome-shell.css
		echo -e "Making new CSS alternative... \n\nDone !"
		echo
	elif [[ "${UBUNTU_VERSION}" =~ "20.04" ]]; then
		sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource
		echo -e "Making new CSS alternative... \nDone !"
		echo
	elif [[ "${UBUNTU_VERSION}" =~ "20.10" ]]; then
		sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource
		echo -e "Making new CSS alternative... \nDone !"
		echo
	fi
}


help() {
       	echo "You must selected your background file to continue..."
       	echo "-----------------------------------------"
       	echo "Usage : ./`basename $0` /path/to/my/picture/file"
       	echo
}


################################################################################
# "Main" part of the script ####################################################

# Checking if the picture is argument to the script
if [[ "${#1}" -eq "0" ]]; then
  help
  exit 1
fi

supported_ubuntu_version
required_packages

# Create working directory 'theme'
# Checking of file format validity
# If needed, converting other picture format to PNG and copy file as 'noise-texture.png' to working directory 'theme'
# 
test -d "${WORKDIR}" && \
  	{
	      echo "'theme' directory already exist !"
	      echo "Delete or rename it to continue."
  	      exit 1
  	} || \
case "$(mimetype -b $1)" in
  image/png*) mkdir -p "${WORKDIR}"
  	      extract_current_theme
  	      cp -vf $1 "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}"
	      ;;
     image/*) mkdir -p "${WORKDIR}"
     	      extract_current_theme
     	      convert $1 "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}" &>/dev/null
	      echo "'$1' -> '${WORKDIR}/${BACKGROUND_TARGET_NAME}'"
	      ;;
           *) echo "$1 is not a valid format picture !"
              exit 1
	      ;;
esac

edit_css_content
create_new_gresource


echo
echo "####################################################"
echo "# The next operations require superuser privileges #"
echo "####################################################"

install_new_theme
apply_new_alternative_gresource

echo
echo "Restart your computer and enjoy :)"
echo "(you can delete the directory '${PWD}/${WORKDIR}')"

################################################################################

«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#23 Le 10/05/2020, à 20:40

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Nouvelle version

  • Passage des [ Hauteur x Largeur ] de l'image en arguments (optionnels)

  • Passage du fichier image en argument obligatoire

  • Aide

#!/bin/bash

## Add custom background to gdm3 login screen
## Tested with Ubuntu 18.04, 20.04 and 20.10
## Requires : libglib2.0-dev-bin '(glib-compile-resources)' libxml2-utils '(xmllint)' imagemagick '(convert)'
## Script version : 0.9

################################################################################
# Constants ####################################################################
UBUNTU_VERSION=$(lsb_release -rs)
SUPPORTED_VERSION="18.04 20.04 20.10"

GST=/usr/share/gnome-shell/gnome-shell-theme.gresource

WORKDIR=theme

BACKGROUND_TARGET_NAME=noise-texture.png
BACKGROUND_FILE=""
VERBOSE=0

ORIGINAL_BACKGROUND_20_10="#lockDialogGroup {\n  background-color: #41494c; }"
EDITED_BACKGROUND_20_10="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"
ORIGINAL_BACKGROUND_20_04="#lockDialogGroup {\n  background-color: #41494c; }"
EDITED_BACKGROUND_20_04="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"
ORIGINAL_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(resource:///org/gnome/shell/theme/noise-texture.png);\n  background-repeat: repeat; }"
EDITED_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"



################################################################################
# Functions ####################################################################


supported_version() {
    echo $SUPPORTED_VERSION | \
    grep -w $UBUNTU_VERSION >/dev/null || { \
    echo "Your Ubuntu version (${UBUNTU_VERSION}) is not supported !"
    echo
    echo "Be sure to use Ubuntu 18.04 LTS, Ubuntu 20.04 LTS or Ubuntu 20.10."
    exit 1;
    }
}


required_packages() {
	command -v xmllint glib-compile-resources convert &>/dev/null
		[[ $? -ne "0" ]] && \
		{
   		echo "'libglib2.0-dev-bin', 'libxml2-utils' and 'imagemagick' packages must be installed to continue!"
   		echo
   		echo "You can copy/paste the following command in a terminal:" 
   		echo "sudo apt install libglib2.0-dev-bin libxml2-utils imagemagick"
   		exit 1
   		}
}


create_working_directory_theme() {
	# Create working directory 'theme'
	test -d "${WORKDIR}" && \
		{
		echo "'theme' directory already exist !"
		echo "Delete or rename it to continue."
	  	exit 1; } || \
	# Checking of file format validity
	# If needed, converting other picture format to PNG and copy as 'noise-texture.png' filename to working directory 'theme'
	case $(mimetype -b ${BACKGROUND_FILE}) in
       image/png*) mkdir -p "${WORKDIR}"
	  	extract_current_theme
	  	cp -vf ${BACKGROUND_FILE} "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}"
		;;
       image/*) mkdir -p "${WORKDIR}"
      	        extract_current_theme
	     	convert ${BACKGROUND_FILE} "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}" &>/dev/null
		echo "'${BACKGROUND_FILE}' -> '${WORKDIR}/${BACKGROUND_TARGET_NAME}'"
		;;
	     *) echo "${BACKGROUND_FILE} is not a valid format picture !"
	        exit 1
		;;
	esac
}

extract_current_theme() {
        for r in `gresource list "${GST}"`; do
                gresource extract "${GST}" "$r" > "${WORKDIR}"/"${r##*/}"
        done
}

create_new_gresource() {
	# Write a new "gnome-shell-theme.gresource.xml" file
	FILES=$(find "${WORKDIR}" -type f -printf "%P\n" | xargs -i echo "    <file>{}</file>")
	cat <<EOF >"${WORKDIR}/gnome-shell-theme.gresource.xml"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gnome/shell/theme">
${FILES}
  </gresource>
</gresources>
EOF

	# Compile this XML file into a new gresource file
		echo "Compiling gnome-shell-theme.gresource..."
	cd "${WORKDIR}"
	glib-compile-resources gnome-shell-theme.gresource.xml
		echo "The file 'gnome-shell-theme.gresource' has been successfully created!"
		echo
	cd ..
}


edit_css_content() {
	if test -f "${WORKDIR}"/gnome-shell.css; then
		css_file=gnome-shell.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_18_04}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_18_04}"
	elif test -f "${WORKDIR}"/gdm3.css; then
		css_file=gdm3.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_20_04}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_20_04}"
	elif test -f "${WORKDIR}"/gdm3.css; then
		css_file=gdm3.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_20_10}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_20_10}"
	else
		echo "No css file found!"
		exit 1
	fi

	# Apply customization to the .css file
		sed -i -z "s%${ORIGINAL_BACKGROUND}%${EDITED_BACKGROUND}%" "theme/${css_file}"
}


install_new_theme() {
	# Copy your background file to /usr/share/gnome-shell/theme
		echo "Copy your background file to /usr/share/gnome-shell/theme"
		sudo cp "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}" /usr/share/gnome-shell/theme/"${BACKGROUND_TARGET_NAME}"
		echo "Done !"
		echo
	# Make a backup of 'gnome-shell-theme.gresource' file to be able to restore in case of problem
	# or install a new gdm3 background 
		echo "Saving original 'gnome-shell-theme.gresource' to 'gnome-shell-theme.gresource.backup'"
	if test -f "${GST}".backup; then
		sudo cp "${GST}".backup "${GST}"
		echo "Done !" 
	else
		sudo cp "${GST}"{,.backup}
		echo "Done !"
		echo
	fi
	# Now, copy your custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell
		echo "Copy your custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell"
		sudo cp "${WORKDIR}"/gnome-shell-theme.gresource /usr/share/gnome-shell
		echo "Done !"
		echo
}


apply_new_alternative_gresource() {
	if [[ "${UBUNTU_VERSION}" =~ "18.04" ]]; then
		sudo update-alternatives --set gdm3.css /usr/share/gnome-shell/theme/gnome-shell.css
		echo -e "Making new CSS alternative... \n\nDone !"
		echo
	elif [[ "${UBUNTU_VERSION}" =~ "20.04" ]]; then
		sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource
		echo -e "Making new CSS alternative... \nDone !"
		echo
	elif [[ "${UBUNTU_VERSION}" =~ "20.10" ]]; then
		sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource
		echo -e "Making new CSS alternative... \nDone !"
		echo
	fi
}


usage() {
   cat << EOF
Usage: $0 [ -f, --file "/path/to/my/picture" ]  [ -w, --width "PICTURE_WIDTH" ] [ -h, --height "PICTURE_HEIGHT" ]

Required argument:
  -f, --file                       background picture file

Optional arguments:
  -w, --width                      width value in pixel (default value is the picture size)
  -h, --height                     height value in pixel (default value is the picture size)
  -v, --verbose                    increase verbosity
  
Help:
      --help                       show help  
EOF
}


################################################################################
# "Main" part of the script ####################################################

# If no arg then exit
if [ $# -eq "0" ]; then
  echo "No argument found !"
  echo
  echo "Type '$0 --help' for details."
  exit 1
fi

# Handling arguments
while [ $# -gt 0 ]; do 
  case "$1" in
--help) usage; exit ;;
    -w|--width) if [ -z $2 ]; then echo "Set the wished width of your background file"; exit 1; elif ! [[ "$2" == ?(-)+([0-9.]) ]]; then echo "Width must be a number!"; exit 1; else BACKGROUND_WIDTH="$2"; shift; fi ;;
    -h|--height) if [ -z $2 ]; then echo "Set the wished height of your background file"; exit 1; elif ! [[ "$2" == ?(-)+([0-9.]) ]]; then echo "Height must be a number!"; exit 1; else BACKGROUND_HEIGHT="$2"; shift; fi ;;
    -f|--file) if [ -z $2 ]; then echo "Select your background file to continue"; exit 1; elif ! test "$(file -b $2| grep -oi 'image')"; then echo "The background file must be a valid picture format!"; exit 1; else BACKGROUND_FILE="$2"; shift; fi ;;
    -v|--verbose) VERBOSE=$((VERBOSE + 1)) ;;
     *) echo "Unknown option"; exit ;;
  esac
 shift
done

# Default wallpaper size if no defined
     [ -z $BACKGROUND_WIDTH ] && { BACKGROUND_WIDTH=$(identify -format "%w\n" $BACKGROUND_FILE); }
     [ -z $BACKGROUND_HEIGHT ] && { BACKGROUND_HEIGHT=$(identify -format "%h\n" $BACKGROUND_FILE); }

# verbose mode, if set
(( $VERBOSE > 0 )) &&
      cat <<-EOF
      
     Wallpaper is '${BACKGROUND_FILE##*/}'
     Resolution is '${BACKGROUND_WIDTH}x${BACKGROUND_HEIGHT}'
     
EOF

# Let's make the background file is set to continue
[ "${BACKGROUND_FILE}" = "" ] && \
      {
      echo "The background file must be select to continue!"
      exit 1
      }

supported_version
required_packages
create_working_directory_theme
edit_css_content
create_new_gresource


echo
echo "####################################################"
echo "# The next operations require superuser privileges #"
echo "####################################################"

install_new_theme
apply_new_alternative_gresource

echo
echo "Restart your computer and enjoy :)"
echo "(you can delete the directory '${PWD}/${WORKDIR}')"

################################################################################

«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#24 Le 13/05/2020, à 01:42

lynn

Re : 20.04: Changement fond d'écran de lancement & de connexion

Nouvelle version :

  • Correction de la fonction de vérification des paquets requis

  • Ajout d'une option (-r) pour supprimer un précédent répertoire de travail

  • Ajout d'une option (-d) pour supprimer le répertoire de travail après utilisation

  • Corrections mineures

#!/bin/bash

## Add custom background to gdm3 login screen
## Tested with Ubuntu 18.04, 20.04 and 20.10
## Requires : libglib2.0-dev-bin '(glib-compile-resources)' libxml2-utils '(xmllint)' imagemagick '(convert)'
## Script version : 0.9

################################################################################
# Constants ####################################################################
UBUNTU_VERSION=$(lsb_release -rs)
SUPPORTED_VERSION="18.04 20.04 20.10"
REQUIRED_PACKAGES="xmllint glib-compile-resources convert"
GST=/usr/share/gnome-shell/gnome-shell-theme.gresource

WORKDIR=theme
BACKGROUND_WIDTH=1280
BACKGROUND_HEIGHT=768
BACKGROUND_TARGET_NAME=noise-texture.png
BACKGROUND_FILE=""
VERBOSE=0

ORIGINAL_BACKGROUND_20_10="#lockDialogGroup {\n  background-color: #41494c; }"
EDITED_BACKGROUND_20_10="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"
ORIGINAL_BACKGROUND_20_04="#lockDialogGroup {\n  background-color: #41494c; }"
EDITED_BACKGROUND_20_04="#lockDialogGroup {\n  background: #41494c url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"
ORIGINAL_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(resource:///org/gnome/shell/theme/noise-texture.png);\n  background-repeat: repeat; }"
EDITED_BACKGROUND_18_04="#lockDialogGroup {\n  background: #2e3436 url(file:///usr/share/gnome-shell/theme/${BACKGROUND_TARGET_NAME});\n  background-size: ${BACKGROUND_WIDTH}px ${BACKGROUND_HEIGHT}px;\n  background-repeat: none;\n}"



################################################################################
# Functions ####################################################################


supported_version() {
   		echo $SUPPORTED_VERSION | \
    		grep -w $UBUNTU_VERSION >/dev/null || { \
    		echo "Your Ubuntu version (${UBUNTU_VERSION}) is not supported!"
   		echo
    		echo "Make sure to use Ubuntu 18.04 LTS, Ubuntu 20.04 LTS or Ubuntu 20.10."
    		exit 1;
    		}
}


required_packages() {
	[[ $(command -v ${REQUIRED_PACKAGES} | wc -l) -lt 3 ]] && {
		echo "==> Make sure these packages are installed to continue:"
		echo "--> libglib2.0-dev-bin"
		echo "--> libxml2-utils"
		echo "--> imagemagick"
		echo
		echo "==> You can copy/paste the following command into your terminal:" 
		echo "sudo apt install libglib2.0-dev-bin libxml2-utils imagemagick"
		exit 1;
		}
}


working_directory_theme() {
	# Check working directory 'theme'
	if [ -d "${PWD}/${WORKDIR}" ] && [ "${REMOVE_PREVIOUS_DIR_THEME}" = YES ]; then
		rm -rf ${PWD}/${WORKDIR}
		echo "--> An existing working directory has been removed successfully."
		echo

	elif [ -d "${PWD}/${WORKDIR}" ]; then
		# Delete or rename previous working directory manually before proceed
		echo "==> A working '${WORKDIR}' directory already exist !"
		echo "Use '-r' option to remove it or delete it manually to continue."
		exit
	fi
}


background_status() {
	# Let's make the background file is set to continue
		[ "${BACKGROUND_FILE}" = "" ] && \
      		{
      		echo "==> The background file must be select to continue!"
      		exit 1
      		}
	# Checking of file format validity
	# If needed, converting other picture format to PNG and copy as 'noise-texture.png' filename to working directory 'theme'
	case $(mimetype -b ${BACKGROUND_FILE}) in
       		image/png*) mkdir -p "${WORKDIR}"
	 	extract_current_theme
	 	cp -f ${BACKGROUND_FILE} "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}"
		echo "Your background file ${BACKGROUND_FILE##*/} has been copied to working directory ${WORKDIR} as ${BACKGROUND_TARGET_NAME}."
		echo
		;;
       		image/*) mkdir -p "${WORKDIR}"
      	       	extract_current_theme
		echo "Convert in progress..."
	     	convert ${BACKGROUND_FILE} "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}" 2>&1 >/dev/null
		echo "--> Done!"
		echo
		echo "Your background file ${BACKGROUND_FILE##*/} has been converted and copied to working directory ${WORKDIR} as ${BACKGROUND_TARGET_NAME.}"
		echo
		;;
	     	*) echo "${BACKGROUND_FILE} is not a valid format picture!"
	       	exit 1
		;;
	esac
}

extract_current_theme() {
        for r in `gresource list "${GST}"`; do
                gresource extract "${GST}" "$r" > "${WORKDIR}"/"${r##*/}"
        done
}

create_new_gresource() {
	# Write a new "gnome-shell-theme.gresource.xml" file
	FILES=$(find "${WORKDIR}" -type f -printf "%P\n" | xargs -i echo "    <file>{}</file>")
	cat <<EOF >"${WORKDIR}/gnome-shell-theme.gresource.xml"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gnome/shell/theme">
${FILES}
  </gresource>
</gresources>
EOF

	# Compile this XML file into a new gresource file
		echo "Compiling gnome-shell-theme.gresource..."
	cd "${WORKDIR}"
	glib-compile-resources gnome-shell-theme.gresource.xml
		echo "--> The file 'gnome-shell-theme.gresource' has been successfully created!"
		echo
	cd ..
}


edit_css_content() {
	if test -f "${WORKDIR}"/gnome-shell.css; then
		css_file=gnome-shell.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_18_04}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_18_04}"
	elif test -f "${WORKDIR}"/gdm3.css; then
		css_file=gdm3.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_20_04}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_20_04}"
	elif test -f "${WORKDIR}"/gdm3.css; then
		css_file=gdm3.css
		ORIGINAL_BACKGROUND="${ORIGINAL_BACKGROUND_20_10}"
		EDITED_BACKGROUND="${EDITED_BACKGROUND_20_10}"
	else
		echo "==> No css file found!"
		exit 1
	fi

	# Apply customization to the .css file
		sed -i -z "s%${ORIGINAL_BACKGROUND}%${EDITED_BACKGROUND}%" "${WORKDIR}/${css_file}"
}


install_new_theme() {
	# Copy your background file to /usr/share/gnome-shell/theme
		echo
		echo "Copy your background file to /usr/share/gnome-shell/theme"
		sudo cp "${WORKDIR}"/"${BACKGROUND_TARGET_NAME}" /usr/share/gnome-shell/theme/"${BACKGROUND_TARGET_NAME}"
		echo "--> Done !"
		echo
	# Make sure to create a backup of original 'gnome-shell-theme.gresource' file to be able to restore in case of problem...
	# If a backup file exist, copy 'gnome-shell-theme.gresource.backup' to 'gnome-shell-theme.gresource'
		echo "Saving original 'gnome-shell-theme.gresource' to 'gnome-shell-theme.gresource.backup'"
	if test -f "${GST}".backup; then
		sudo cp "${GST}".backup "${GST}"
		echo "--> Done !" 
	else
	# If 'gnome-shell-theme.gresource.backup' does not exist, copy 'gnome-shell-theme.gresource' to 'gnome-shell-theme.gresource.backup'
		sudo cp "${GST}"{,.backup}
		echo "--> Done !"
		echo
	fi
	# Now, copy your custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell
		echo
		echo "Copy your custom 'gnome-shell-theme.gresource' to /usr/share/gnome-shell"
		sudo cp "${WORKDIR}"/gnome-shell-theme.gresource /usr/share/gnome-shell
		echo "--> Done !"
		echo
}


apply_new_alternative_gresource() {
	if [[ "${UBUNTU_VERSION}" =~ "18.04" ]]; then
		sudo update-alternatives --set gdm3.css /usr/share/gnome-shell/theme/ubuntu.css
		echo -e "Making new CSS alternative... \n--> Done !"
		echo
	elif [[ "${UBUNTU_VERSION}" =~ "20.04" ]]; then
		sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource
		echo -e "Making new CSS alternative... \n--> Done !"
		echo
	elif [[ "${UBUNTU_VERSION}" =~ "20.10" ]]; then
		sudo update-alternatives --set gdm3-theme.gresource /usr/share/gnome-shell/gnome-shell-theme.gresource
		echo -e "Making new CSS alternative... \n--> Done !"
		echo
	fi
}


usage() {
	cat << EOF
Usage: $0 [ -f, --file "/path/to/my/picture.{png,jpeg,jpg,etc}" ]  [ -w, --width "PICTURE_WIDTH" ] [ -h, --height "PICTURE_HEIGHT" ] 

Required argument:
  -f, --file                       Background picture file

Optional arguments:
  -r, --remove			   Remove previous existing '$WORKDIR' directory 
  -d, --delete			   Delete working directory '$WORKDIR' after install
  -w, --width                      Width value in pixel (default value is the picture size)
  -h, --height                     Height value in pixel (default value is the picture size)
  -v, --verbose                    Increase verbosity
  
Help:
      --help                       Show this help  
EOF
}


verbose_mode() {
# verbose mode, if set
(( $VERBOSE > 0 )) &&
      cat <<-EOF

Preview settings:
   
  Wallpaper is '${BACKGROUND_FILE##*/}'
  Resolution is '${BACKGROUND_WIDTH}x${BACKGROUND_HEIGHT}'
     
EOF
}

delete_workdir_after_install() {
# Delete working directory after install 
	if [[ "${DELETE_DIR_THEME_AFTER_INSTALL}" = "YES" ]]; then
		rm -rf ${PWD}/${WORKDIR}
		echo
		echo "--> The working directory has been removed successfully."
		echo
	fi
}


################################################################################
# "Main" part of the script ####################################################

supported_version
required_packages

# If no arg then exit
	if [ $# -eq "0" ]; then
  		echo "==> No argument found!"
  		echo
  		echo "Type '$0 --help' for details."
  		exit 1
	fi

# Handling arguments
while [ $# -gt 0 ]; do 
  case "$1" in
--help) usage; exit ;;
    -r|--remove) REMOVE_PREVIOUS_DIR_THEME=YES ;;
    -d|--delete) DELETE_DIR_THEME_AFTER_INSTALL=YES ;;
    -w|--width) if [ -z $2 ]; then echo "Set the wished width of your background file"; exit 1; elif ! [[ "$2" == ?(-)+([0-9.]) ]]; then echo "Width must be a number!"; exit 1; else BACKGROUND_WIDTH="$2"; shift; fi ;;
    -h|--height) if [ -z $2 ]; then echo "Set the wished height of your background file"; exit 1; elif ! [[ "$2" == ?(-)+([0-9.]) ]]; then echo "Height must be a number!"; exit 1; else BACKGROUND_HEIGHT="$2"; shift; fi ;;
    -f|--file) if [ -z $2 ]; then echo "Select your background file to continue"; exit 1; elif ! test "$(file -b $2| grep -oi 'image')"; then echo "The background file must be a valid picture format!"; exit 1; else BACKGROUND_FILE="$2"; shift; fi ;;
    -v|--verbose) VERBOSE=$((VERBOSE + 1)) ;;
     *) echo "Unknown option"; exit ;;
  esac
 shift
done

verbose_mode
working_directory_theme
background_status
edit_css_content
create_new_gresource


echo "####################################################"
echo "# The next operations require superuser privileges #"
echo "#                                                  #" 
install_new_theme 
apply_new_alternative_gresource
echo "#                                                  #"
echo "#             End superuser operations             #"
echo "####################################################"

delete_workdir_after_install

echo
echo "### Restart your computer and enjoy :) ###"
echo

################################################################################

«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»

Coluche

Hors ligne

#25 Le 13/05/2020, à 16:23

heliofff

Re : 20.04: Changement fond d'écran de lancement & de connexion

Hors ligne