#!/bin/sh
NAME=cadvisor
GIT_COMMIT="$1"
GIT_SHORT="${GIT_COMMIT:0:7}"
GIT_VERSION="$2"
set -o errexit
set -o nounset
set -o pipefail
set -x
SPEC="${NAME}.spec"
curl -s -L https://github.com/google/${NAME}/archive/${GIT_COMMIT}.tar.gz > ${NAME}-${GIT_SHORT}.tar.gz
if [[ "${GIT_VERSION}" =~ ^([0-9]+)\.([0-9]+)(\.)?([0-9]+)?(-.*)?$ ]]; then
git_major=${BASH_REMATCH[1]}
git_minor=${BASH_REMATCH[2]}
git_really_minor=${BASH_REMATCH[4]}
since_tag=${BASH_REMATCH[5]}
else
echo "Failed to parse version!"
/bin/false
fi
if [[ "${since_tag}" =~ ^-([0-9]+)-.*$ ]]; then
since_tag=${BASH_REMATCH[1]}
else
since_tag=0
fi
version="${git_major}.${git_minor}"
if [[ -n ${git_really_minor} ]]; then
version="${version}.${git_really_minor}"
fi
#put the git hash in as the commit
sed -i -e "s/%global commit\t\t[[:xdigit:]]\{40\}/%global commit\t\t${GIT_COMMIT}/" ${SPEC}
#update the version with the latest tag
sed -i -e "s/Version:\t[[:digit:]]\+\.[[:digit:]]\+\(\.[[:digit:]]\+\)\?/Version:\t${version}/" ${SPEC}
#update the release with since_tag
sed -i -e "s/Release:\t[[:digit:]]\+\.[[:digit:]]\+/Release:\t${since_tag}.0/" ${SPEC}
#increment the version number
./add-chglog --comment="Bump to upstream ${GIT_COMMIT}" --userstring="Eric Paris <eparis@redhat.com>" ${SPEC}
fedpkg clog
echo "****Don't forget to run: fedpkg new-sources ${NAME}-${GIT_SHORT}.tar.gz"