-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.sh
executable file
·171 lines (163 loc) · 6.46 KB
/
build.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
#!/bin/bash
# build.sh -- Build myClock from command line
# https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc
# under Windows use git bash in git for Windows https://gitforwindows.org/
APP="myClock"
SRC="$APP.ino"
BIN="$SRC.bin"
RM=`which rm`
PYTHON=`which python`
BOLD='\033[1;34m'
NC='\033[0m'
#default board d1_mini
boardsmanager="http://arduino.esp8266.com/stable/package_esp8266com_index.json"
boardver="esp8266:esp8266:2.6.3"
board="esp8266:esp8266:d1_mini:xtal=160,vt=flash,eesz=4M1M,ip=lm2f,dbg=Disabled,lvl=NoAssert-NDEBUG,wipe=none,baud=921600"
port="8266"
if [[ "$OSTYPE" == "darwin"* ]]; then
arduino="/Applications/Arduino.app/Contents/MacOS/Arduino"
buildpath="$HOME/.build"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
arduino="/c/Program Files (x86)/Arduino/arduino_debug.exe"
buildpath="${USERPROFILE}\.build"
else
arduino="`which arduino`"
if [ -z "$arduino" ]; then
arduino="`find ~/.local /usr -type f -name arduino -print -quit`"
fi
buildpath="$HOME/.build"
fi
if [ -z "$arduino" ]; then
echo "Arduino IDE must be installed" >&2
exit 1
fi
SKETCHBOOK="`\"${arduino}\" --get-pref sketchbook.path 2>/dev/null`"
while getopts ":lvf:s:hcwuo" opt; do
case $opt in
l)
echo -e "Board ${BOLD}lolin32${NC} selected." >&2
boardsmanager="https://dl.espressif.com/dl/package_esp32_index.json"
boardver="esp32:esp32:1.0.2"
board="esp32:esp32:lolin32:PartitionScheme=min_spiffs"
port="3232"
;;
v)
verbose="--verbose"
debug="--debug"
;;
f)
FLASH=$OPTARG
espota="`\"${arduino}\" --get-pref runtime.platform.path 2>/dev/null`/tools/espota.py"
echo "Uploading to $FLASH with $espota" >&2
;;
s)
SER=$OPTARG
esptool="`\"${arduino}\" --get-pref runtime.tools.esptool.path 2>/dev/null`/esptool"
echo "Uploading to $SER with $esptool." >&2
;;
c)
echo -e "${BOLD}Cleaning${NC} ${buildpath}..." >&2
"${RM}" ${verbose} --one-file-system -rf "${buildpath}";;
w)
echo "Wipe entire flash on upload." >&2
board=${board/wipe=none/wipe=all};;
u)
echo -en "${BOLD}`basename $PWD`: ${NC}" && git pull --no-edit
if [ ! -d "$SKETCHBOOK/libraries/ArduinoJson" ]; then
( cd $SKETCHBOOK/libraries/ && git clone https://github.com/bblanchon/ArduinoJson.git -b 5.x )
else
( cd $SKETCHBOOK/libraries/ArduinoJson && echo -en "${BOLD}`basename $PWD`: ${NC}" && git fetch --all && git checkout 5.x -f && git pull --no-edit )
fi
if [ ! -d "$SKETCHBOOK/libraries/Syslog" ]; then
( cd $SKETCHBOOK/libraries/ && git clone https://github.com/arcao/Syslog.git )
else
( cd $SKETCHBOOK/libraries/Syslog && echo -en "${BOLD}`basename $PWD`: ${NC}" && git pull --no-edit )
fi
if [ ! -d "$SKETCHBOOK/libraries/Adafruit-GFX-Library" ]; then
( cd $SKETCHBOOK/libraries/ && git clone https://github.com/adafruit/Adafruit-GFX-Library.git )
else
( cd $SKETCHBOOK/libraries/Adafruit-GFX-Library && echo -en "${BOLD}`basename $PWD`: ${NC}" && git pull --no-edit )
fi
if [ ! -d "$SKETCHBOOK/libraries/PxMatrix" ]; then
( cd $SKETCHBOOK/libraries/ && git clone https://github.com/2dom/PxMatrix.git )
else
( cd $SKETCHBOOK/libraries/PxMatrix && echo -en "${BOLD}`basename $PWD`: ${NC}" && git fetch --all && git reset --hard origin/master && git pull --no-edit )
fi
if [ ! -d "$SKETCHBOOK/libraries/WiFiManager" ]; then
( cd $SKETCHBOOK/libraries/ && git clone https://github.com/tzapu/WiFiManager.git -b development )
else
( cd $SKETCHBOOK/libraries/WiFiManager && echo -en "${BOLD}`basename $PWD`: ${NC}" && git fetch --all && git checkout development -f && git pull --no-edit )
fi
if [ ! -d "$SKETCHBOOK/libraries/DallasTemperature" ]; then
( cd $SKETCHBOOK/libraries/ && git clone https://github.com/milesburton/Arduino-Temperature-Control-Library DallasTemperature )
else
( cd $SKETCHBOOK/libraries/DallasTemperature && echo -en "${BOLD}`basename $PWD`: ${NC}" && git pull --no-edit )
fi
if [ ! -d "$SKETCHBOOK/libraries/OneWire" ]; then
(cd $SKETCHBOOK/libraries/ && git clone https://github.com/PaulStoffregen/OneWire )
else
( cd $SKETCHBOOK/libraries/OneWire && echo -en "${BOLD}`basename $PWD`: ${NC}" && git pull --no-edit )
fi
exit 0;;
o)
echo -e "${BOLD}Select ${boardver}${NC}" >&2
pref="`\"${arduino}\" --get-pref runtime.hardware.path 2>/dev/null`/../../../../preferences.txt"
"${arduino}" --board "${board}" --save-prefs
ret=$?
if [ $ret -ne 0 ]; then
echo -e "${BOLD}Install ${boardver}${NC}" >&2
rm -v $pref
"${arduino}" --pref boardsmanager.additional.urls=${boardsmanager} --save-prefs &>/dev/null
"${arduino}" --install-boards "${boardver}" &>/dev/null
"${arduino}" --board "${board}" --save-prefs
ret=$?
if [ $ret -ne 0 ]; then
echo -e "${BOLD}FAILED! Delete preferences.txt and try again.${NC}" >&2
exit 1
fi
fi
if [[ $board == esp8266* ]]; then
echo -e "${BOLD}Generate boards.txt${NC}" >&2
tools="`\"${arduino}\" --get-pref runtime.platform.path 2>/dev/null`"
( cd $tools && ${PYTHON} ./tools/boards.txt.py --nofloat --boardsgen)
fi
exit 0;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1;;
*)
echo "Usage: build.sh [-l] [-v] [-f IP] [-s /dev/ttyX|COMx] [-h] [-c] [-w]"
echo ""
echo "Build ${APP} and optionally flash device."
echo ""
echo "Options:"
echo -e "\t-l\tBuild for lolin32 instead of d1_mini"
echo -e "\t-v\tUse verbose output"
echo -e "\t-f\tIP address of ${APP} to update"
echo -e "\t-s\tSerial device of ${APP} to update"
echo -e "\t-h\tDisplay usage and exit"
echo -e "\t-c\tClean build directory before building"
echo -e "\t-w\tWipe entire flash, instead of sketch only"
echo -e "\t-u\tUpdate or install required libraries and exit"
echo -e "\t-o\tUpdate or install core and exit\n"
echo "Arduino: $arduino"
echo "Sketchbook: $SKETCHBOOK"
echo "Board: $board"
exit 0;;
esac
done
echo -e "${BOLD}Building ${APP}${NC} in ${buildpath}..." >&2
"${arduino}" ${verbose} --pref build.path="${buildpath}" --board "${board}" --save-prefs --verify ${SRC}
ret=$?
if [ $ret -eq 0 ]; then
if [ -f "$espota" ] && [ ! -z "$FLASH" ]; then
echo "Flashing ${BIN} to ${FLASH}..." >&2
"${PYTHON}" "${espota}" ${debug} --progress --file="${buildpath}/${BIN}" --ip=${FLASH} --port=${port}
elif [ -f "$esptool" ] && [ ! -z "$SER" ]; then
echo "Flashing ${BIN} to ${SER}..." >&2
"${esptool}" -cp ${SER} -cb 921600 -ca 0x0 -cd nodemcu -cf "${buildpath}/${BIN}"
fi
echo "build complete" >&2
else
exit $ret
fi