-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·370 lines (306 loc) · 10.5 KB
/
install.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
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
#!/bin/bash
# Welcome! This is our lame attempt at creating an installer pacakge
# for the Press Every Key Toolchain. It should alert you to any missing
# packages which we can't install automatically, download the compiler
# and check out our SDK from github and get everything ready for you.
# rudimentary test to check whether the first argument passed is
# an available executable.
function check() {
if ! check_no_die ${1} ; then
echo "Please install '${1}' and rerun this script!"
cd $CURRENT_DIR
exit 1
fi
}
function check_no_die() {
if ! command -v ${1} 2>&1 > /dev/null ; then
return 1
fi
return 0
}
# sets a variable `OS` to either OSX, WIN or LIN if
# we can determine the operating system and exits if
# we can't.
function check_os() {
uname=`uname`
case ${uname} in
*Darwin*)
OS="OSX"
;;
*CYGWIN*)
OS="WIN"
;;
*Linux*)
OS="LIN"
;;
*)
echo "Sorry we can't support (or determine) your operating system : ${uname}"
cd $CURRENT_DIR
exit 1
;;
esac
}
# Tries to determine is curl or wget are installed and configures them
# as the default to use for use.
function set_download_cmd() {
if ! check_no_die curl ; then
if ! check_no_die wget; then
echo "Please install 'wget' or 'curl'"
exit 1
fi
DOWNLOAD_COMMAND='wget --no-check-certificate'
return
fi
DOWNLOAD_COMMAND='curl -L -O'
}
# Download the GNU ARM embedded compilers. The URLs contained with here
# need to be updated periodically.
# https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-mac.tar.bz2
ARM_DIR="gcc-arm-none-eabi-4_9-2014q4"
ARM_ARCHIVE="${ARM_DIR}-20141203-"
ARM_NONE_URL='https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download'
function get_arm() {
echo "Installing compiler ..."
case $OS in
"OSX")
SUFFIX='mac.tar.bz2'
;;
"WIN")
SUFFIX='win32.zip'
;;
"LIN")
SUFFIX='linux.tar.bz2'
;;
*)
echo "Sorry your OS (${1}) is not supported or we couldn't determine it."
cd $CURRENT_DIR
exit 1
;;
esac
ARM_ARCHIVE=${ARM_ARCHIVE}${SUFFIX}
cd $INSTALL_DIR
# check already downloaded ?
if [[ ! -f ${ARM_ARCHIVE} ]]; then
$DOWNLOAD_COMMAND ${ARM_NONE_URL}/${ARM_ARCHIVE}
else
echo "Found '${ARM_ARCHIVE}'!"
echo "Activating recovery mode :)"
echo
echo "(We're probably here because our script screwed up previously"
echo " so we don't really know what's going on and will just unpack"
echo " the compiler again, clobbering any previously unpacked"
echo " compiler."
echo " Press S to skip unpacking, Q to quit the script or anything"
echo " else to continue"
echo
echo "If you don't know what this means, hit enter"
read WHAT_TO_DO
if [[ ${WHAT_TO_DO}X == "SX" ]] ; then
echo
return
else
if [[ ${WHAT_TO_DO}X == "QX" ]] ; then
echo "Quitting! Sorry things didn't work out ... "
cd $CURRENT_DIR
exit 1
fi
fi
fi
echo "Unpacking ..."
case $OS in
"WIN")
check "unzip"
unzip $ARM_ARCHIVE
;;
*)
# I hope it's safe to assume that any linux, osx or cygwin install
# will have a sane tar:
tar -xjf ${ARM_ARCHIVE}
;;
esac
echo "... done\n"
}
REPO_BASENAME='everykey-sdk'
function check_out_repo() {
echo "Checking out the SDK files from github..."
cd $INSTALL_DIR
if [[ -d $REPO_BASENAME ]]; then
sleep 0.25
echo "It seems that the SDK was already checked out."
else
git clone https://github.com/presseverykey/${REPO_BASENAME}.git
fi
echo "... done\n"
}
function link_proper_checksum() {
# check for gcc and compile if present!
CHECKSUM_DIR="$INSTALL_DIR/${REPO_BASENAME}/checksum"
if check_no_die "gcc"; then
cd $CHECKSUM_DIR
make
# TODO test $?, explode if compile fails ...
else
case $OS in
"OSX")
CHECKSUM_SUFFIX="mac"
;;
"WIN")
CHECKSUM_SUFFIX="win"
;;
"LIN")
CHECKSUM_SUFFIX="linux"
;;
esac
cp $CHECKSUM_DIR/checksum.${CHECKSUM_SUFFIX} $CHECKSUM_DIR/checksum
# TODO maybe some sort of test to make sure checksum runs ... ?
fi
}
function set_path() {
echo "We've installed the compiler and SDK for you. The compiler and"
echo "a utility program in the SDK need to be placed into your \$PATH"
echo "variable, so the shell will know where to find these programs."
echo
echo "You will need to execute the following lines the shell before using"
echo "the SDK in future:"
echo
echo " #############################################################"
echo " # Adjust the PATH for the ARM toolchain #"
echo " # either add this to your .profile or run these commands #"
echo " # manually before you compile firmware #"
echo " # if you find this in your .profile and don't want it there #"
echo " # just delete up to the next comment block #"
echo " #############################################################"
echo
echo " export PATH=\$PATH:${INSTALL_DIR}/${REPO_BASENAME}/checksum"
echo " export PATH=\$PATH:${INSTALL_DIR}/${ARM_DIR}/bin"
echo
echo " #############################################################"
echo " # END OF ARM/EVERYKEY PATH ADJUSTMENTS #"
echo " #############################################################"
echo
if [[ -f ~/.profile ]]; then
echo "If you like, I can also add the above to your .profile"
echo
echo "This is somewhat experimental, i.e. if you also have a"
echo ".bash_profile, aren't using bash or doing one of a million"
echo "unforseeable things that we haven't dealt with (we're looking"
echo "at you, gentoo users), this may not work! CAVEAT EMPTOR!"
echo
echo "(If you don't know what this means, you should google"
echo " it or just type Y) :"
read ADD_TO_PROFILE
echo
if [[ ${ADD_TO_PROFILE}X == "YX" ]]; then
echo >> ~/.profile
echo "$SET_PATH" >> ~/.profile
# Have to admit, it's a bit lazy to copy and paste here, but I couldn't
# figure out how to get cygwin to handle line endings properly ...
echo "#############################################################" >> ~/.profile
echo "# Adjust the PATH for the ARM toolchain #" >> ~/.profile
echo "# either add this to your .profile or run these commands #" >> ~/.profile
echo "# manually before you compile firmware #" >> ~/.profile
echo "# if you find this in your .profile and don't want it there #" >> ~/.profile
echo "# just delete up to the next comment block #" >> ~/.profile
echo "#############################################################" >> ~/.profile
echo >> ~/.profile
echo "export PATH=\$PATH:${INSTALL_DIR}/${REPO_BASENAME}/checksum" >> ~/.profile
echo "export PATH=\$PATH:${INSTALL_DIR}/${ARM_DIR}/bin" >> ~/.profile
echo >> ~/.profile
echo "#############################################################" >> ~/.profile
echo "# END OF ARM/EVERYKEY PATH ADJUSTMENTS #" >> ~/.profile
echo "#############################################################" >> ~/.profile
echo >> ~/.profile
echo "PATH adjustments were made to your '.profile'. You may need to"
echo 'log in again or run `exec bash --login` for these settings to take'
echo "effect"
else
echo "Leaving your .profile alone... Don't forget to manually"
echo "set up the PATH"
fi
else
echo "Couldn't find a .profile in your home directory, so you're"
echo "probably using some other mechanism to configure your shell."
echo "You will need to manually adjust the PATH like above. Sorry!"
fi
echo
}
# Windows speciality... we make heavy use of symlinks in the SDK. Unfortunately,
# the cygwin/windows/git combination isn't quite compatible, so for windows users,
# we delete all the symlinks in the examples an copy in the necessary files...
function urgh_deal_with_symlinks() {
echo "The SDK makes heavy use of symbolic links. Unfortunately, the combination"
echo "of cygwin, git and windows doesn't really like that ..."
echo "I can try to replace all symlinks in the SDK with the actual files now"
echo "or you can do this yourself."
echo "Press S to skip, just hit enter to replace the symlinks."
read WHAT_TO_DO
if [[ ${WHAT_TO_DO}X == "SX" ]] ; then
echo
return
fi
for a_file in makefile lpc1343.ld ; do
for ff in `find $INSTALL_DIR/${REPO_BASENAME} -name ${a_file} -type l` ; do
rm $ff
cp $INSTALL_DIR/${REPO_BASENAME}/everykey/${a_file} $ff
done
done
for a_file in everypio.h everypio.c ; do
for ff in `find $INSTALL_DIR/${REPO_BASENAME} -name ${a_file} -type l` ; do
rm $ff
cp $INSTALL_DIR/${REPO_BASENAME}/libs/everypio/${a_file} $ff
done
done
for a_file in everycdc.h everycdc.c ; do
for ff in `find $INSTALL_DIR/everykey-sdk -name ${a_file} -type l` ; do
rm $ff
cp $INSTALL_DIR/${REPO_BASENAME}/libs/everycdc/${a_file} $ff
done
done
for a_dir in everykey everykey_usb ; do
for ff in `find $INSTALL_DIR/${REPO_BASENAME} -name ${a_dir} -type l`; do
rm -rf $ff
cp -r $INSTALL_DIR/${REPO_BASENAME}/${a_dir} $ff
done
done
}
if check_no_die clear ; then
clear
fi
echo "Welcome to the Everykey Toolchain Installer!"
check_os
check "git"
check "make"
set_download_cmd
CURRENT_DIR=`pwd`
INSTALL_DIR=`pwd`
echo "Where would you like to install the toolchain [${INSTALL_DIR}] ?"
read new_install_dir
if [[ ${new_install_dir}X != "X" ]] ; then
INSTALL_DIR=$new_install_dir
fi
sleep 0.25
if [ -d $INSTALL_DIR ]; then
echo "installing to: ${INSTALL_DIR}"
else
echo "not a valid directory: ${INSTALL_DIR}"
exit 1
fi
sleep 0.25
cd $INSTALL_DIR
get_arm
check_out_repo
link_proper_checksum
set_path
if [[ "$OS" == "WIN" ]] ; then
urgh_deal_with_symlinks
fi
cd $CURRENT_DIR
echo "Done! (You're welcome.)"
echo
echo "In order to try out the SDK, set the PATH correctly"
echo "as described above, change to the directory:"
echo " $INSTALL_DIR/${REPO_BASENAME}/examples/blink"
echo 'and type `make`.'
echo
echo "Press EVERYKEY to continue..."
read