-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·205 lines (152 loc) · 6.15 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
#!/bin/bash
#if [ -n "$1" ]; then
# if [$1 = 'clean'] ; then
# rm -rf $ARDMK_DIR $ARDUINO_DIR $ESP_ROOT
# fi
# exit 0
#fi
if [ "$(uname -s)" = 'Linux' ]; then
REPOSITORY=$(dirname $(readlink -f "$BASH_SOURCE"))
else
REPOSITORY="$(cd "$(dirname "$(readlink "$BASH_SOURCE")")"; pwd)"
fi
PROFILE="/home/boris/.profile"
BASHRC="/home/boris/.bashrc"
ZSHRC="/home/boris/.zshrc"
# Download and install Aduino IDE if it is not already installed
if [ -z "$ARDUINO_DIR" ]; then # ifndef ARDUINO_DIR
# Download Arduino IDE
case $(uname -m) in
i686 ) OS=linux32;;
x86_64 ) OS=linux64;;
arm* ) OS=linuxarm;;
* ) exit 1;;
esac
if [ "$(uname -s)" = 'Linux' ]; then
ARDUINO_URL=https://downloads.arduino.cc/arduino-1.6.12-$OS.tar.xz
ARDUINO_TAR=$(basename "$ARDUINO_URL")
wget "$ARDUINO_URL" -O "$ARDUINO_TAR"
# Install Arduino IDE
ARDUINO_SRC=$(tar -tf "$ARDUINO_TAR" | head -1)
ARDUINO_SRC=${ARDUINO_SRC%/} # Remove trailing '/'
tar -xvf "$ARDUINO_TAR"
rm "$ARDUINO_TAR"
sudo mv "$ARDUINO_SRC" /opt
echo export ARDUINO_DIR="/opt/$ARDUINO_SRC" >> "$PROFILE"
# Launch Arduino IDE and give it time to settle in
"/opt/$ARDUINO_SRC/arduino" &
sleep 10
pkill -n java
else
ARDUINO_URL=https://downloads.arduino.cc/arduino-1.6.12-macosx.zip
ARDUINO_TAR=$(basename "$ARDUINO_URL")
wget "$ARDUINO_URL" -O "$ARDUINO_TAR"
# Install Arduino IDE
ARDUINO_APP=$(tar -tf "$ARDUINO_TAR" | head -1)
ARDUINO_APP=${ARDUINO_APP%/} # Remove trailing '/'
ARDUINO_SRC=${ARDUINO_APP%.app} # Remove '.app'
tar -xvf "$ARDUINO_TAR"
rm "$ARDUINO_TAR"
sudo mv "$ARDUINO_APP" /Applications
echo export ARDUINO_DIR="/Applications/$ARDUINO_SRC" >> "$PROFILE"
# Launch Arduino IDE and give it time to settle in
open -a "/Applications/$ARDUINO_APP" &
sleep 10
pkill -n Arduino
fi
fi # ifndef ARDUINO_DIR
ARDUINO_DIR = "/opt/arduino-1.6.12/"
# Install ESP-32 driver for Arduino IDE
if [ -z "$ESP_ROOT" ] ; then
if [ "$(uname -s)" = 'Linux' ] ; then
mkdir "/opt/arduino-1.6.12/hardware/espressif"
cd "/opt/arduino-1.6.12/hardware/espressif"
git clone https://github.com/espressif/arduino-esp32.git esp32
cd esp32
git submodule update --init --recursive && \
cd tools
python get.py
echo export ESP_ROOT="/opt/arduino-1.6.12/hardware/espressif/esp32" >> "$PROFILE"
echo export PYTHONPATH="$REPOSITORY/raspberrypi/:\$PYTHONPATH" >> "$BASHRC"
else
mkdir -p ~/Documents/Arduino/hardware/espressif && \
cd ~/Documents/Arduino/hardware/espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python get.py
echo export ESP_ROOT="~/Documents/Arduino/hardware/espressif/esp32" >> "$PROFILE"
echo export PYTHONPATH="$REPOSITORY/raspberrypi/:\$PYTHONPATH" >> "$BASHRC"
#manage default zsh shell case on macos catalina
echo export "source ~/.bashrc" >> "$ZSHRC"
echo export "source ~/.profile" >> "$ZSHRC"
#install esptool.py to correct mac os esp32 error
pip install esptool
sudo mv $ESP_ROOT/tools/esptool.py $ESP_ROOT/tools/esptool
fi
fi
# Install Arduino-Makefile if it is not already installed
if [ -z "$ARDMK_DIR" ]; then # ifndef ARDMK_DIR
if [ "$(uname -s)" = 'Linux' ]; then
sudo apt-get install arduino-mk
sudo apt-get install python-serial
sudo apt-get install python3-serial
sudo apt-get install libigraph0-dev
sudo apt-get install python3-pip
sudo apt-get install zlib1g-dev
sudo apt-get install libxml2-dev
sudo pip3 install python-igraph
sudo pip3 install transformations
sudo apt-get install doxygen
sudo apt-get install texlive-font-utils
echo export ARDMK_DIR="/usr/share/arduino" >> "$PROFILE"
else
# installing homebrew for macos
#/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# add tap
brew tap sudar/arduino-mk
# to install the last stable release
brew install arduino-mk
echo export ARDMK_DIR="/usr/local/opt/arduino-mk" >> "$PROFILE"
sudo sed -i "" "s_/dev/tty.usbserial*__g" "$ARDMK_DIR/Arduino.mk"
sudo easy_install pip
pip install pyserial
pip3 install pyserial
pip3 install python-igraph
pip3 install exhale
pip3 install sphinx-rtd-theme
fi
fi
if [ "$(uname -s)" = 'Linux' ]; then
# Add the current user to the dialout group
# Install udev rules
PYTHONPATH=$(python3 -m site --user-site)
UDEVRULES_DIRECTORY=/etc/udev/rules.d
UDEVRULE='KERNEL=="ttyUSB*", PROGRAM="/usr/bin/env PATH='"$PATH"' PYTHONPATH='"$PYTHONPATH:$REPOSITORY/raspberrypi/"' '"$REPOSITORY/raspberrypi/robot getuuid"' /dev/%k", SYMLINK+="arduino/%c" \nKERNEL=="ttyACM*" , PROGRAM="/usr/bin/env PATH='"$PATH"' PYTHONPATH='"$PYTHONPATH:$REPOSITORY/raspberrypi/"' '"$REPOSITORY/raspberrypi/robot getuuid"' /dev/%k", SYMLINK+="arduino/%c" '
if [ ! -e "$UDEVRULES_DIRECTORY/serialtalks.rules" ] ; then
sudo usermod -a -G dialout $USER
echo -e $UDEVRULE | sudo tee "$UDEVRULES_DIRECTORY/serialtalks.rules" > /dev/null
sudo udevadm control --reload-rules
fi
else
git clone https://github.com/clubrobot/SerialRenamerDaemon.git
cd SerialRenamerDaemon
sudo make install
fi
# Add the robot command to the user path if it is not already in it
if [ "$(uname -s)" = 'Linux' ]; then
if [[ ":$PATH:" != *":$REPOSITORY/raspberrypi:"* ]]; then # if not **/team-2017/raspberrypi in PATH
echo export PATH="$REPOSITORY/raspberrypi:\$PATH" >> "$PROFILE"
fi
else
if [[ "$(cat /etc/paths)" != *":$REPOSITORY/raspberrypi:"* ]]; then
echo $REPOSITORY/raspberrypi | sudo tee -a /etc/paths
sudo launchctl unload /Library/LaunchDaemons/fr.insa-rennes.clubrobot.serialrenamerd.plist
sudo sed -i "" "s_REPOSITORY_$REPOSITORY/raspberrypi_g" /Library/LaunchDaemons/fr.insa-rennes.clubrobot.serialrenamerd.plist
sudo launchctl load /Library/LaunchDaemons/fr.insa-rennes.clubrobot.serialrenamerd.plist
fi
fi
# A reboot is required to source the .profile file
echo "My work here is done. Now it is time for me to retire."
echo "Please reboot your computer to take the changes into account"