-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·104 lines (91 loc) · 1.95 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
#!/bin/bash
function err {
>&2 red "[ERROR] "$@
}
function red {
echo -en "\033[31m" ## red
echo $@
echo -en "\033[0m" ## reset color
}
function help() {
echo "$0 [options] [build|upload|all]"
echo ""
echo "build build the code (default action)"
echo "upload upload the code"
echo "all build and upload if build is success"
echo ""
echo "-h show this help"
echo "-b <board> set board (default=arduino:avr:mega:cpu=atmega2560)"
echo "-p <port> set port (default=/dev/ttyARDUINO_MEGA)"
echo "-m <mode> set mode (GT/GTM) **REQUIRED** to set"
}
: ${ARDUINO_BOARD:="arduino:avr:mega:cpu=atmega2560"}
: ${ARDUINO_PORT:="/dev/ttyARDUINO_MEGA"}
: ${ARDUINO_MODE:=} # mode should be specified
board=$ARDUINO_BOARD
port=$ARDUINO_PORT
mode=$ARDUINO_MODE
zip=0
while getopts "hb:p:m:z" arg; do
case $arg in
h)
help
exit
;;
b)
board=$OPTARG
;;
p)
port=$OPTARG
;;
m)
mode=$OPTARG
;;
z)
zip=1
;;
esac
done
shift $((OPTIND-1))
target=$1
if [ -z $target ]; then
target=build
fi
if [[ $zip -eq 1 ]]; then
target=build
fi
function build() {
echo "check version..."
./version.sh
echo "building..."
com="arduino-cli compile -b $board --build-property build.extra_flags=\"-D$mode\" ."
if [[ $zip -eq 1 ]]; then
echo $com
eval $com
else
sketchname="$(basename `pwd`)-$mode-$(cat version.txt)"
com="$com --output-dir /tmp/$sketchname"
echo $com
eval $com
zip -r ${sketchname}.zip /tmp/$sketchname
fi
if [ $? -ne 0 ]; then
err "Please check board ($board) or mode ($mode)"
fi
}
function upload() {
echo "uploading..."
arduino-cli upload -b $board -p $port .
if [ $? -ne 0 ]; then
err "Please check board ($board) or port ($port)"
fi
}
if [ $target == "build" ]; then
build
fi
if [ $target == "upload" ]; then
upload
fi
if [ $target == "all" ]; then
build && upload
fi