@@ -12,6 +12,21 @@ checkExecutable () {
12
12
fi
13
13
}
14
14
15
+ printHelp () {
16
+ echo " "
17
+ echo " Usage: $0 [-t <tag> | -d <device ids>] -f <firmwarefile> [-o <waittime in seconds - default 600>] [-v <new firmware version for tagging updated devices>]"
18
+ echo " "
19
+ echo " Examples -----------------"
20
+ echo " perform ota on devices with firmware=v1 tag"
21
+ echo " $0 -t firmware=v1 -f myfirmware.bin"
22
+ echo " perform ota on devices with firmware=v1 tag and apply new tag firmware=v2 to updated devices, waiting for 1200 seconds"
23
+ echo " $0 -t firmware=v1 -f myfirmware.bin -v firmware=v2 -w 1200"
24
+ echo " perform ota on two specified devices"
25
+ echo " $0 -d 261ec96a-38ba-4520-96e6-2447c4163e9b,8b10acdb-b722-4068-8e4d-d1c1b7302df4 -f myfirmware.bin"
26
+ echo " "
27
+ exit 1
28
+ }
29
+
15
30
# Check dependencies...
16
31
checkExecutable " arduino-cloud-cli"
17
32
checkExecutable " jq"
@@ -23,33 +38,48 @@ checkExecutable "paste"
23
38
waittime=600
24
39
newtagversion=" "
25
40
26
- while getopts t:v:f:o: flag
41
+ while getopts t:v:f:o:d: flag
27
42
do
28
43
case " ${flag} " in
29
44
t) tag=${OPTARG} ;;
30
45
v) newtagversion=${OPTARG} ;;
31
46
f) firmwarefile=${OPTARG} ;;
32
47
o) waittime=${OPTARG} ;;
48
+ d) deviceids=${OPTARG} ;;
33
49
esac
34
50
done
35
51
36
- if [[ " $firmwarefile " == " " || " $tag " == " " || " $waittime " == " " ]]; then
37
- echo " Usage: $0 -t <tag> -f <firmwarefile> [-o <waittime>] [-v <new firmware version for tagging>]"
38
- exit 1
52
+ if [[ " $firmwarefile " == " " || " $waittime " == " " ]]; then
53
+ printHelp
54
+ fi
55
+ if [[ " $tag " == " " && " $deviceids " == " " ]]; then
56
+ printHelp
39
57
fi
40
58
41
- echo " Starting OTA process for devices with tag \" $tag \" using firmware \" $firmwarefile \" "
42
- echo " "
59
+ if [[ " $deviceids " == " " ]]; then
60
+ echo " Starting OTA process for devices with tag \" $tag \" using firmware \" $firmwarefile \" "
61
+ echo " "
62
+
63
+ devicelistjson=$( arduino-cloud-cli device list --tags $tag --format json)
64
+ else
65
+ echo " Starting OTA process for devices \" $deviceids \" using firmware \" $firmwarefile \" "
66
+ echo " "
67
+
68
+ devicelistjson=$( arduino-cloud-cli device list -d $deviceids --format json)
69
+ fi
43
70
44
- devicelistjson=$( arduino-cloud-cli device list --tags $tag --format json)
45
71
devicecount=$( echo $devicelistjson | jq ' .[] | .id' | wc -l)
46
72
47
73
if [ " $devicecount " -gt 0 ]; then
48
- echo " Found $devicecount devices with tag \" $tag \" "
74
+ echo " Found $devicecount devices"
49
75
echo " "
50
- arduino-cloud-cli device list --tags $tag
76
+ if [[ " $deviceids " == " " ]]; then
77
+ arduino-cloud-cli device list --tags $tag
78
+ else
79
+ arduino-cloud-cli device list -d $deviceids
80
+ fi
51
81
else
52
- echo " No devices found with tag \" $tag \" "
82
+ echo " No device found"
53
83
exit 1
54
84
fi
55
85
66
96
fqbn=$( echo $devicelistjson | jq -r ' .[] | .fqbn' | sort | uniq | head -n 1)
67
97
68
98
echo " Sending OTA request to detected boards of type $fqbn ..."
69
- otastartedout=$( arduino-cloud-cli ota mass-upload --device-tags $tag --file $firmwarefile -b $fqbn --format json)
99
+ if [[ " $deviceids " == " " ]]; then
100
+ otastartedout=$( arduino-cloud-cli ota mass-upload --device-tags $tag --file $firmwarefile -b $fqbn --format json)
101
+ else
102
+ otastartedout=$( arduino-cloud-cli ota mass-upload -d $deviceids --file $firmwarefile -b $fqbn --format json)
103
+ fi
70
104
if [ $? -ne 0 ]; then
71
105
echo " Detected error during OTA process. Exiting..."
72
106
exit 1
0 commit comments