forked from openstenoproject/plover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·314 lines (279 loc) · 4.75 KB
/
bootstrap.sh
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
#!/bin/bash
opt_tests_only=0
opt_dry_run=0
python='false'
wheels=''
info()
{
if [ -t 1 ]
then
echo "[34m$@[0m"
else
echo "$@"
fi
}
err()
{
if [ -t 2 ]
then
echo "[31m$@[0m" 1>&2
else
echo "$@" 1>&2
fi
}
find_dist()
{
if ! [ -r /etc/lsb-release ]
then
if [ -r /etc/arch-release ]
then
echo arch
return
fi
err "unsuported distribution: $dist"
return 1
fi
dist="$(lsb_release -i -s | tr A-Z a-z)"
case "$dist" in
arch)
echo 'arch'
;;
linuxmint|ubuntu)
echo 'ubuntu'
;;
*)
err "unsuported distribution: $dist"
return 1
;;
esac
}
run()
{
info "$@"
if [ $opt_dry_run -eq 0 ]
then
"$@"
fi
}
pip()
{
run "$python" -m pip --disable-pip-version-check --timeout=5 --retries=2 "$@"
}
pip_cache_requirements()
{
run pip wheel -r requirements.txt -w "$wheels" --find-links "$wheels" "$@"
}
pip_install_requirements()
{
run pip install --user --upgrade --no-index -r requirements.txt --find-links "$wheels" "$@"
}
# Mac OS X. {{{
osx_bootstrap()
{
if [ "$python" == 'python2' ]
then
python_package='python'
else
python_package="$python"
fi
run brew update
osx_packages_install $python_package
run brew link --overwrite $python_package
}
osx_packages_install()
{
for package in "$@"
do
run brew install $package ||
run brew outdated $package ||
run brew upgrade $package
done
}
osx_python2_base_packages=(
)
osx_python2_extra_packages=(
wxpython
)
osx_python3_base_packages=(
)
osx_python3_extra_packages=(
)
# }}}
# Arch Linux. {{{
arch_bootstrap()
{
run sudo pacman --sync --refresh
}
arch_packages_install()
{
run sudo pacman --sync --needed "$@"
}
arch_python2_base_packages=(
cython2
libusb
python2-appdirs
python2-dbus
python2-hidapi
python2-mock
python2-pip
python2-pyserial
python2-pytest
python2-setuptools
python2-setuptools-scm
python2-six
python2-wheel
python2-xlib
)
arch_python2_extra_packages=(
base-devel
wmctrl
wxpython
)
arch_python3_base_packages=(
cython
libusb
python-appdirs
python-dbus
python-mock
python-pip
python-pyserial
python-pytest
python-setuptools
python-setuptools-scm
python-six
python-wheel
python-xlib
)
arch_python3_extra_packages=(
wmctrl
)
# }}}
# Ubuntu. {{{
ubuntu_bootstrap()
{
run sudo apt-add-repository -y ppa:benoit.pierre/plover
run sudo apt-get update -qq
}
ubuntu_packages_install()
{
run sudo apt-get install -y "$@"
}
ubuntu_python2_base_packages=(
cython
libudev-dev
libusb-1.0-0-dev
python-appdirs
python-dbus
python-dev
python-hid
python-mock
python-pip
python-pkg-resources
python-pytest
python-serial
python-setuptools
python-setuptools-scm
python-six
python-wheel
python-xlib
)
ubuntu_python2_extra_packages=(
debhelper
devscripts
python-wxgtk3.0
wmctrl
)
ubuntu_python3_base_packages=(
cython3
libudev-dev
libusb-1.0-0-dev
python3-appdirs
python3-dbus
python3-dev
python3-hid
python3-mock
python3-pip
python3-pkg-resources
python3-pytest
python3-serial
python3-setuptools
python3-setuptools-scm
python3-six
python3-wheel
python3-xlib
)
ubuntu_python3_extra_packages=(
wmctrl
)
# }}}
set -e
while [ $# -ne 0 ]
do
case "$1" in
--tests-only|-t)
opt_tests_only=1
;;
--dry-run|-n)
opt_dry_run=1
;;
--debug|-d)
set -x
;;
--help|-h)
exit 0
;;
-*)
err "invalid option: $1"
exit 1
;;
*)
break
;;
esac
shift
done
python="${1:-python2}"
case "$OSTYPE" in
linux-gnu)
dist="$(find_dist)"
wheels="${XDG_CACHE_HOME:-$HOME/.cache}/wheels"
;;
darwin*)
dist='osx'
wheels="$HOME/Library/Caches/wheels"
;;
*)
err "unsupported OS type: $OSTYPE"
exit 1
;;
esac
var="${dist}_${python}_base_packages[@]"
packages=("${!var}")
if [ $opt_tests_only -eq 0 ]
then
var="${dist}_${python}_extra_packages[@]"
packages+=("${!var}")
fi
"${dist}_bootstrap"
if [ -n "$packages" ]
then
"${dist}_packages_install" "${packages[@]}"
fi
# Update antiquated version of pip on Ubuntu...
run "$python" -m pip install --upgrade --user pip
# Upgrade setuptools, we need at least 19.6 to prevent issues with Cython patched 'build_ext' command.
pip install --upgrade --user 'setuptools>=19.6'
# Manually install Cython if not already to speedup hidapi build.
pip install --user Cython
# Generate requirements.
run "$python" setup.py write_requirements
# Since pip will not build and cache wheels for VCS links, we do it ourselves:
# - first, update the cache (without VCS links), and try to install from it
if ! { pip_cache_requirements && pip_install_requirements; }
then
# - if it failed, try to update the cache again, this time with VCS links
pip_cache_requirements -c requirements_constraints.txt
# - and try again
pip_install_requirements
fi
# vim: foldmethod=marker