#!/bin/bash

# Environments to build
ENVIRONMENTS="sonoff-debug sonoff-dht22-debug sonoff-ds18b20-debug sonoff-pow-debug sonoff-dual-debug sonoff-4ch-debug electrodragon-debug ecoplug-debug"

# Get current version
version=`cat espurna/config/version.h | grep APP_VERSION | awk '{print $3}' | sed 's/"//g'`
echo $version

# Create output folder
mkdir -p firmware

# Build all the required firmwares
for environment in $ENVIRONMENTS; do
    platformio run -e $environment
    mv .pioenvs/$environment/firmware.bin firmware/espurna-$version-$environment.bin
done

platformio run -vv -t uploadfs -e node-debug
mv .pioenvs/node-debug/spiffs.bin firmware/espurna-$version-spiffs.bin