1515# IOT_SSID your-iot-ssid IOT_PW_FILE ~/.iot_wifi_pw
1616# NODE 100 (target on chip-tool fabric) PROV_NODE 1
1717# NEWVER 23 CURVER_MAX 22 CODE 34970112332
18- set -o pipefail
18+ # Hardened like its sibling scripts: -e halts a mid-sequence failure (e.g. a failed chip-tool
19+ # write) instead of silently continuing; -u catches unset vars; pipefail propagates pipe failures.
20+ # Informational `... | grep | tail` filters (which legitimately match nothing) and the interactive
21+ # teardown are explicitly `|| true`-guarded so they don't trip -e.
22+ set -euo pipefail
1923CHIP=" ${CHIP:- $HOME / ameba-dev/ connectedhomeip} "
2024CT=" $CHIP /examples/chip-tool/out/host/chip-tool"
2125OP=" $CHIP /examples/ota-provider-app/linux/out/host/chip-ota-provider-app"
@@ -37,10 +41,10 @@ case "${1:-}" in
3741 echo " >>> Commissioning (bypass). Retry this subcommand if you see IM 0x0501 (transient)."
3842 " $CT " pairing code-wifi " $NODE " " $IOT_SSID " " $( cat " $IOT_PW_FILE " ) " " $CODE " \
3943 --bypass-attestation-verifier 1 --storage-directory " $STORE " 2>&1 | \
40- grep -iE " Commissioning complete|CHIP Error|IM Error|Timeout|success" | tail -6
44+ grep -iE " Commissioning complete|CHIP Error|IM Error|Timeout|success" | tail -6 || true
4145 echo " >>> Identity + OTA Requestor check:"
4246 for a in vendor-id product-id software-version; do
43- " $CT " basicinformation read " $a " " $NODE " 0 --storage-directory " $STORE " 2>&1 | grep -iE " VendorID|ProductID|SoftwareVersion" | tail -1
47+ " $CT " basicinformation read " $a " " $NODE " 0 --storage-directory " $STORE " 2>&1 | grep -iE " VendorID|ProductID|SoftwareVersion" | tail -1 || true
4448 done
4549 " $CT " descriptor read server-list " $NODE " 0 --storage-directory " $STORE " 2>&1 | grep -iE " 42 \(Ota" && \
4650 echo " >>> OTA Requestor present. Run: $0 ota <VID> <PID>" || echo " >>> NO OTA Requestor (42) — use CH341A flash instead."
@@ -52,7 +56,7 @@ case "${1:-}" in
5256 python3 " $TOOL " extract " $OTA_SRC " " $WORK /payload.bin" > /dev/null 2>&1 || die " extract failed"
5357 python3 " $TOOL " create -v " $VID " -p " $PID " -vn " $NEWVER " -vs " ${NEWVER} .0" -mi 1 -ma " $CURVER_MAX " \
5458 -da sha256 " $WORK /payload.bin" " $TGT " > /dev/null 2>&1 || die " create failed"
55- python3 " $TOOL " show " $TGT " | grep -iE " Vendor Id|Product Id|Version:"
59+ python3 " $TOOL " show " $TGT " | grep -iE " Vendor Id|Product Id|Version:" || true
5660 if printf ' %s\n' " $@ " | grep -qx -- --dry-run; then
5761 echo " >>> --dry-run: .ota repackaged + header verified (host-only); skipping provider/commission/OTA."
5862 exit 0
@@ -61,13 +65,13 @@ case "${1:-}" in
6165 rm -f /tmp/ota_prov.kvs
6266 " $OP " --discriminator 22 --secured-device-port 5560 --KVS /tmp/ota_prov.kvs --filepath " $TGT " > " $WORK /provider.log" 2>&1 &
6367 PP=$! ; sleep 4
64- " $CT " pairing onnetwork " $PROV_NODE " 20202021 --storage-directory " $STORE " 2>&1 | grep -iE " complete|Error" | tail -2
68+ " $CT " pairing onnetwork " $PROV_NODE " 20202021 --storage-directory " $STORE " 2>&1 | grep -iE " complete|Error" | tail -2 || true
6569 " $CT " accesscontrol write acl " [{\" fabricIndex\" :1,\" privilege\" :5,\" authMode\" :2,\" subjects\" :[112233],\" targets\" :null},{\" fabricIndex\" :1,\" privilege\" :3,\" authMode\" :2,\" subjects\" :null,\" targets\" :null}]" " $PROV_NODE " 0 --storage-directory " $STORE " > /dev/null 2>&1
6670 " $CT " otasoftwareupdaterequestor write default-otaproviders " [{\" fabricIndex\" :1,\" providerNodeID\" :$PROV_NODE ,\" endpoint\" :0}]" " $NODE " 0 --storage-directory " $STORE " > /dev/null 2>&1
67- " $CT " otasoftwareupdaterequestor announce-otaprovider " $PROV_NODE " 0 0 0 " $NODE " 0 --storage-directory " $STORE " 2>&1 | grep -iE " Status=0x0|Error" | tail -1
71+ " $CT " otasoftwareupdaterequestor announce-otaprovider " $PROV_NODE " 0 0 0 " $NODE " 0 --storage-directory " $STORE " 2>&1 | grep -iE " Status=0x0|Error" | tail -1 || true
6872 echo " >>> Announced. Watching transfer (Ctrl-C when you see ApplyUpdateRequest)..."
69- timeout 300 tail -f " $WORK /provider.log" | grep --line-buffered -iE " QueryImage|UpdateAvailable|BlockAckEOF|ApplyUpdateRequest"
70- kill " $PP " 2> /dev/null
73+ timeout 300 tail -f " $WORK /provider.log" | grep --line-buffered -iE " QueryImage|UpdateAvailable|BlockAckEOF|ApplyUpdateRequest" || true
74+ kill " $PP " 2> /dev/null || true
7175 echo " >>> On ApplyUpdateRequest the unit reboots into our firmware. Then press 77 and add to HA with code $CODE ."
7276 ;;
7377 * ) echo " usage: $0 {commission | ota <VID> <PID> [--dry-run]} (see firmware/docs/12-ota-convert-stock-unit.md)" ;;
0 commit comments