#!/bin/bash

## get serial port via board list, choose lines including "USB", and pick up 1st word
serials=`arduino-cli board list | grep USB | awk '{print $1}'`

# echo ${serials}
if [ -z "${serials}" ]; then
  echo "No device connected."
  exit  
fi


## if multiple ports found, try uploading to all ports.
seriallist=($serials)

## print the list
# echo ${seriallist[@]}

for ser in ${seriallist[@]} ; do
    echo ${ser}
    arduino-cli upload --fqbn esp32:esp32:m5stick-c -p ${ser} "."
done

