install.sh
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.18' '3.20' '3.22')
14
GS_VERSIONS=('3.18' '3.24' '3.26')
15
LATEST_GS_VERSION=${GS_VERSIONS[@]: -1}
16
17
# Set a proper gnome-shell theme version
18
if [[ $(which gnome-shell 2> /dev/null) ]]; then
19
CURRENT_GS_VERSION=$(gnome-shell --version | cut -d ' ' -f 3 | cut -d . -f -2)
20
for version in "${GS_VERSIONS[@]}"; do
21
if (( $(echo "$CURRENT_GS_VERSION <= $version" | bc) )); then
22
GS_VERSION=${version}
23
break
24
elif (( $(echo "$CURRENT_GS_VERSION > $LATEST_GS_VERSION" | bc) )); then
25
GS_VERSION=${LATEST_GS_VERSION}
26
break
27
fi
28
done
29
else
30
GS_VERSION=${LATEST_GS_VERSION}
31
fi
32
33
usage() {
34
printf "%s\n" "Usage: $0 [OPTIONS...]"
35
printf "\n%s\n" "OPTIONS:"
36
printf " %-25s%s\n" "-d, --dest DIR" "Specify theme destination directory (Default: ${DEST_DIR})"
37
printf " %-25s%s\n" "-n, --name NAME" "Specify theme name (Default: ${THEME_NAME})"
38
printf " %-25s%s\n" "-c, --color VARIANTS..." "Specify theme color variant(s) [standard|dark|light] (Default: All variants)"
39
printf " %-25s%s\n" "-s, --size VARIANT" "Specify theme size variant [standard|compact] (Default: All variants)"
40
printf " %-25s%s\n" "-h, --help" "Show this help"
41
printf "\n%s\n" "INSTALLATION EXAMPLES:"
42
printf "%s\n" "Install all theme variants into ~/.themes"
43
printf " %s\n" "$0 --dest ~/.themes"
44
printf "%s\n" "Install standard theme variant only"
45
printf " %s\n" "$0 --color standard --size standard"
46
printf "%s\n" "Install specific theme variants with different name into ~/.themes"
47
printf " %s\n" "$0 --dest ~/.themes --name MyTheme --color light dark --size compact"
48
}
49
50
install() {
51
local dest=${1}
52
local name=${2}
53
local color=${3}
54
local size=${4}
55
56
[[ ${color} == '-dark' ]] && local ELSE_DARK=${color}
57
[[ ${color} == '-light' ]] && local ELSE_LIGHT=${color}
58
59
local THEME_DIR=${dest}/${name}${color}${size}
60
61
[[ -d ${THEME_DIR} ]] && rm -rf ${THEME_DIR}
62
63
echo "Installing '${THEME_DIR}'..."
64
65
mkdir -p ${THEME_DIR}
66
cp -r ${REPO_DIR}/COPYING ${THEME_DIR}
67
cp -r ${SRC_DIR}/index${color}${size}.theme ${THEME_DIR}/index.theme
68
69
mkdir -p ${THEME_DIR}/chrome
70
cp -r ${SRC_DIR}/chrome/chrome-theme${color}.crx ${THEME_DIR}/chrome/chrome-theme.crx
71
cp -r ${SRC_DIR}/chrome/chrome-scrollbar${ELSE_DARK}.crx ${THEME_DIR}/chrome/chrome-scrollbar.crx
72
73
mkdir -p ${THEME_DIR}/gnome-shell
74
cp -r ${SRC_DIR}/gnome-shell/{*.svg,extensions,noise-texture.png,pad-osd.css} ${THEME_DIR}/gnome-shell
75
cp -r ${SRC_DIR}/gnome-shell/assets${ELSE_DARK} ${THEME_DIR}/gnome-shell/assets
76
cp -r ${SRC_DIR}/gnome-shell/${GS_VERSION}/gnome-shell${color}${size}.css ${THEME_DIR}/gnome-shell/gnome-shell.css
77
glib-compile-resources \
78
--sourcedir=${THEME_DIR}/gnome-shell \
79
--target=${THEME_DIR}/gnome-shell/gnome-shell-theme.gresource \
80
${SRC_DIR}/gnome-shell/gnome-shell-theme.gresource.xml
81
82
mkdir -p ${THEME_DIR}/gtk-2.0
83
cp -r ${SRC_DIR}/gtk-2.0/{apps.rc,hacks.rc,main.rc} ${THEME_DIR}/gtk-2.0
84
cp -r ${SRC_DIR}/gtk-2.0/assets${ELSE_DARK} ${THEME_DIR}/gtk-2.0/assets
85
cp -r ${SRC_DIR}/gtk-2.0/gtkrc${color} ${THEME_DIR}/gtk-2.0/gtkrc
86
87
cp -r ${SRC_DIR}/gtk/assets ${THEME_DIR}/gtk-assets
88
89
for version in "${GTK_VERSIONS[@]}"; do
90
if [[ ${version} == '3.18' ]]; then
91
mkdir -p ${THEME_DIR}/gtk-3.0
92
ln -s ../gtk-assets ${THEME_DIR}/gtk-3.0/assets
93
cp -r ${SRC_DIR}/gtk/${version}/gtk${color}.css ${THEME_DIR}/gtk-3.0/gtk.css
94
[[ ${color} != '-dark' ]] && \
95
cp -r ${SRC_DIR}/gtk/${version}/gtk-dark.css ${THEME_DIR}/gtk-3.0/gtk-dark.css
96
else
97
mkdir -p ${THEME_DIR}/gtk-${version}
98
ln -s ../gtk-assets ${THEME_DIR}/gtk-${version}/assets
99
cp -r ${SRC_DIR}/gtk/${version}/gtk${color}${size}.css ${THEME_DIR}/gtk-${version}/gtk.css
100
[[ ${color} != '-dark' ]] && \
101
cp -r ${SRC_DIR}/gtk/${version}/gtk-dark${size}.css ${THEME_DIR}/gtk-${version}/gtk-dark.css
102
fi
103
done
104
105
mkdir -p ${THEME_DIR}/metacity-1
106
cp -r ${SRC_DIR}/metacity-1/assets ${THEME_DIR}/metacity-1
107
cp -r ${SRC_DIR}/metacity-1/metacity-theme-2${ELSE_LIGHT}.xml ${THEME_DIR}/metacity-1/metacity-theme-2.xml
108
cp -r ${SRC_DIR}/metacity-1/metacity-theme-3${ELSE_LIGHT}.xml ${THEME_DIR}/metacity-1/metacity-theme-3.xml
109
110
mkdir -p ${THEME_DIR}/unity
111
cp -r ${SRC_DIR}/unity/{*.svg,*.png,dash-widgets.json} ${THEME_DIR}/unity
112
cp -r ${SRC_DIR}/unity/assets${ELSE_LIGHT} ${THEME_DIR}/unity/assets
113
114
mkdir -p ${THEME_DIR}/xfwm4
115
cp -r ${SRC_DIR}/xfwm4/{*.svg,themerc} ${THEME_DIR}/xfwm4
116
cp -r ${SRC_DIR}/xfwm4/assets${ELSE_LIGHT} ${THEME_DIR}/xfwm4/assets
117
}
118
119
while [[ $# -gt 0 ]]; do
120
case "${1}" in
121
-d|--dest)
122
dest="${2}"
123
if [[ ! -d "${dest}" ]]; then
124
echo "ERROR: Destination directory does not exist."
125
exit 1
126
fi
127
shift 2
128
;;
129
-n|--name)
130
name="${2}"
131
shift 2
132
;;
133
-c|--color)
134
shift
135
for variant in "${@}"; do
136
case "${variant}" in
137
standard)
138
colors+=("${COLOR_VARIANTS[0]}")
139
shift
140
;;
141
dark)
142
colors+=("${COLOR_VARIANTS[1]}")
143
shift
144
;;
145
light)
146
colors+=("${COLOR_VARIANTS[2]}")
147
shift
148
;;
149
-*|--*)
150
break
151
;;
152
*)
153
echo "ERROR: Unrecognized color variant '$1'."
154
echo "Try '$0 --help' for more information."
155
exit 1
156
;;
157
esac
158
done
159
;;
160
-s|--size)
161
shift
162
for variant in "${@}"; do
163
case "${variant}" in
164
standard)
165
sizes+=("${SIZE_VARIANTS[0]}")
166
shift
167
;;
168
compact)
169
sizes+=("${SIZE_VARIANTS[1]}")
170
shift
171
;;
172
-*|--*)
173
break
174
;;
175
*)
176
echo "ERROR: Unrecognized size variant '$1'."
177
echo "Try '$0 --help' for more information."
178
exit 1
179
;;
180
esac
181
done
182
;;
183
-h|--help)
184
usage
185
exit 0
186
;;
187
*)
188
echo "ERROR: Unrecognized installation option '$1'."
189
echo "Try '$0 --help' for more information."
190
exit 1
191
;;
192
esac
193
done
194
195
if [[ ! -w "${dest:-${DEST_DIR}}" ]]; then
196
echo "Please run as root."
197
exit 1
198
fi
199
200
for color in "${colors[@]:-${COLOR_VARIANTS[@]}}"; do
201
for size in "${sizes[@]:-${SIZE_VARIANTS[@]}}"; do
202
install "${dest:-${DEST_DIR}}" "${name:-${THEME_NAME}}" "${color}" "${size}"
203
done
204
done
205
206
echo
207
echo Done.
208