-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
290 lines (234 loc) · 9.83 KB
/
main.sh
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/usr/bin/env bash
# Autor: Giotto88, Github Copilot
# Version: 0.1
# Script per la modifica del tema di GDM3
#
# Fork originale: https://github.com/thiggy01/change-gdm-background
# =================================================================== #
# --------------------- FUNCIONS -------------------------
# 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.
CompileRes() {
glib-compile-resources --sourcedir=$workDir/theme/ $workDir/theme/"$gdm3xml"
}
# Moves the newly created resource to its default place.
MoveRes() {
sudo -i mv $workDir/theme/gnome-shell-theme.gresource $gdm3Resource
}
# Check if gresource was sucessfuly moved to its default folder.
Check() {
if [ "$?" -eq 0 ]; then
# If everything went well, remove backup file.
# rm "$gdm3Resource~"
# echo 'Changes applied successfully.'
echo -e '\nModifiche caricate con successo.\nRiavviare il servizio GDM per applicare le modifiche.'
else
# If something went wrong, restore backup file.
echo 'qualcosa è andato storto.'
read -p "Ripristinare backup? (Y/N): " response
response=$(echo "$response" | tr '[:lower:]' '[:upper:]')
if [[ "$response" == "Y" || "$response" == "YES" ]]; then
sudo -i mv "$gdm3Resource~" "$gdm3Resource"
[ $? -eq 1 ] && echo ">> Errore"
echo "YES"
else
echo "NO"
fi
echo 'Il backup non è stato ripristinato.'
fi
}
CleanUp() {
# Remove temporary directories and files.
rm -r "$workDir"
return $?
}
# --------------------- FUNCIONS -------------------------
# --------------------- VARIABLES -------------------------
# Assign the default gdm theme file path.
gdm3Resource=/usr/share/gnome-shell/theme/Yaru/gnome-shell-theme.gresource
gdm3xml=$(basename "$gdm3Resource").xml
workDir="/tmp/gdm3-theme"
# --------------------- VARIABLES -------------------------
# check if libglib2.0-dev is install in ubuntu
if ! dpkg -s libglib2.0-dev >/dev/null 2>&1; then
echo "libglib2.0-dev non installato"
echo "installazione in corso..."
sudo apt install libglib2.0-dev
fi
while true; do
echo " ______ _______ __ __ ________ _______ ______ ________ ______ _______ "
echo " / \| \| \ / \ | \ \| \ \/ \| \ "
echo "| ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\ ▓▓\ / ▓▓ | ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓\\▓▓▓▓▓▓\▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\ "
echo "| ▓▓ __\▓▓ ▓▓ | ▓▓ ▓▓▓\ / ▓▓▓ | ▓▓__ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓__| ▓▓ "
echo "| ▓▓| \ ▓▓ | ▓▓ ▓▓▓▓\ ▓▓▓▓ | ▓▓ \ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓ ▓▓ "
echo "| ▓▓ \▓▓▓▓ ▓▓ | ▓▓ ▓▓\▓▓ ▓▓ ▓▓ | ▓▓▓▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓▓▓▓▓▓\ "
echo "| ▓▓__| ▓▓ ▓▓__/ ▓▓ ▓▓ \▓▓▓| ▓▓ | ▓▓_____| ▓▓__/ ▓▓_| ▓▓_ | ▓▓ | ▓▓__/ ▓▓ ▓▓ | ▓▓ "
echo " \▓▓ ▓▓ ▓▓ ▓▓ ▓▓ \▓ | ▓▓ | ▓▓ \ ▓▓ ▓▓ ▓▓ \ | ▓▓ \▓▓ ▓▓ ▓▓ | ▓▓ "
echo " \▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓ \▓▓ \▓▓▓▓▓▓▓▓\▓▓▓▓▓▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓ "
echo " "
echo -e "versione 0.1 \n\n"
echo -e "0\tEsci dal programma"
echo -e "STEP 1:\tPreparazione di file e cartelle"
echo -e "STEP 2:\tEstrazione dei file dal file binario"
echo -e "STEP 3:\tCompilazione del file"
echo -e "STEP 4:\tPulizia dei file non piu' necessari"
echo -e "STEP 5:\tRiavvio del servizio GDM"
echo ""
echo ""
# leggi il primo numero inserito da tastiera
read -p "Inserisci il numero della voce da eseguire: " -n 1 -r scelta
# --------------------------------------------------------- #
clear
#display environment variables
echo -e "GDM3 XML:\t $gdm3xml"
echo -e "GDM3 Resource:\t $gdm3Resource"
echo -e "Work Directory:\t $workDir \n\n"
case $scelta in
0)
exit 0
;;
1)
echo "STEP 1: Preparazione di file e cartelle"
echo ""
read -p "Cambiare le variabili d'ambiente? (Y/N): " response
if [[ "$response" == "Y" || "$response" == "YES" ]]; then
# Change the default gdm theme file path if the user provides one.
read -p "Inserisci il percorso del file gnome-shell-theme.gresource: " gdm3Resource
# Check if the file exists.
if [ ! -f "$gdm3Resource" ]; then
echo "Il file $gdm3Resource non esiste."
exit 1
fi
# Change the default Work Directory file path if the user provides one.
read -p "Inserisci il percorso della cartella di lavoro: " workDir
# Check if the file exists.
if [ ! -d "$workDir" ]; then
echo "La cartella $workDir non esiste."
exit 1
fi
echo "YES"
else
echo "NO"
fi
# create work directory
mkdir -p "$workDir"/theme
# Create a backup file of the original theme if there isn't one. [optional]
read -p "Creare un backup del file gnome-shell-theme.gresource? (Y/N): " response
# Convert the response to uppercase for case-insensitivity
response=$(echo "$response" | tr '[:lower:]' '[:upper:]')
# Check if the response is 'Y' or 'YES', and set the exit code accordingly
if [[ "$response" == "Y" || "$response" == "YES" ]]; then
[ ! -f "$gdm3Resource"~ ] && cp "$gdm3Resource" "$gdm3Resource~"
[ $? -eq 1 ] && echo ">> Errore"
echo "YES"
else
echo "NO"
fi
#clean file with .css in /usr/share/gnome-shell/theme/Yaru? [optional]
read -p "Pulire i file non utili di Yaru (css/svg)? (Y/N): " response
response=$(echo "$response" | tr '[:lower:]' '[:upper:]')
if [[ "$response" == "Y" || "$response" == "YES" ]]; then
sudo -i rm /usr/share/gnome-shell/theme/Yaru/*.css
sudo -i rm /usr/share/gnome-shell/theme/Yaru/*.svg
[ $? -eq 1 ] && echo ">> Errore"
echo "YES"
else
echo "NO"
fi
;;
2)
echo "STEP 2: Estrazione dei file dal file binario"
echo ""
# Call procedures to create directories and extract resources to them.
CreateDirs
ExtractRes
echo "GDM CSS: $workDir"/theme/gdm.css
read -p "Elencare i file in $workDir/theme? (Y/N): " response
response=$(echo "$response" | tr '[:lower:]' '[:upper:]')
if [[ "$response" == "Y" || "$response" == "YES" ]]; then
echo -e "$(ls -l -r "$workDir"/theme)\n"
[ $? -eq 1 ] && echo ">> Errore"
echo "YES"
else
echo "NO"
fi
echo "modificare ora i file css in $workDir/theme prima dello step 3"
;;
3)
echo "STEP 3: Compilazione del file"
echo ""
# Wait for user input to continue.
echo -e "[1/3] Generazione del file xml"
read -p "Premi un tasto per continuare: " -n 1
# Generate gresource xml file.
echo '<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/shell/theme">' > "$workDir"/theme/"$gdm3xml"
for file in `gresource list "$gdm3Resource~"`; do
echo " <file>${file#\/org\/gnome/shell\/theme\/}</file>" \
>> "$workDir"/theme/"$gdm3xml"
done
#TODO: aggiungere file addizionali come immagini, etcetera
#echo " <file>$imgFile</file>" >> "$workDir"/theme/"$gdm3xml"
echo ' </gresource>
</gresources>' >> "$workDir"/theme/"$gdm3xml"
# Wait for user input to continue.
echo -e "\n[2/3] Compilazione della nuova risorsa"
read -p "Premi un tasto per continuare: " -n 1
CompileRes
echo -e "\n[3/3] Collocazione della nuova risorsa"
read -p "Premi un tasto per continuare: " -n 1
MoveRes
# Check if everything was successful.
Check
;;
4)
echo "STEP 4: Pulizia dei file non piu' necessari"
echo ""
# Remove temporary files and exit.
read -p "Vuoi pulire i file temporanei in $workDir? (Y/N): " response
response=$(echo "$response" | tr '[:lower:]' '[:upper:]')
if [[ "$response" == "Y" || "$response" == "YES" ]]; then
CleanUp
[ $? -eq 1 ] && echo ">> Errore"
echo "YES"
else
echo "NO"
fi
;;
5)
echo "STEP 5: Riavvio del servizio GDM"
echo ""
# Solve a permission change issue (thanks to @huepf from github).
chmod 644 "$gdm3Resource"
echo 'GDM background sucessfully changed.'
read -p 'Do you want to restart gdm to apply change? (y/n):' -n 1
echo
# If change was successful apply ask for gdm restart.
if [[ "$REPLY" =~ ^[yY]$ ]]; then
service gdm restart
else
echo "Change will be applied only after restarting gdm"
echo
fi
;;
*)
echo "voce non valida"
;;
esac
done