-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·249 lines (200 loc) · 6.48 KB
/
setup.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
#!/usr/bin/env bash
help () {
cat <<EOF
=== INTRO ===
This script:
1. Installs Sloeber (Eclipse For Arduino)
2. Checks out Prusa MK2 Firmware
3. Prepares all libraries and guide you during further configuration.
The parameter --sandbox points by default to paren directory where you checked out ths 'project'.
Example:
mysandbox/PrusaMK2Eclipse/setup.sh
mysandbox/soeber <- eclipse installation
mysandbox/soeber-workspace <- eclipse workspace
mysandbox/Prusa-Firmware <- Firmware from github
Additionally the following directories are used:
~/Download <- where sloeber archive will be saved
~/Arduino/libraries <- where we install LiquidTWI2 library
Please be aware: this two directories are outside of your sanbox and will be modified permanently.
=== Human Interface ===
Script guides you through installtion showing two types of messages:
INFO:.... <- expalantion wat is beeing done, where you seat back and pray
COMMAND:... <- call to action, request what YOU must execute and confirm
=== Error Handling and Retry ===
If ccript is interupted (Ctrl-C) or ends with unexpected error, it can be startet simply again.
Through cheking of preconditions, it tries to continue where break occured.
If nothing helps, please panick and remove your sanbox, then try again.
Example: $0 -sandbox path
Parameters:
--help|-h : show this help
--trace|-t : trace script
--sandbox|-s : target path to your sandbox
EOF
}
#set -o xtrace
set -o errexit
set -o nounset
#set -o pipefail
__start_dir=`pwd`
__install="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#----------------------------------------------------------------
# Exit script always in the same directory where it was started
# Show ERROR warning if anny error occurred, do not show if Crl-C was pressed.
#----------------------------------------------------------------
cleanup() {
# 130 is Ctrl-C
if [[ $? -ne 0 && $? -ne 130 ]]; then
echo "Exit status: $?";
cat <<'EOF'
______ _____ _____ ____ _____
| ____| __ \| __ \ / __ \| __ \
| |__ | |__) | |__) | | | | |__) |
| __| | _ /| _ /| | | | _ /
| |____| | \ \| | \ \| |__| | | \ \
|______|_| \_\_| \_\\____/|_| \_\
EOF
fi
cd $__start_dir
}
trap cleanup EXIT
#
# some utlity functions
#
qpushd() {
pushd $@ 1>/dev/null
}
qpopd() {
popd $@ 1>/dev/null
}
inf() {
printf "INFO : $@ \n"
}
die() {
printf "ERROR : $@ \n"
exit 1
}
cmd() {
printf "COMMAND : $@ - continue? [Y/n]"
read answer
case "${answer:-y}" in
"Y"|"y")
;;
*)
inf "exiting on demand"
exit 0;
esac
}
P_HELP="";
P_TRACE="";
P_SANDBOX=`cd ${__install}/..; pwd`
while [[ $# -gt 0 ]]
do
NEXT_PARAMETER=$1
case "$NEXT_PARAMETER" in
"--help"|"-h")
P_HELP=true;
;;
"--trace"|"-t")
P_TRACE=true
;;
"--sandbox"|"-s")
P_SANDBOX=$2
shift
;;
*)
echo "ERROR: Unsupported parameter '$NEXT_PARAMETER'\n\n"
exit -1;
;;
esac
shift
done;
if [[ "$P_HELP" = true ]]; then
help
exit 0
fi
if [[ "$P_TRACE" = true ]]; then
set -x
fi
# check if sanbox exists, if not, exit
if [[ ! -d $P_SANDBOX ]]; then
die "Directory '$P_SANDBOX' not found.";
fi
qpushd $P_SANDBOX
# install sloeber if not found
if [[ ! -e "sloeber" ]]; then
inf "installing sloeber"
githubUrl="https://github.com"
#TODO: determine platform, assumin 64 bit
sloeberReleaseUrl=`curl -s ${githubUrl}/Sloeber/arduino-eclipse-plugin/releases/ | perl -ne 'if ( /href="(.*?\/releases\/download\/.*?linux64.*?)"/ ) { print "$1\n"; exit 0; };'`
sloeberArchiveName=`basename $sloeberReleaseUrl`;
qpushd ~/Downloads
if [[ ! -e $sloeberArchiveName ]]; then
wget ${githubUrl}${sloeberReleaseUrl}
else
inf "using existing archive ~/Downloads/${sloeberArchiveName}"
fi
qpopd
tar -xvzf ~/Downloads/$sloeberArchiveName
else
inf "$P_SANDBOX/sloeber alreday exists, continue with old installation"
fi
if [[ ! -e Prusa-Firmware ]]; then
git clone https://github.com/prusa3d/Prusa-Firmware.git
qpushd Prusa-Firmware/Firmware
#TODO: assuming variant RAMBo13a
cp variants/1_75mm_MK2-RAMBo13a-E3Dv6full.h Configuration_prusa.h
qpopd
fi
qpopd
# last Sloeber release has a bug, apply clean up workaround for IndexOutOfBound Exception
cleanUpOldLibs() {
if [[ -e $P_SANDBOX/sloeber/arduinoPlugin/libraries ]]; then
qpushd $P_SANDBOX/sloeber/arduinoPlugin/libraries
for nextLib in `ls -1`; do
if [[ `ls $nextLib | wc -l` -eq 0 ]]; then
inf "Removing empty directory $nextLib";
rmdir $nextLib
fi
done
qpopd
fi
}
cleanUpOldLibs;
inf "Starting sloeber, wait until android plugin is installed."
$P_SANDBOX/sloeber/sloeber-ide -data $P_SANDBOX/sloeber-workspace 2>/dev/null &
cmd "Are all downloads finished?"
if [[ ! -e $P_SANDBOX/sloeber/arduinoPlugin/packages/rambo ]]; then
inf "Rambo hardware not registered yet."
cmd "Open Arduino->Preferences->Third party index URL's and paste additional URL: \nhttps://raw.githubusercontent.com/ultimachine/ArduinoAddons/master/package_ultimachine_index.json"
cmd "Open Arduino->Platforms and Boards and select rambo->RepRap..->1.0.1"
fi
# install libs under rambo hardware to link them automatically
mkdir -p ~/Arduino/libraries
qpushd ~/Arduino/libraries
if [[ ! -e LiquidTWI2 ]]; then
inf "checking out LiquidTWI2"
git clone https://github.com/lincomatic/LiquidTWI2.git
fi
qpopd
qpushd $P_SANDBOX/sloeber/arduinoPlugin/packages
if [[ ! -e rambo/hardware/avr/1.0.1/libraries/SPI ]]; then
cp -r arduino/hardware/avr/1.6.20/libraries/SPI rambo/hardware/avr/1.0.1/libraries/
fi
if [[ ! -e rambo/hardware/avr/1.0.1/libraries/Wire ]]; then
cp -r arduino/hardware/avr/1.6.20/libraries/Wire rambo/hardware/avr/1.0.1/libraries/
fi
if [[ ! -e rambo/hardware/avr/1.0.1/libraries/LiquidTWI2 ]]; then
ln -s ~/Arduino/libraries/LiquidTWI2 rambo/hardware/avr/1.0.1/libraries/LiquidTWI2
fi
qpopd
cmd "\n\
1. In Arduino->Preferences->LibraryManager->Display switch LiquidCristal off and LiquideCrystal_I2C on.\n\
2. If you can't confirm a dialog, close sloeber and start this script again."
cleanUpOldLibs;
cmd "\n\
1. Create new Arduino Sketch named \"Firmware\" located exactly in $P_SANDBOX/PrusaMK2/Prusa-Firmware/Firmware\n\
2. Choose rambo as a platform.\n\
3. Choose \"Default ino file\" as template, it will not overwrite exiting one.\n\
4. Go to Arduino->Add Libary to sleected Project, add LiquideCrystal_I2C.\n\
4. Now you are done. You should be able to build the firmware and navigate the code.";
inf "HINT: Start sloeber ar any time using command: $P_SANDBOX/sloeber/sloeber-ide -data $P_SANDBOX/sloeber-workspace"