Files
spore/ctl.sh

77 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
source .env
function info {
sed -n 's/^##//p' ctl.sh
}
function build {
function target {
echo "Building project for $1..."
pio run -e $1
}
function all {
pio run
}
${@:-all}
}
function flash {
function target {
echo "Flashing firmware for $1..."
pio run --target upload -e $1
}
${@:-info}
}
function mkfs {
~/bin/mklittlefs -c data \
-s 0x9000 \
-b 4096 \
-p 256 \
littlefs.bin
}
function flashfs {
esptool.py --port /dev/ttyUSB0 \
--baud 115200 \
write_flash 0xbb000 littlefs.bin
}
function uploadfs {
echo "Uploading files to LittleFS..."
pio run -e $1 -t uploadfs
}
function ota {
function update {
echo "Updating node at $1 with $2... "
curl -X POST \
-F "file=@.pio/build/$2/firmware.bin" \
http://$1/api/node/update | jq -r '.status'
}
function all {
echo "Updating all nodes..."
curl -s http://$API_NODE/api/cluster/members | jq -r '.members.[].ip' | while read -r ip; do
ota update $ip $1
done
}
${@:-info}
}
function cluster {
function members {
curl -s http://$API_NODE/api/cluster/members | jq -r '.members[] | "\(.hostname) \(.ip)"'
}
${@:-info}
}
function monitor {
pio run --target monitor
}
${@:-info}