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