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.45 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
cp -r "$SRC_DIR/gtk/assets" "$THEME_DIR/gtk-assets"
138
cp -r "$SRC_DIR/gtk/icons" "$THEME_DIR/gtk-icons"
139
140
local GTK_VARIANTS=('')
141
[[ "$color" != '-dark' ]] && local GTK_VARIANTS+=('-dark')
142
143
for version in "${GTK_VERSIONS[@]}"; do
144
mkdir -p "$THEME_DIR/gtk-$version"
145
ln -s ../gtk-assets "$THEME_DIR/gtk-$version/assets"
146
ln -s ../gtk-icons "$THEME_DIR/gtk-$version/icons"
147
148
for variant in "${GTK_VARIANTS[@]}"; do
149
sed \
150
-e "s/@dark_theme@/$scss_dark_theme/g" \
151
-e "s/@light_topbar@/$scss_light_topbar/g" \
152
-e "s/@compact@/$scss_compact/g" \
153
"$SRC_DIR/gtk/gtk$variant.scss.in" > "$SRC_DIR/gtk/gtk$variant.gtk-$version.$name.scss"
154
sassc "${SASSC_OPT[@]}" "$SRC_DIR/gtk/gtk$variant.gtk-$version.$name.scss" "$THEME_DIR/gtk-$version/gtk$variant.css"
155
done
156
done
157
158
mkdir -p "$THEME_DIR/metacity-1"
159
cp -r "$SRC_DIR/metacity-1/"{assets,metacity-theme-3.xml} "$THEME_DIR/metacity-1"
160
cp -r "$SRC_DIR/metacity-1/metacity-theme-2$color.xml" "$THEME_DIR/metacity-1/metacity-theme-2.xml"
161
162
mkdir -p "$THEME_DIR/plank"
163
cp -r "$SRC_DIR/plank/dock.theme" "$THEME_DIR/plank"
164
165
mkdir -p "$THEME_DIR/unity"
166
cp -rT "$SRC_DIR/unity/dash-buttons" "$THEME_DIR/unity"
167
cp -r "$SRC_DIR/unity/dash-widgets.json" "$THEME_DIR/unity"
168
cp -rT "$SRC_DIR/unity/launcher" "$THEME_DIR/unity"
169
cp -rT "$SRC_DIR/unity/window-buttons${ELSE_LIGHT:-}" "$THEME_DIR/unity"
170
171
cp -r "$SRC_DIR/xfwm4/xfwm4$color" "$THEME_DIR/xfwm4"
172
}
173
174
# Bakup and install files related to GDM theme
175
install_gdm() {
176
local THEME_DIR="$1/$2$3$4"
177
local GS_THEME_FILE="/usr/share/gnome-shell/gnome-shell-theme.gresource"
178
local UBUNTU_THEME_FILE="/usr/share/gnome-shell/theme/ubuntu.css"
179
180
if [[ -f "$GS_THEME_FILE" ]] && command -v glib-compile-resources >/dev/null; then
181
echo "Installing '$GS_THEME_FILE'..."
182
cp -an "$GS_THEME_FILE" "$GS_THEME_FILE.bak"
183
glib-compile-resources \
184
--sourcedir="$THEME_DIR/gnome-shell" \
185
--target="$GS_THEME_FILE" \
186
"$THEME_DIR/gnome-shell/gnome-shell-theme.gresource.xml"
187
else
188
echo
189
echo "ERROR: Failed to install '$GS_THEME_FILE'"
190
exit 1
191
fi
192
193
if [[ -f "$UBUNTU_THEME_FILE" ]]; then
194
echo "Installing '$UBUNTU_THEME_FILE'..."
195
cp -an "$UBUNTU_THEME_FILE" "$UBUNTU_THEME_FILE.bak"
196
cp -af "$THEME_DIR/gnome-shell/gnome-shell.css" "$UBUNTU_THEME_FILE"
197
fi
198
}
199
200
colors=()
201
sizes=()
202
while [[ "$#" -gt 0 ]]; do
203
case "${1:-}" in
204
-d|--dest)
205
dest="$2"
206
mkdir -p "$dest"
207
shift 2
208
;;
209
-n|--name)
210
_name="$2"
211
shift 2
212
;;
213
-g|--gdm)
214
gdm='true'
215
shift 1
216
;;
217
-c|--color)
218
shift
219
for variant in "$@"; do
220
case "$variant" in
221
standard)
222
colors+=("${COLOR_VARIANTS[0]}")
223
shift
224
;;
225
dark)
226
colors+=("${COLOR_VARIANTS[1]}")
227
shift
228
;;
229
light)
230
colors+=("${COLOR_VARIANTS[2]}")
231
shift
232
;;
233
-*)
234
break
235
;;
236
*)
237
echo "ERROR: Unrecognized color variant '$1'."
238
echo "Try '$0 --help' for more information."
239
exit 1
240
;;
241
esac
242
done
243
;;
244
-s|--size)
245
shift
246
for variant in "$@"; do
247
case "$variant" in
248
standard)
249
sizes+=("${SIZE_VARIANTS[0]}")
250
shift
251
;;
252
compact)
253
sizes+=("${SIZE_VARIANTS[1]}")
254
shift
255
;;
256
-*)
257
break
258
;;
259
*)
260
echo "ERROR: Unrecognized size variant '${1:-}'."
261
echo "Try '$0 --help' for more information."
262
exit 1
263
;;
264
esac
265
done
266
;;
267
-h|--help)
268
usage
269
exit 0
270
;;
271
*)
272
echo "ERROR: Unrecognized installation option '${1:-}'."
273
echo "Try '$0 --help' for more information."
274
exit 1
275
;;
276
esac
277
done
278
279
if [[ ! -w "${dest:-$DEST_DIR}" ]]; then
280
echo "Please run as root."
281
exit 1
282
fi
283
284
if [[ "${#colors[@]}" -eq 0 ]] ; then
285
colors=("${COLOR_VARIANTS[@]}")
286
fi
287
if [[ "${#sizes[@]}" -eq 0 ]] ; then
288
sizes=("${SIZE_VARIANTS[@]}")
289
fi
290
for color in "${colors[@]}"; do
291
for size in "${sizes[@]}"; do
292
install "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size"
293
done
294
done
295
296
if [[ "${gdm:-}" == 'true' ]]; then
297
install_gdm "${dest:-$DEST_DIR}" "${_name:-$THEME_NAME}" "$color" "$size"
298
fi
299
300
echo
301
echo "Done."
302