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