install.sh
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, INSTALL_GDM_THEME.md & index.theme
118
#
119
120
mkdir -p "$THEME_DIR"
121
cp \
122
"$REPO_DIR/COPYING" \
123
"$REPO_DIR/INSTALL_GDM_THEME.md" \
124
"$THEME_DIR"
125
sed \
126
-e "s|@theme_name@|$name|g" \
127
"$SRC_DIR/index.theme.in" > \
128
"$THEME_DIR/index.theme"
129
130
#
131
# Chrome extensions
132
#
133
134
mkdir -p "$THEME_DIR/chrome"
135
cp -T \
136
"$SRC_DIR/chrome/chrome-scrollbar${ELSE_DARK:-}.crx" \
137
"$THEME_DIR/chrome/chrome-scrollbar.crx"
138
cp -T \
139
"$SRC_DIR/chrome/chrome-theme$color.crx" \
140
"$THEME_DIR/chrome/chrome-theme.crx"
141
142
#
143
# Cinnamon
144
#
145
146
mkdir -p "$THEME_DIR/cinnamon"
147
cp -r \
148
"$SRC_DIR/cinnamon/assets" \
149
"$THEME_DIR/cinnamon"
150
cp \
151
"$SRC_DIR/cinnamon/thumbnail.png" \
152
"$THEME_DIR/cinnamon"
153
sed \
154
-e "s|@dark_theme@|$scss_dark_theme|g" \
155
-e "s|@light_topbar@|$scss_light_topbar|g" \
156
-e "s|@compact@|$scss_compact|g" \
157
-e "s|@current_source_dir@|$SRC_DIR/cinnamon|g" \
158
"$SRC_DIR/cinnamon/cinnamon.scss.in" | \
159
sassc --stdin "${SASSC_OPT[@]}" \
160
"$THEME_DIR/cinnamon/cinnamon.css"
161
162
#
163
# GNOME Shell
164
#
165
166
mkdir -p "$THEME_DIR/gnome-shell"
167
cp -r -T \
168
"$SRC_DIR/gnome-shell/assets${ELSE_DARK:-}" \
169
"$THEME_DIR/gnome-shell/assets"
170
cp -r \
171
"$SRC_DIR/gnome-shell/extensions" \
172
"$SRC_DIR/gnome-shell/icons" \
173
"$THEME_DIR/gnome-shell"
174
cp \
175
"$SRC_DIR/gnome-shell/gnome-shell-start.svg" \
176
"$SRC_DIR/gnome-shell/gnome-shell-theme.gresource.xml" \
177
"$SRC_DIR/gnome-shell/noise-texture.png" \
178
"$SRC_DIR/gnome-shell/pad-osd.css" \
179
"$SRC_DIR/gnome-shell/process-working.svg" \
180
"$THEME_DIR/gnome-shell"
181
sed \
182
-e "s|@dark_theme@|$scss_dark_theme|g" \
183
-e "s|@light_topbar@|$scss_light_topbar|g" \
184
-e "s|@compact@|$scss_compact|g" \
185
-e "s|@version@|$GS_VERSION|g" \
186
-e "s|@current_source_dir@|$SRC_DIR/gnome-shell|g" \
187
"$SRC_DIR/gnome-shell/gnome-shell.scss.in" | \
188
sassc --stdin "${SASSC_OPT[@]}" \
189
"$THEME_DIR/gnome-shell/gnome-shell.css"
190
191
#
192
# GTK 2
193
#
194
195
mkdir -p "$THEME_DIR/gtk-2.0"
196
cp -r -T \
197
"$SRC_DIR/gtk-2.0/assets${ELSE_DARK:-}" \
198
"$THEME_DIR/gtk-2.0/assets"
199
cp -T \
200
"$SRC_DIR/gtk-2.0/gtkrc$color" \
201
"$THEME_DIR/gtk-2.0/gtkrc"
202
cp \
203
"$SRC_DIR/gtk-2.0/apps.rc" \
204
"$SRC_DIR/gtk-2.0/hacks.rc" \
205
"$SRC_DIR/gtk-2.0/main.rc" \
206
"$THEME_DIR/gtk-2.0"
207
208
#
209
# GTK 3 & 4
210
#
211
212
local GTK_VARIANTS=('')
213
[[ "$color" != '-dark' ]] && local GTK_VARIANTS+=('-dark')
214
215
for version in "3.0" "4.0"; do
216
mkdir -p "$THEME_DIR/gtk-$version"
217
cp -r \
218
"$SRC_DIR/gtk-3.0/assets" \
219
"$SRC_DIR/gtk-3.0/icons" \
220
"$THEME_DIR/gtk-$version"
221
222
for variant in "${GTK_VARIANTS[@]}"; do
223
sed \
224
-e "s|@dark_theme@|$scss_dark_theme|g" \
225
-e "s|@light_topbar@|$scss_light_topbar|g" \
226
-e "s|@compact@|$scss_compact|g" \
227
-e "s|@version@|$GTK4_VERSION|g" \
228
-e "s|@current_source_dir@|$SRC_DIR/gtk-$version|g" \
229
"$SRC_DIR/gtk-$version/gtk$variant.scss.in" | \
230
sassc --stdin "${SASSC_OPT[@]}" \
231
"$THEME_DIR/gtk-$version/gtk$variant.css"
232
done
233
done
234
235
#
236
# Metacity
237
#
238
239
mkdir -p "$THEME_DIR/metacity-1"
240
cp -r \
241
"$SRC_DIR/metacity-1/assets" \
242
"$THEME_DIR/metacity-1"
243
cp -T \
244
"$SRC_DIR/metacity-1/metacity-theme-2$color.xml" \
245
"$THEME_DIR/metacity-1/metacity-theme-2.xml"
246
cp \
247
"$SRC_DIR/metacity-1/metacity-theme-3.xml" \
248
"$THEME_DIR/metacity-1"
249
250
#
251
# Plank
252
#
253
254
mkdir -p "$THEME_DIR/plank"
255
cp \
256
"$SRC_DIR/plank/dock.theme" \
257
"$THEME_DIR/plank"
258
259
#
260
# Unity
261
#
262
263
mkdir -p "$THEME_DIR/unity"
264
cp -r -T \
265
"$SRC_DIR/unity/dash-buttons" \
266
"$THEME_DIR/unity"
267
cp -r -T \
268
"$SRC_DIR/unity/launcher" \
269
"$THEME_DIR/unity"
270
cp -r -T \
271
"$SRC_DIR/unity/window-buttons${ELSE_LIGHT:-}" \
272
"$THEME_DIR/unity"
273
cp \
274
"$SRC_DIR/unity/dash-widgets.json" \
275
"$THEME_DIR/unity"
276
277
#
278
# Xfwm4
279
#
280
281
mkdir -p "$THEME_DIR/xfwm4"
282
cp -r -T \
283
"$SRC_DIR/xfwm4/xfwm4$color" \
284
"$THEME_DIR/xfwm4"
285
}
286
287
# Bakup and install files related to GDM theme
288
install_gdm_theme() {
289
local THEME_DIR="$1/$2$3$4"
290
local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource"
291
local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css"
292
293
if [[ -f "$GS_THEME_FILE" ]] && command -v glib-compile-resources >/dev/null; then
294
echo "Installing '$GS_THEME_FILE'..."
295
cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak"
296
glib-compile-resources \
297
--sourcedir="$THEME_DIR/gnome-shell" \
298
--target="$GS_THEME_FILE" \
299
"$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml"
300
else
301
echo
302
echo "ERROR: Failed to install '$GS_THEME_FILE'"
303
exit 1
304
fi
305
306
if [[ -f "$UBUNTU_THEME_FILE" ]]; then
307
echo "Installing '$UBUNTU_THEME_FILE'..."
308
cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak"
309
cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE"
310
fi
311
}
312
313
colors=()
314
sizes=()
315
while [[ "$#" -gt 0 ]]; do
316
case "${1:-}" in
317
-d|--dest)
318
dest="$2"
319
mkdir -p "$dest"
320
shift 2
321
;;
322
-n|--name)
323
_name="$2"
324
shift 2
325
;;
326
-g|--gdm)
327
gdm='true'
328
shift 1
329
;;
330
-c|--color)
331
shift
332
for variant in "$@"; do
333
case "$variant" in
334
standard)
335
colors+=("${COLOR_VARIANTS[0]}")
336
shift
337
;;
338
dark)
339
colors+=("${COLOR_VARIANTS[1]}")
340
shift
341
;;
342
light)
343
colors+=("${COLOR_VARIANTS[2]}")
344
shift
345
;;
346
-*)
347
break
348
;;
349
*)
350
echo "ERROR: Unrecognized color variant '$1'."
351
echo "Try '$0 --help' for more information."
352
exit 1
353
;;
354
esac
355
done
356
;;
357
-s|--size)
358
shift
359
for variant in "$@"; do
360
case "$variant" in
361
standard)
362
sizes+=("${SIZE_VARIANTS[0]}")
363
shift
364
;;
365
compact)
366
sizes+=("${SIZE_VARIANTS[1]}")
367
shift
368
;;
369
-*)
370
break
371
;;
372
*)
373
echo "ERROR: Unrecognized size variant '${1:-}'."
374
echo "Try '$0 --help' for more information."
375
exit 1
376
;;
377
esac
378
done
379
;;
380
-h|--help)
381
usage
382
exit 0
383
;;
384
*)
385
echo "ERROR: Unrecognized installation option '${1:-}'."
386
echo "Try '$0 --help' for more information."
387
exit 1
388
;;
389
esac
390
done
391
392
if [[ ! -w "${dest:-$DEST_DIR}" ]]; then
393
echo "Please run as root."
394
exit 1
395
fi
396
397
if [[ "${#colors[@]}" -eq 0 ]] ; then
398
colors=("${COLOR_VARIANTS[@]}")
399
fi
400
if [[ "${#sizes[@]}" -eq 0 ]] ; then
401
sizes=("${SIZE_VARIANTS[@]}")
402
fi
403
for color in "${colors[@]}"; do
404
for size in "${sizes[@]}"; do
405
install_theme "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size"
406
done
407
done
408
409
if [[ "${gdm:-}" == 'true' ]]; then
410
install_gdm_theme "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size"
411
fi
412
413
echo
414
echo "Done."
415