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