A fork of the Materia GTK theme.

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 install.sh

View raw Download
text/x-shellscript • 10.19 kiB
Bourne-Again shell script, ASCII text executable
        
            
1
#!/bin/bash
2
set -ueo pipefail
3
#set -x
4
5
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
6
SRC_DIR="$REPO_DIR/src"
7
8
DEST_DIR="/usr/share/themes"
9
THEME_NAME="Materia"
10
COLOR_VARIANTS=('' '-dark' '-light')
11
SIZE_VARIANTS=('' '-compact')
12
13
# Set a proper gtk4 theme version
14
if [[ -z "${GTK4_VERSION:-}" ]]; then
15
if [[ "$(command -v gtk4-launch)" ]]; then
16
GTK4_FULL_VERSION="$(gtk4-launch --version)"
17
GTK4_MAJOR_VERSION="$(echo "$GTK4_FULL_VERSION" | cut -d . -f 1)"
18
GTK4_MINOR_VERSION="$(echo "$GTK4_FULL_VERSION" | cut -d . -f 2)"
19
20
if (( "$GTK4_MINOR_VERSION" % 2 == 0 )); then
21
GTK4_VERSION="$GTK4_MAJOR_VERSION.$GTK4_MINOR_VERSION"
22
else
23
GTK4_VERSION="$GTK4_MAJOR_VERSION.$((GTK4_MINOR_VERSION + 1))"
24
fi
25
else
26
echo "'gtk4-launch' not found, using styles for last gtk4 version available."
27
GTK4_VERSION="4.0"
28
fi
29
fi
30
31
# Set a proper gnome-shell theme version
32
if [[ -z "${GS_VERSION:-}" ]]; then
33
if [[ "$(command -v gnome-shell)" ]]; then
34
GS_FULL_VERSION="$(gnome-shell --version | rev | cut -d ' ' -f 1 | rev)"
35
GS_MAJOR_VERSION="$(echo "$GS_FULL_VERSION" | cut -d . -f 1)"
36
GS_MINOR_VERSION="$(echo "$GS_FULL_VERSION" | cut -d . -f 2)"
37
38
if (( "$GS_MAJOR_VERSION" >= 40 )); then
39
GS_VERSION="$GS_MAJOR_VERSION"
40
elif (( "$GS_MINOR_VERSION" % 2 == 0 )); then
41
GS_VERSION="$GS_MAJOR_VERSION.$GS_MINOR_VERSION"
42
else
43
GS_VERSION="$GS_MAJOR_VERSION.$((GS_MINOR_VERSION + 1))"
44
fi
45
else
46
echo "'gnome-shell' not found, using styles for last gnome-shell version available."
47
GS_VERSION="3.36"
48
fi
49
fi
50
51
if [[ ! "$(command -v sassc)" ]]; then
52
echo "'sassc' needs to be installed to generate the CSS."
53
exit 1
54
fi
55
56
SASSC_OPT=('-M' '-t' 'expanded')
57
58
usage() {
59
cat << EOF
60
Usage: $0 [OPTION]...
61
62
OPTIONS:
63
-d, --dest DIR Specify destination directory (Default: $DEST_DIR)
64
-n, --name NAME Specify theme name (Default: $THEME_NAME)
65
-c, --color VARIANT... Specify color variant(s) [standard|dark|light] (Default: All variants)
66
-s, --size VARIANT Specify size variant [standard|compact] (Default: All variants)
67
-g, --gdm Install and apply GDM theme (for advanced users)
68
See also: src/gnome-shell/README.md
69
-h, --help Show help
70
71
INSTALLATION EXAMPLES:
72
Install all theme variants into ~/.themes
73
$0 --dest ~/.themes
74
Install all theme variants including GDM theme
75
$0 --gdm
76
Install standard theme variant only
77
$0 --color standard --size standard
78
Install specific theme variants with different name into ~/.themes
79
$0 --dest ~/.themes --name MyTheme --color light dark --size compact
80
EOF
81
}
82
83
install_theme() {
84
local dest="$1"
85
local name="$2$3$4"
86
local color="$3"
87
local size="$4"
88
89
if [[ "$color" == '' ]]; then
90
local scss_dark_theme="false"
91
local scss_light_topbar="false"
92
elif [[ "$color" == '-light' ]]; then
93
local scss_dark_theme="false"
94
local scss_light_topbar="true"
95
elif [[ "$color" == '-dark' ]]; then
96
local scss_dark_theme="true"
97
local scss_light_topbar="false"
98
fi
99
100
if [[ "$size" == '' ]]; then
101
local scss_compact="false"
102
elif [[ "$size" == '-compact' ]]; then
103
local scss_compact="true"
104
fi
105
106
[[ "$color" == '-dark' ]] && local ELSE_DARK="$color"
107
[[ "$color" == '-light' ]] && local ELSE_LIGHT="$color"
108
109
local THEME_DIR="$dest/$name"
110
111
# SC2115: Protect /.
112
[[ -d "$THEME_DIR" ]] && rm -rf "${THEME_DIR:?}"
113
114
echo "Installing '$THEME_DIR'..."
115
116
#
117
# COPYING & index.theme
118
#
119
120
mkdir -p "$THEME_DIR"
121
cp \
122
"$REPO_DIR/COPYING" \
123
"$THEME_DIR"
124
sed \
125
-e "s|@theme_name@|$name|g" \
126
"$SRC_DIR/index.theme.in" > \
127
"$THEME_DIR/index.theme"
128
129
#
130
# Chrome extensions
131
#
132
133
mkdir -p "$THEME_DIR/chrome"
134
cp -T \
135
"$SRC_DIR/chrome/chrome-scrollbar${ELSE_DARK:-}.crx" \
136
"$THEME_DIR/chrome/chrome-scrollbar.crx"
137
cp -T \
138
"$SRC_DIR/chrome/chrome-theme$color.crx" \
139
"$THEME_DIR/chrome/chrome-theme.crx"
140
141
#
142
# Cinnamon
143
#
144
145
mkdir -p "$THEME_DIR/cinnamon"
146
cp -r \
147
"$SRC_DIR/cinnamon/assets" \
148
"$THEME_DIR/cinnamon"
149
cp \
150
"$SRC_DIR/cinnamon/thumbnail.png" \
151
"$THEME_DIR/cinnamon"
152
sed \
153
-e "s|@dark_theme@|$scss_dark_theme|g" \
154
-e "s|@light_topbar@|$scss_light_topbar|g" \
155
-e "s|@compact@|$scss_compact|g" \
156
-e "s|@current_source_dir@|$SRC_DIR/cinnamon|g" \
157
"$SRC_DIR/cinnamon/cinnamon.scss.in" | \
158
sassc --stdin "${SASSC_OPT[@]}" \
159
"$THEME_DIR/cinnamon/cinnamon.css"
160
161
#
162
# GNOME Shell
163
#
164
165
mkdir -p "$THEME_DIR/gnome-shell"
166
cp -r -T \
167
"$SRC_DIR/gnome-shell/assets${ELSE_DARK:-}" \
168
"$THEME_DIR/gnome-shell/assets"
169
cp -r \
170
"$SRC_DIR/gnome-shell/extensions" \
171
"$SRC_DIR/gnome-shell/icons" \
172
"$THEME_DIR/gnome-shell"
173
cp \
174
"$SRC_DIR/gnome-shell/README.md" \
175
"$SRC_DIR/gnome-shell/gnome-shell-theme.gresource.xml" \
176
"$SRC_DIR/gnome-shell/noise-texture.png" \
177
"$SRC_DIR/gnome-shell/pad-osd.css" \
178
"$SRC_DIR/gnome-shell/process-working.svg" \
179
"$THEME_DIR/gnome-shell"
180
sed \
181
-e "s|@dark_theme@|$scss_dark_theme|g" \
182
-e "s|@light_topbar@|$scss_light_topbar|g" \
183
-e "s|@compact@|$scss_compact|g" \
184
-e "s|@version@|$GS_VERSION|g" \
185
-e "s|@current_source_dir@|$SRC_DIR/gnome-shell|g" \
186
"$SRC_DIR/gnome-shell/gnome-shell.scss.in" | \
187
sassc --stdin "${SASSC_OPT[@]}" \
188
"$THEME_DIR/gnome-shell/gnome-shell.css"
189
190
#
191
# GTK 2
192
#
193
194
mkdir -p "$THEME_DIR/gtk-2.0"
195
cp -r -T \
196
"$SRC_DIR/gtk-2.0/assets${ELSE_DARK:-}" \
197
"$THEME_DIR/gtk-2.0/assets"
198
cp -T \
199
"$SRC_DIR/gtk-2.0/gtkrc$color" \
200
"$THEME_DIR/gtk-2.0/gtkrc"
201
cp \
202
"$SRC_DIR/gtk-2.0/apps.rc" \
203
"$SRC_DIR/gtk-2.0/hacks.rc" \
204
"$SRC_DIR/gtk-2.0/main.rc" \
205
"$THEME_DIR/gtk-2.0"
206
207
#
208
# GTK 3 & 4
209
#
210
211
local GTK_VARIANTS=('')
212
[[ "$color" != '-dark' ]] && local GTK_VARIANTS+=('-dark')
213
214
for version in "3.0" "4.0"; do
215
mkdir -p "$THEME_DIR/gtk-$version"
216
cp -r \
217
"$SRC_DIR/gtk-3.0/assets" \
218
"$SRC_DIR/gtk-3.0/icons" \
219
"$THEME_DIR/gtk-$version"
220
221
for variant in "${GTK_VARIANTS[@]}"; do
222
sed \
223
-e "s|@dark_theme@|$scss_dark_theme|g" \
224
-e "s|@light_topbar@|$scss_light_topbar|g" \
225
-e "s|@compact@|$scss_compact|g" \
226
-e "s|@version@|$GTK4_VERSION|g" \
227
-e "s|@current_source_dir@|$SRC_DIR/gtk-$version|g" \
228
"$SRC_DIR/gtk-$version/gtk$variant.scss.in" | \
229
sassc --stdin "${SASSC_OPT[@]}" \
230
"$THEME_DIR/gtk-$version/gtk$variant.css"
231
done
232
done
233
234
#
235
# Metacity
236
#
237
238
mkdir -p "$THEME_DIR/metacity-1"
239
cp -r \
240
"$SRC_DIR/metacity-1/assets" \
241
"$THEME_DIR/metacity-1"
242
cp -T \
243
"$SRC_DIR/metacity-1/metacity-theme-2$color.xml" \
244
"$THEME_DIR/metacity-1/metacity-theme-2.xml"
245
cp \
246
"$SRC_DIR/metacity-1/metacity-theme-3.xml" \
247
"$THEME_DIR/metacity-1"
248
249
#
250
# Plank
251
#
252
253
mkdir -p "$THEME_DIR/plank"
254
cp \
255
"$SRC_DIR/plank/dock.theme" \
256
"$THEME_DIR/plank"
257
258
#
259
# Unity
260
#
261
262
mkdir -p "$THEME_DIR/unity"
263
cp -r -T \
264
"$SRC_DIR/unity/dash-buttons" \
265
"$THEME_DIR/unity"
266
cp -r -T \
267
"$SRC_DIR/unity/launcher" \
268
"$THEME_DIR/unity"
269
cp -r -T \
270
"$SRC_DIR/unity/window-buttons${ELSE_LIGHT:-}" \
271
"$THEME_DIR/unity"
272
cp \
273
"$SRC_DIR/unity/dash-widgets.json" \
274
"$THEME_DIR/unity"
275
276
#
277
# Xfwm4
278
#
279
280
mkdir -p "$THEME_DIR/xfwm4"
281
cp -r -T \
282
"$SRC_DIR/xfwm4/xfwm4$color" \
283
"$THEME_DIR/xfwm4"
284
}
285
286
# Bakup and install files related to GDM theme
287
install_gdm_theme() {
288
local THEME_DIR="$1/$2$3$4"
289
local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource"
290
local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css"
291
292
if [[ -f "$GS_THEME_FILE" ]] && command -v glib-compile-resources >/dev/null; then
293
echo "Installing '$GS_THEME_FILE'..."
294
cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak"
295
glib-compile-resources \
296
--sourcedir="$THEME_DIR/gnome-shell" \
297
--target="$GS_THEME_FILE" \
298
"$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml"
299
else
300
echo
301
echo "ERROR: Failed to install '$GS_THEME_FILE'"
302
exit 1
303
fi
304
305
if [[ -f "$UBUNTU_THEME_FILE" ]]; then
306
echo "Installing '$UBUNTU_THEME_FILE'..."
307
cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak"
308
cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE"
309
fi
310
}
311
312
colors=()
313
sizes=()
314
while [[ "$#" -gt 0 ]]; do
315
case "${1:-}" in
316
-d|--dest)
317
dest="$2"
318
mkdir -p "$dest"
319
shift 2
320
;;
321
-n|--name)
322
_name="$2"
323
shift 2
324
;;
325
-g|--gdm)
326
gdm='true'
327
shift 1
328
;;
329
-c|--color)
330
shift
331
for variant in "$@"; do
332
case "$variant" in
333
standard)
334
colors+=("${COLOR_VARIANTS[0]}")
335
shift
336
;;
337
dark)
338
colors+=("${COLOR_VARIANTS[1]}")
339
shift
340
;;
341
light)
342
colors+=("${COLOR_VARIANTS[2]}")
343
shift
344
;;
345
-*)
346
break
347
;;
348
*)
349
echo "ERROR: Unrecognized color variant '$1'."
350
echo "Try '$0 --help' for more information."
351
exit 1
352
;;
353
esac
354
done
355
;;
356
-s|--size)
357
shift
358
for variant in "$@"; do
359
case "$variant" in
360
standard)
361
sizes+=("${SIZE_VARIANTS[0]}")
362
shift
363
;;
364
compact)
365
sizes+=("${SIZE_VARIANTS[1]}")
366
shift
367
;;
368
-*)
369
break
370
;;
371
*)
372
echo "ERROR: Unrecognized size variant '${1:-}'."
373
echo "Try '$0 --help' for more information."
374
exit 1
375
;;
376
esac
377
done
378
;;
379
-h|--help)
380
usage
381
exit 0
382
;;
383
*)
384
echo "ERROR: Unrecognized installation option '${1:-}'."
385
echo "Try '$0 --help' for more information."
386
exit 1
387
;;
388
esac
389
done
390
391
if [[ ! -w "${dest:-$DEST_DIR}" ]]; then
392
echo "Please run as root."
393
exit 1
394
fi
395
396
if [[ "${#colors[@]}" -eq 0 ]] ; then
397
colors=("${COLOR_VARIANTS[@]}")
398
fi
399
if [[ "${#sizes[@]}" -eq 0 ]] ; then
400
sizes=("${SIZE_VARIANTS[@]}")
401
fi
402
for color in "${colors[@]}"; do
403
for size in "${sizes[@]}"; do
404
install_theme "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size"
405
done
406
done
407
408
if [[ "${gdm:-}" == 'true' ]]; then
409
install_gdm_theme "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size"
410
fi
411
412
echo
413
echo "Done."
414