forked from thiggy01/ubuntu-change-gdm-background
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand-wallpaper
executable file
·165 lines (134 loc) · 4.63 KB
/
rand-wallpaper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
# Authors: Gabriel Theuws
# Translate : Gabriel Theuws
# Contact: [email protected]
# Contact: [email protected]
# URL origin: https://github.com/thiggy01/ubuntu-20.04-change-gdm-background
# URL translation: https://github.com/Amiralgaby/ubuntu-change-gdm-background
# =================================================================== #
usage () {
cat << EOF
Utilisation avec privilège administrateur:
$0 [OPTIONS]
OPTIONS :
--cache-filigrane - Cache le logo Ubuntu sur l'écran de connexion
et par la même occasion celui du boot
--restore - Restaure l'ancien thème
EOF
}
[ "$1" == "-h" ] && usage && exit 0
# Check if script is run by root.
if [ "$(id -u)" -ne 0 ] ; then
echo 'Ce script doit être exécuté en tant que root ou avec la commande sudo.' >&2
usage
exit 1
fi
[ -f /etc/os-release ] && . /etc/os-release
# Check what linux distro is being used.
if ! [[ "$VERSION_CODENAME" =~ (focal|groovy) ]]; then
echo "Désolé, ce script ne fonctionne qu'avec des distros focal ou groovy." >&2
exit 1
fi
# Check if glib 2.0 development libraries are installed.
command -v glib-compile-resources >/dev/null 2>&1 || {
echo "La commande glib-compile-resources n'a pas été trouvée" >&2
echo "Ce script ne peut pas fonctionner sans les bibliothèques nécessaires" >&2
exit 1
}
# Assign the default gdm theme file path.
if [ "$NAME" == 'Ubuntu' ]; then
gdm3Resource=/usr/share/gnome-shell/theme/Yaru/gnome-shell-theme.gresource
elif [ "$NAME" == 'Pop' ]; then
gdm3Resource=/usr/share/gnome-shell/theme/Pop/gnome-shell-theme.gresource
fi
# Create a backup file of the original theme if there isn't one.
[ ! -f "$gdm3Resource"~ ] && cp "$gdm3Resource" "$gdm3Resource~"
# Restore backup function.
restore () {
if mv "$gdm3Resource~" "$gdm3Resource"; then
chmod 644 "$gdm3Resource"
echo 'Le fond GDM a été restauré avec succès.'
exit 0
fi
}
# Restore the original gdm3 theme.
[ "$1" == "--restore" ] && restore
#Define main variables.
gdm3xml=${gdm3Resource##*/}.xml
workDir="/tmp/gdm3-theme"
# Create directories from resource list.
CreateDirs() {
for resource in $(gresource list "$gdm3Resource~"); do
resource="${resource#\/org\/gnome\/shell\/}"
if [ ! -d "$workDir"/"${resource%/*}" ]; then
mkdir -p "$workDir"/"${resource%/*}"
fi
done
}
# Extract resources from binary file.
ExtractRes() {
for resource in $(gresource list "$gdm3Resource~"); do
gresource extract "$gdm3Resource~" "$resource" > \
"$workDir"/"${resource#\/org\/gnome\/shell\/}"
done
}
# Compile resources into a gresource binary file.
CompileMoveRes() {
glib-compile-resources --sourcedir=$workDir/theme/ $workDir/theme/"$gdm3xml"
# Move the generated binary file to the gnome-shell folder.
if mv $workDir/theme/gnome-shell-theme.gresource $gdm3Resource; then
# Solve a permission change issue (thanks to @huepf from github).
chmod 644 "$gdm3Resource"
echo "L'arrière-plan de l'écran de connexion a changé avec succès."
else
# If something went wrong, restore backup file.
echo "quelque chose s'est mal passé." >&2
restore
echo "Aucun changement n'a été appliqué" >&2
fi
# Remove temporary directories and files.
rm -r "$workDir"
exit 0
}
runApp() {
# Define image variables.
imgFile="${1##*/}"
# Call procedures to create directories and extract resources to them.
ExtractRes
# Change gdm background to the image you submited.
oldBg="#lockDialogGroup \{.*?\}"
newBg="#lockDialogGroup {
background: url('resource:\/\/\/org\/gnome\/shell\/theme\/$imgFile');
background-size: cover; }"
perl -i -0777 -pe "s/$oldBg/$newBg/s" "$workDir"/theme/gdm3.css
filesXML=""
for file in $(gresource list "$gdm3Resource~"); do
filesXML="$filesXML
<file>${file#\/org\/gnome/shell\/theme\/}</file>"
done
filesXML="$filesXML
<file>$imgFile</file>"
pathXML=""$workDir"/theme/"$gdm3xml""
# Generate gresource xml file.
cat <<EOF > "$pathXML"
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/shell/theme">
$filesXML
</gresource>
</gresources>
EOF
# Compile and move gresource.
CompileMoveRes
}
CreateDirs
PATH_TO_IMG="$workDir"/theme/image
if nc -zw1 picsum.photos 443
then
echo "Connexion active"
wget --no-verbose https://picsum.photos/1600/900 -6 -O "$PATH_TO_IMG"
else
echo "Problème pour se connecter" >&2
exit 1
fi
[ -f "$PATH_TO_IMG" ] && runApp "$PATH_TO_IMG" || echo "Le fichier \"$PATH_TO_IMG\" n'a pas été trouvé"