-
Notifications
You must be signed in to change notification settings - Fork 7
/
compile-theme
executable file
·379 lines (305 loc) · 8.88 KB
/
compile-theme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#! /bin/bash
set -e
THEME_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
declare -a VALID_GTK_VERSIONS=(10 18 20)
declare -a VALID_FLAVORS=('luna' 'homestead' 'metallic' 'royale' 'noir' 'embedded' 'zune')
help() {
cat << EOF
help: $0 options
compile CinnXP cursor, gtk, metacity, and cinnamon themes
OPTIONS:
-h this...
-a Compile all available flavors with one command.
Only compiles one gtk3 version at a time. Defaults for gtk
minor verison apply here (see below)
-g Target gtk minor version. Default is "20" for gtk3.20 and higher
For Linux Mint 17.x and 18.x pass "10" or "18" respectively
-f Flavor to compile (full string name) Defaults to "luna."
Current valid options are "luna," "homestead," "metallic," "royale,"
"noir," "embedded," and "zune"
-n Alternative root name for output file (default is "pkg")
-p Package all flavors/versions in tar.xz format for distribution
EOF
}
# TODO: add option to install to either /usr/share/ or $HOME
elementIn () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
validate_sassc() {
if [ ! "$(which sassc 2> /dev/null)" ]; then
echo sassc not installed. See README
exit 1
fi
}
validate_flavor() {
if ! $(elementIn "$1" "${VALID_FLAVORS[@]}"); then
echo "Invalid flavor requested."
help
exit
fi
}
validate_gtk_minor_version() {
if ! $(elementIn "$1" "${VALID_GTK_VERSIONS[@]}"); then
echo "Invalid gtk versions requested."
help
exit
fi
}
build_cursor_theme() {
local pkg_path="$1"
icon_dir="$pkg_path/CinnXP"
echo "Building cursor theme
"
if [ ! -d "$icon_dir" ]; then
mkdir -p "$icon_dir/cursors"
fi
cd icon-src/cursor-build
# generate cursor files
for i in *.cursor
do
filename=${i%.cursor}
xcursorgen "$i" "$icon_dir/cursors/$filename"
done
cp cursor.theme "$icon_dir"
cp thumbnail.png "$icon_dir/cursors"
cd "$icon_dir"/cursors
# link remaining cursor icons
ln -s sb_v_double_arrow 00008160000006810000408080010102
ln -s sb_h_double_arrow 028006030e0e7ebffc7f7070c0600140
ln -s crossed_circle 03b6e0fcb3499374a867c041f52298f0
ln -s left_ptr_watch 08e8e1c95fe2fc01f976f1e063a24ccd
ln -s copy 1081e37283d90000800003c07f3ef6bf
ln -s sb_h_double_arrow 14fef782d02440884392942c11205230
ln -s sb_v_double_arrow 2870a09082c103050810ffdffffe0204
ln -s link 3085a0e285430894940527032f8b26df
ln -s left_ptr_watch 3ecb610c1bf2410f44200f48c40d3599
ln -s move 4498f0e0c1937ffe01fd06f973665830
ln -s help 5c6cd98b3f3ebcb1f9c7f1c204630408
ln -s copy 6407b0e94181790501fd1e167b474872
ln -s link 640fb0e74195791501fd1ed57b41487f
ln -s move 9081237383d90e509aa00f00170e968f
ln -s hand 9d800788f1b08800ae810202380a0822
ln -s left_ptr arrow
ln -s top_left_corner bd_double_arrow
ln -s top_right_corner bottom_left_corner
ln -s top_left_corner bottom_right_corner
ln -s sb_v_double_arrow bottom_side
ln -s sb_v_double_arrow bottom_tee
ln -s top_left_corner c7088f0f3e6c8088236ef8e1e3e70000
ln -s crosshair cross
ln -s crosshair cross_reverse
ln -s help d9ce0ab605698f320427677b458ad60b
ln -s crosshair diamond_cross
ln -s hand dnd-none
ln -s target dotbox
ln -s target dot_box_mask
ln -s sb_v_double_arrow double_arrow
ln -s right_ptr draft_large
ln -s right_ptr draft_small
ln -s target draped_box
ln -s hand e29285e634086352946a0e7090d73106
ln -s top_right_corner fcf1c3c7cd4491d801f1e1c78f100000
ln -s top_right_corner fd_double_arrow
ln -s hand fleur
ln -s hand grab
ln -s hand grabbing
ln -s hand hand1
ln -s hand hand2
ln -s sb_h_double_arrow h_double_arrow
ln -s target icon
ln -s sb_h_double_arrow left_side
ln -s sb_h_double_arrow left_tee
ln -s top_right_corner ll_angle
ln -s top_left_corner lr_angle
ln -s crossed_circle pirate
ln -s help question_arrow
ln -s sb_h_double_arrow right_side
ln -s sb_h_double_arrow right_tee
ln -s crosshair tcross
ln -s left_ptr top_left_arrow
ln -s sb_v_double_arrow top_side
ln -s sb_v_double_arrow top_tee
ln -s top_left_corner ul_angle
ln -s top_right_corner ur_angle
ln -s sb_v_double_arrow v_double_arrow
ln -s wait watch
ln -s crossed_circle X_cursor
ln -s ibeam xterm
cd "$THEME_ROOT"
}
clean_scss() {
local scss_dir="$1"
declare -a files_to_clean=('gtk-contained.css' 'cinnamon.css')
for file in "${files_to_clean[@]}"
do
if [ -e "$scss_dir/$file" ]; then
echo "WARNING: source dir not clean (FOUND $file)"
rm "$scss_dir/$file"
fi
done
}
# TODO: it's kinda strange that I forbid scss on gtk3.10...but really I don't
# feel like converting it
build_gtk3_theme() {
local theme_dest="$1"
local theme_src="$2"
local gtk3_minor_revision="$3"
echo " - now building gtk3 theme
"
local scss=true
if [ "$gtk3_minor_revision" -lt 16 ]; then
scss=false
fi
if $scss; then
clean_scss "$theme_src/gtk-3.$gtk3_minor_revision"
fi
# make new gtk-3.0 dir in target dir
if [ ! -d "$theme_dest" ]; then
mkdir -p "$theme_dest/gtk-3.0"
fi
# copy gtk3 to tmp working directory (resolve symlinks)
build_path="/tmp/gtk-3.0"
cp -rL "$theme_src/gtk-3.$gtk3_minor_revision" "$build_path"
cd "$build_path"
if $scss; then
./parse-sass.sh > /dev/null
# change compiled files here (currently uses all png images and gtk-contained.css files)
files=$(find . -type f \( -name "*.png" ! -name "thumbnail.png" -or -name "*gtk-contained.css" \))
resource_file="gtk-contained.css"
else
files=$(find . -type f \( -name "*.png" -or -name "*.css" \))
resource_file="gtk.css"
fi
# build xml file for gtk.gresource
files=${files//.$'\n'/}
files=${files//'./'/' <file>'}
files=${files//$'\n'/'</file>'$'\n'}
files="$files"'</file>'$'\n'
resource_path="/org/gnome/$theme_folder_name"
xml_path="/tmp/gresources.xml"
header="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<gresources>
<gresource prefix=\"$resource_path\">
"
footer=" </gresource>
</gresources>"
echo "$header$files$footer" > "$xml_path"
# build gtk3 resources file
glib-compile-resources --target="$theme_dest/gtk-3.0/gtk.gresource" "/tmp/gresources.xml"
# copy thumbnail
cp "$theme_src/thumbnail-gtk.png" "$theme_dest/gtk-3.0/thumbnail.png"
# make gtk.css to point to correct resource
echo "@import url(\"resource://$resource_path/$resource_file\");" > "$theme_dest/gtk-3.0/gtk.css"
rm "$xml_path"
rm -r "$build_path"
cd "$THEME_ROOT"
}
build_cinnamon_theme() {
local theme_dir="$1"
local theme_src="$2"
echo " - now building cinnamon theme
"
clean_scss "$theme_src/cinnamon"
# make new cinnamon dir in target dir
if [ ! -d "$theme_dir" ]; then
mkdir -p "$theme_dir/cinnamon"
fi
# copy cinnamon to tmp working directory (resolve symlinks)
build_path="$theme_dir/cinnamon"
cp -rL "$theme_src/cinnamon" "$build_path"
cd "$build_path"
./parse-sass.sh > /dev/null
# remove building files
rm README parse-sass.sh *.scss
cd "$THEME_ROOT"
}
build_flavor() {
local pkg_path="$1"
local flavor="$2"
local gtk3_minor_revision="$3"
theme_folder_name="CinnXP-${flavor^}"
theme_src="$THEME_ROOT/theme-src/flavors/$flavor"
theme_dest="$pkg_path/$theme_folder_name"
echo "Building flavor: $flavor (gtk3.$gtk3_minor_revision)"
build_gtk3_theme "$theme_dest" "$theme_src" "$gtk3_minor_revision"
build_cinnamon_theme "$theme_dest" "$theme_src"
# copy everything else
echo " - now copying gtk2 and metacity themes
"
cp -rL "$theme_src/"{gtk-2.0,index.theme} "$theme_dest"
cp -r "$theme_src/metacity-1" "$theme_dest"
}
build_all_flavors() {
local pkg_path="$1"
local gtk3_minor_revision="$2"
validate_gtk_minor_version "$gtk3_minor_revision"
build_cursor_theme "$pkg_path/usr/share/icons"
for flavor in "${VALID_FLAVORS[@]}"
do
build_flavor "$pkg_path/usr/share/themes" "$flavor" "$gtk3_minor_revision"
done
}
package_all() {
local cursor_dest="$THEME_ROOT/CinnXP_Cursors"
build_cursor_theme "$cursor_dest"
tar cJPf "$cursor_dest.tar.xz" "CinnXP_Cursors"
rm -r "$cursor_dest"
for version in "${VALID_GTK_VERSIONS[@]}"
do
local version_dest="$THEME_ROOT/CinnXP_themes_gtk3.$version"
for flavor in "${VALID_FLAVORS[@]}"
do
build_flavor "$version_dest" "$flavor" "$version"
done
tar cJPf "$version_dest.tar.xz" "CinnXP_themes_gtk3.$version"
rm -r "$version_dest"
done
}
# default values
pkg_dir="$THEME_ROOT/pkg"
gtk3_minor_revision=20
flavor="luna"
while getopts “hapg:f:n:” OPTION
do
case $OPTION in
h)
help
exit 1
;;
a)
all=0
;;
p)
package=0
;;
g)
gtk3_minor_revision=$OPTARG
;;
f)
flavor=$OPTARG
;;
n)
pkg_dir="$THEME_ROOT/$OPTARG"
;;
*)
break
;;
esac
done
validate_sassc
if [ -n "$all" ] && [ -n "$package" ]; then
echo "ERROR: cannot set -a and -p at once"
exit
fi
if [ -n "$all" ]; then
build_all_flavors "$pkg_dir" "$gtk3_minor_revision"
elif [ -n "$package" ]; then
package_all
else
validate_gtk_minor_version "$gtk3_minor_revision"
validate_flavor "$flavor"
build_cursor_theme "$pkg_dir/usr/share/icons"
build_flavor "$pkg_dir/usr/share/themes" "$flavor" "$gtk3_minor_revision"
fi