-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-build-env.sh
executable file
·166 lines (137 loc) · 4.35 KB
/
setup-build-env.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
#!/bin/bash
# enable following two line to make it run line by line --> for debugging only
#set -x
#trap read debug
# Check if we're root and re-execute if we're not.
rootcheck () {
if [ $(id -u) != "0" ]
then
echo "!! We require root permissions, restarting with SUDO ..."
echo ""
echo ""
sudo "$0" "$@" # Modified as suggested below.
exit $?
else
echo "-> Ok, we have root permissions."
fi
}
printCheckmark() {
echo -e "\xe2\x9c\x93"
echo ""
}
updateLibrary () {
echo -n "-> Copy $PROJECT_DIR to sketchbook libraries ";
mkdir -p $ARDUINO_LIB_DIR/MYLIBRARY
rsync -avzq --exclude 'Arduino' --exclude 'arduino-cli-build' --exclude 'bin' --exclude '.arduino15' $PROJECT_DIR $ARDUINO_LIB_DIR/MYLIBRARY
printCheckmark;
}
echo "========================================"
echo "Setup Arduino Build Environment "
echo "========================================"
echo
#rootcheck
# make this script expand alias, see alias usage below...
shopt -s expand_aliases
WORKING_DIR="${CI_PROJECT_DIR:-./arduino-cli-build}"
echo "-> WORKING_DIR : $WORKING_DIR"
PROJECT_DIR=$1
if [ -z $1 ]; then
PROJECT_DIR=".";
fi
echo "-> PROJECT_DIR : $PROJECT_DIR"
ARDUINO_DIR=$WORKING_DIR/Arduino
ARDUINO_LIB_DIR=$ARDUINO_DIR/libraries
ARDUINO_15_DIR=$WORKING_DIR/.arduino15
ARDUINO_CLI_DIR=$WORKING_DIR/arduino-cli
PATH="$ARDUINO_CLI_DIR:$PATH"
if [ -e $ARDUINO_CLI_DIR ]; then
echo "existing setup in $ARDUINO_CLI_DIR detected. Just updateing library"
updateLibrary;
exit;
fi
#echo -n "-> Cleanup old stuff "
#rm -Rf $WORKING_DIR
#printCheckmark
# setup the build environment:
# * install required command line tools like rsync and curl
# * install Arduino CLI
# * install boards
# * install required Arduino libs (may be something more than we really need, but this does not hurt)
# install CURL command to be able to install Arduino CLI
if [ -z $(which rsync) ] && [ -z $(which curl) ]; then
echo "-> APT update and install curl+rsync "
if [ $(id -u) != "0" ]; then
# not root, need sudo
sudo apt-get -q -q update
sudo apt-get -y -q -q install curl rsync
else
apt-get -q -q update
apt-get -y -q -q install curl rsync
fi
else
echo -n "-> curl+rsync detected "
fi
printCheckmark
# install Arduino CLI
echo "-> Install Arduino CLI ..."
mkdir -p $ARDUINO_CLI_DIR
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=$ARDUINO_CLI_DIR sh
echo -n "-> Install Arduino CLI "; printCheckmark;
# make local arduino folders and preferences, preferences will be used by ALIAS command, see 'before_script' above
echo -n "-> Configure Arduino CLI "
mkdir -p $ARDUINO_DIR
mkdir -p $ARDUINO_15_DIR
# write preference file
cat >$ARDUINO_CLI_DIR/arduino-cli.yaml <<EOF
board_manager:
additional_urls: []
daemon:
port: "50051"
directories:
data: ${ARDUINO_15_DIR}
downloads: ${ARDUINO_15_DIR}/staging
user: ${ARDUINO_DIR}
logging:
file: ""
format: text
level: info
EOF
# create an alias to not apply config file argument every time
alias arduinocli="$ARDUINO_CLI_DIR/arduino-cli --config-file $ARDUINO_CLI_DIR/arduino-cli.yaml"
printCheckmark;
# make our project available as library for Arduino
updateLibrary;
# show config
echo "-> Arduino CLI config dump: "
arduinocli config dump
# update core board index
echo "-> Update Core index"
arduinocli core update-index
# install UNO/Leonardo/...
#echo "-> Install Arduino AVR core"
#arduinocli core install arduino:avr
# install SAMD core
echo "-> Install SAMD core"
arduinocli core install arduino:samd
# install ESP8266 core
#echo "-> Install Arduino ESP8266 core"
#arduinocli core update-index --additional-urls "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
#arduinocli core install esp8266:esp8266 --additional-urls "https://arduino.esp8266.com/stable/package_esp8266com_index.json"
# list installed cores and boards
echo "-> Installed cores: "
arduinocli core list
echo ""
echo -n "-> Installing cores "; printCheckmark;
echo "-> Installed boards: "
arduinocli board listall
echo ""
echo -n "-> Installing boards "; printCheckmark;
# install libs
#echo "-> Installing libs ..."
#arduinocli lib install "FlashStorage"
#echo -n "-> Installing libs "; printCheckmark;
# list libs
echo "-> List of installed libs: "
arduinocli lib list
echo ""
echo -n "-> Setup Arduino Build Environment "; printCheckmark;