av/cmd/revid-cli/upgrade.sh

57 lines
1.2 KiB
Bash
Raw Normal View History

2018-06-06 02:19:14 +03:00
#!/bin/bash
# All-purpose upgrade script.
# Upgrades source(s) to given Git tag, runs make in each directory,
# and write tags to tags.conf upon success, exiting 0.
# NB: Customize SrcDirs as needed to reflect dependencies.
Usage="Usage: upgrade.sh [-d] tag"
2018-08-20 11:13:56 +03:00
BaseDir=$GOPATH/src/bitbucket.org/ausocean
VarDir=/var/netsender
LogFile=/var/log/netsender/stream.log
2018-06-06 02:23:37 +03:00
SrcDirs=($BaseDir/utils $BaseDir/iot $BaseDir/av)
2018-06-06 02:19:14 +03:00
if [ "$1" == "-d" ]; then
set -x
GitFlags=""
NewTag="$2"
else
2018-08-20 11:13:56 +03:00
# capture stdout and stderr
exec 2> $LogFile
exec 1>&2
2018-06-06 02:19:14 +03:00
GitFlags="--quiet"
NewTag="$1"
fi
2018-08-20 11:13:56 +03:00
if [ -z "$GOPATH" ]; then
echo "Error: GOPATH not defined"
exit 1
fi
2018-06-06 02:19:14 +03:00
if [ -z "$NewTag" ]; then
echo "$Usage"
exit 1
fi
for dir in ${SrcDirs[@]}; do
pushd $dir
if [ ! "$?" == 0 ]; then
exit 1
fi
2018-06-06 02:19:14 +03:00
git fetch $GitFlags --depth=1 origin refs/tags/$NewTag:refs/tags/$NewTag
if [ ! "$?" == 0 ]; then
exit 1
fi
2018-06-22 11:44:07 +03:00
git checkout $GitFlags --force tags/$NewTag
2018-06-06 02:19:14 +03:00
if [ ! "$?" == 0 ]; then
exit 1
fi
if [ -e Makefile ]; then
make
if [ ! "$?" == 0 ]; then
exit 1
fi
fi
popd
done
if [ ! -d "$VarDir" ]; then
echo "Error: $VarDir does not exit."
exit 1
fi
git tag > "$VarDir/tags.conf"
exit $?