forked from flutterwireless/ArduinoCodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
240 lines (214 loc) · 5.37 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
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
user=$(who am i | awk '{print $1}') #gets the original user (even if sudo is used)
function main() {
requireSudo
installRequiredPackages
installArmToolchain
fixPortIssue
#copyFlutterLibraryFromBundle #TODO use git instead
#cloneFlutterLibrary #clone flutter from git
buildIDE
if [ $? -eq 0 ]
then
echo
echo "$(tput setaf 2)Success!$(tput sgr0) You are ready to go, use the symbolic link 'arduino' in this folder to launch the IDE."
else
echo
echo "$(tput setaf 1)Failed!$(tput sgr0) The IDE build failed, check the log for more information."
fi
}
function fixPortIssue() {
dpkg -s modemmanager > /dev/null 2>&1
if [[ $? -ne 0 ]]
then
echo " $(tput setaf 2)absent$(tput sgr0) modemmanager"
else
promptYesOrDie "Package modemmanager will cause issues with Arduino USB connection. Remove?"
apt-get purge modemmanager -y
echo " $(tput setaf 2)removed$(tput sgr0) modemmanager"
fi
groups=`groups $user`
if [[ $groups != *"dialout"* ]]
then
echo "$(tput setaf 1)Note:$(tput sgr0) you may need to reboot or relog for this change to take effect!"
promptYesOrDie "You are not part of the dialout group for USB port access. Add group to uucp,dialout?"
usermod -a -G uucp,dialout $user
fi
}
function buildIDE() {
if [ ! -e ./arduino ]
then
sudo -u $user ant -f $SCRIPT_DIR/ArduinoIDEFlutter/build/build.xml
if [ $? -eq 0 ]
then
ln -s $SCRIPT_DIR/ArduinoIDEFlutter/build/linux/work/arduino .
echo " $(tput setaf 2)installed$(tput sgr0) Arduino IDE Symbolic Link"
else
return 1
fi
else
echo " $(tput setaf 2)found$(tput sgr0) Arduino IDE Symbolic Link"
fi
}
function copyFlutterLibraryFromBundle() {
sketchbook=`getSketchbookPath`
librariesFolder="$sketchbook/libraries"
sudo -u $user mkdir -p $librariesFolder
flutterFolder="$librariesFolder/Flutter"
if [ -e "$flutterFolder" ]
then
echo " $(tput setaf 2)found$(tput sgr0) Flutter Arduino Library"
else
promptYesOrDie "The Flutter library for Arduino will be copied into $librariesFolder."
echo " $(tput setaf 4)installing$(tput sgr0) Flutter"
sudo -u $user cp -r $SCRIPT_DIR/Flutter $librariesFolder/
fi
}
function cloneFlutterLibrary() {
flutterGit=:"" #TODO fill me
sketchbook=`getSketchbookPath`
librariesFolder="$sketchbook/libraries"
flutterFolder="$librariesFolder/Flutter"
if [ -e "$flutterFolder" ]
then
echo " $(tput setaf 2)found$(tput sgr0) Flutter Arduino Library"
else
promptYesOrDie "The Flutter library for Arduino will be cloned into $librariesFolder."
echo " $(tput setaf 4)installing$(tput sgr0) Flutter"
sudo -u $user git clone $flutterGit
fi
}
function requireSudo() {
if [[ $EUID -ne 0 ]]
then
echo "This script must be run as root, re-run with sudo"
exit 1
fi
}
function promptYesOrDie() {
read -p "$1 (y) " choice
if [ -n "$choice" ]
then
case "$choice" in
y|Y ) return;;
n|N ) echo "Setup terminated";exit;;
* ) echo "Invalid response, setup terminated.";exit;;
esac
fi
}
function installArmToolchain() {
dpkg -s gcc-arm-none-eabi > /dev/null 2>&1
if [[ $? -ne 0 ]]
then
repo=ppa:terry.guo/gcc-arm-embedded
echo "Flutter requires the ARM toolchain."
echo "To install it, $repo will be added to your sources.lst"
promptYesOrDie "Install the ARM toolchain?"
echo " $(tput setaf 4)installing$(tput sgr0) gcc-arm-none-eabi"
add-apt-repository $repo
apt-get update
apt-get install gcc-arm-none-eabi -y
else
echo " $(tput setaf 2)found$(tput sgr0) gcc-arm-none-eabi"
fi
}
MACHINE_ARCHITECTURE=`uname -m`
if [ "$MACHINE_ARCHITECTURE" == 'x86_64' ]
then
packages=$(cat << EOF
javac openjdk-7-jdk
git git
ant ant
- lib32z1
- lib32ncurses5
- lib32bz2-1.0
EOF
)
else
packages=$(cat << EOF
javac openjdk-7-jdk
git git
ant ant
EOF
)
fi
function installRequiredPackages() {
IFS='
'
echo "Checking for required packages.."
local i=0 installList=()
for line in $packages
do
cmd=${line%% *}
pkg=${line##* }
if [[ "$cmd" == "-" ]]
then
cmd=$pkg
dpkg -s $pkg > /dev/null 2>&1
else
command -v $cmd >/dev/null 2>&1
fi
if [[ $? -gt 0 ]]
then
echo " $(tput setaf 1)missing$(tput sgr0) $cmd"
installList="$installList $pkg"
installList[$i]="$pkg"
((++i))
else
echo " $(tput setaf 2)found$(tput sgr0) $cmd"
fi
done
if [ ${#installList[@]} -ne 0 ]
then
promptYesOrDie "${#installList[@]} packages will be installed: ${installList[@]}"
eval apt-get install --yes ${installList[@]}
fi
}
arduinoPreferenceLocations=$(cat << EOF
${HOME}/.arduino/preferences.txt
${HOME}/.arduino15/preferences.txt
${HOME}/Library/Arduino/preferences.txt
EOF
)
function getSketchbookPath() {
preferenceFile=''
found=0
for loc in `echo $arduinoPreferenceLocations`
do
if [ -e "$loc" ]
then
preferenceFile=$loc
found=1
fi
done
sketchbookPath=''
if [[ $found -eq 1 ]]
then
sketchbookPath=`grep sketchbook.path $preferenceFile`
sketchbookPath=${sketchbookPath##*=}
if [ ! -d "$sketchbookPath" ]
then
sketchbookPath=''
else
echo $sketchbookPath;
fi
fi
if [ -z "$sketchbookPath" ]
then
>&2 echo "Unable to detect sketchbook folder."
default="/home/$user/Arduino"
read -p "Enter sketchbook path to use ($default): " path 1>&2
if [ -z "$path" ]
then
path=$default
fi
if [ ! -d "$path" ]
then
promptYesOrDie "Sketchbook folder ($path) doesn't exist, create it?"
sudo -u $user mkdir -p $path
fi
echo $path
fi
}
main