esmp3/deploy.sh

38 lines
1.2 KiB
Bash
Raw Normal View History

2019-11-28 18:26:35 +00:00
#!/usr/bin/env bash
set -x
set -e
if ! git diff-index --quiet HEAD ; then
echo "Git isn't clean. Cant deploy."
exit 1
fi
read -p "Version to generate: " VERSION
OTA_VERSION=`grep "VERSION=" bin/update.manifest | cut -d"=" -f2`
OTA_VERSION=$(( "$OTA_VERSION" + 1 ))
echo "$OTA_VERSION" > data/_version.txt
sed -i.bak "s/#define OTA_VERSION .*/#define OTA_VERSION $OTA_VERSION/" include/config.h include/config.sample.h
rm include/config.h.bak include/config.sample.h.bak
PLATFORMIO_BUILD_FLAGS='-DVERSION=\"$VERSION\"' pio run -e deploy -t buildprog || exit 1
pio run -e deploy -t buildfs || exit 1
cp .pio/build/deploy/firmware.bin bin/firmware.bin || exit 1
cp .pio/build/deploy/spiffs.bin bin/spiffs.bin || exit 1
sed -i.bak "s/VERSION=.*/VERSION=$OTA_VERSION/" bin/update.manifest
MD5=`md5sum --binary bin/firmware.bin | cut -d" " -f1`
sed -i.bak "s/IMAGE_MD5=.*/IMAGE_MD5=$MD5/" bin/update.manifest
MD5=`md5sum --binary bin/spiffs.bin | cut -d" " -f1`
sed -i.bak "s/SPIFFS_MD5=.*/SPIFFS_MD5=$MD5/" bin/update.manifest
rm bin/update.manifest.bak
git diff
exit 99
git add bin/firmware.bin bin/spiffs.bin bin/update.manifest
git commit -m "Deploying version $VERSION."
git tag -a -m "Deploying version $VERSION" $VERSION