45 lines
842 B
Bash
Executable File
45 lines
842 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
source .env
|
|
|
|
function info {
|
|
sed -n 's/^##//p' ctl.sh
|
|
}
|
|
|
|
function build {
|
|
echo "Building project..."
|
|
pio run
|
|
}
|
|
|
|
function flash {
|
|
echo "Flashing firmware..."
|
|
pio run --target upload
|
|
}
|
|
|
|
function ota {
|
|
function update {
|
|
echo "Updating node at $1"
|
|
curl -X POST \
|
|
-F "file=@.pio/build/esp01_1m/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
|
|
done
|
|
}
|
|
${@:-info}
|
|
}
|
|
|
|
function cluster {
|
|
function members {
|
|
curl -s http://$API_NODE/api/cluster/members | jq -r '.members[] | "\(.hostname) \(.ip)"'
|
|
}
|
|
${@:-info}
|
|
}
|
|
|
|
${@:-info}
|