#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <hash>"
read -p "Enter the hash: " hash
if [ -z "$hash" ]; then
echo "No hash entered."
exit 1
fi
else
hash=$1
fi
# ダウンロードURL
URL="https://lattr.istlab.info/inobin/dl/${hash}"
RESPONCE_CODE=$(curl -s -o byhash.bin -w "%{http_code}" $URL)
if [ $RESPONCE_CODE -ne 200 ]; then
echo "Error: $RESPONCE_CODE"
exit 1
fi
curl -o byhash.partitions.bin -s ${URL}/partitions
curl -o byhash.bootloader.bin -s ${URL}/bootloader
echo "Downloaded ${hash} as [byhash.bin], [byhash.partitions.bin], [byhash.bootloader.bin]"
# もし、hashがp1ではじまっていたら、注意喚起する
if [[ $hash =~ ^p1 ]]; then
echo "注:Plus2(黄色)ではなく、Plus(オレンジ色)用のプログラムです。"
board="plus"
else
board="plus2"
fi
# 書き込みを行う
serials=`arduino-cli board list | grep USB | awk '{print $1}'`
seriallist=($serials)
if [ -z "${serials}" ]; then
echo "デバイスがみつかりませんでした。"
sleep 2
echo "デバイスを接続しているのに認識しないときは、ドライバを入れてください。"
sleep 2
echo "https://ftdichip.com/drivers/vcp-drivers/ → Click here to download
の hereをおす。ZIP解凍して実行。"
exit
fi
for ser in ${seriallist[@]} ; do
echo ${ser}
arduino-cli upload --fqbn esp32:esp32:m5stack_stickc_${board} -p ${ser} --input-file byhash.bin
done
# 接続デバイスが1つのみの場合、シリアルモニタを開くか確認
if [[ "${#seriallist[@]}" -eq 1 ]]; then
read -p "シリアルモニタを開きますか?(y/n): " yn
if [ $yn = "y" ]; then
echo "終了するときはCtrl+Cを押してください。"
arduino-cli monitor -p ${seriallist[0]} --config 115200
fi
fi