lw-build-system/scripts/version.sh

136 lines
2.4 KiB
Bash
Raw Normal View History

#!/bin/bash
2007-10-14 11:31:40 +01:00
# lw-build-system/scripts/version.sh
#
# Copyright: ©20072010, Laurence Withers
# Author: Laurence Withers <l@lwithers.me.uk>
# License: GPLv3
2007-10-14 11:31:40 +01:00
#
# Script to automate bumping of version or soversion files, and pushing
# changes (and tags) to the origin repository.
#
if [ $# -eq 0 ]
then
2007-10-14 11:31:40 +01:00
echo "Usage: $0 COMMANDS"
echo ""
echo " major - bump major version, reset minor and micro"
echo " minor - bump minor version, reset micro"
echo " micro - bump micro version"
echo " libmajor LIB - as major but for soversion"
echo " libmicro LIB - as micro but for soversion"
echo " tag - tag version"
echo " push - do a git push with --tags"
2007-10-14 11:31:40 +01:00
exit 1
fi
edit_versions() {
2007-10-14 11:31:40 +01:00
file="$1"
shift
SEDCMD=""
while [ $# -ne 0 ]
do
var="$1"
shift
value="$1"
shift
SEDCMD="${SEDCMD} -e s,^${var}=.*$,${var}=${value},"
done
sed ${SEDCMD} -i "${file}"
git commit -m "Bump version" "${file}"
}
bump_major() {
source "./version"
2007-10-14 11:31:40 +01:00
edit_versions "version" "VERMAJOR" "$[${VERMAJOR} + 1]" "VERMINOR" "0" "VERMICRO" "0"
}
bump_minor() {
source "./version"
2007-10-14 11:31:40 +01:00
edit_versions "version" "VERMINOR" "$[${VERMINOR} + 1]" "VERMICRO" "0"
}
bump_micro() {
source "./version"
2007-10-14 11:31:40 +01:00
edit_versions "version" "VERMICRO" "$[${VERMICRO} + 1]"
}
bump_somajor() {
source "./src/$1/soversion"
2007-10-14 11:31:40 +01:00
edit_versions "src/$1/soversion" "SOMAJOR" "$[${SOMAJOR} + 1]" "SOMINOR" "0" "SOMICRO" "0"
}
bump_somicro() {
source "./src/$1/soversion"
2007-10-14 11:31:40 +01:00
edit_versions "src/$1/soversion" "SOMICRO" "$[${SOMICRO} + 1]"
}
do_tag() {
local tag_args=""
source "./version"
if [ -n "${PGP_KEYID}" ]
then
tag_args="-u ${PGP_KEYID} ${tag_args}"
else
tag_args="-a"
fi
git tag ${tag_args} "${VERMAJOR}.${VERMINOR}.${VERMICRO}"
}
do_push() {
git push
git push --tags
}
set -ex
source "${HOME}/.lwbuildrc"
while [ $# -ne 0 ]
do
2007-10-14 11:31:40 +01:00
case $1 in
major)
bump_major
;;
minor)
bump_minor
;;
micro)
bump_micro
;;
libmajor)
bump_somajor $2
shift
;;
libmicro)
bump_somicro $2
shift
;;
tag)
do_tag
;;
push)
do_push
;;
*)
echo "Unrecognised command: $1"
exit 1
;;
esac
shift
done
true
2007-10-14 11:31:40 +01:00
# vim:ts=4:sw=4:expandtab