esmp3/deploy.sh

54 lines
1.4 KiB
Bash
Raw Normal View History

2019-11-28 18:26:35 +00:00
#!/usr/bin/env bash
#set -x
set -e
2019-11-28 18:26:35 +00:00
if ! git diff-index --quiet HEAD ; then
echo "Git isn't clean. Cant deploy."
exit 1
fi
2019-11-29 04:29:01 +00:00
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
if [ "$branch_name" != "master" ]; then
echo "We are not on master branch. Can't deploy."
exit 1
fi
2019-11-29 05:13:16 +00:00
echo
echo
echo "Last tags:"
vers=`git tag --sort=-version:refname | head -n 5`
while read version; do
echo " $version"
done <<< "$vers"
2019-11-28 18:26:35 +00:00
read -p "Version to generate: " VERSION
OTA_VERSION=`grep "VERSION=" bin/update.manifest | cut -d"=" -f2`
2019-11-29 23:14:02 +00:00
OTA_VERSION=$(( $OTA_VERSION + 1 ))
2019-11-28 18:26:35 +00:00
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
cp .pio/build/deploy/firmware.bin bin/firmware.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
rm bin/update.manifest.bak
2019-11-29 04:29:01 +00:00
echo; echo; echo; echo; echo
echo "Please check the git diff, if everything looks okay:"
2019-11-28 18:26:35 +00:00
git diff
2019-11-29 04:29:01 +00:00
read -p "Press ENTER to continue, Ctrl-C to abort. " foo
2019-11-28 18:26:35 +00:00
git add bin/firmware.bin bin/update.manifest
2019-11-28 18:26:35 +00:00
git commit -m "Deploying version $VERSION."
git tag -a -m "Deploying version $VERSION" $VERSION
2019-11-29 04:29:01 +00:00
git push --follow-tags