lw-build-system/scripts/version.sh

136 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# lw-build-system/scripts/version.sh
#
# Copyright: ©20072010, Laurence Withers
# Author: Laurence Withers <l@lwithers.me.uk>
# License: GPLv3
#
# Script to automate bumping of version or soversion files, and pushing
# changes (and tags) to the origin repository.
#
if [ $# -eq 0 ]
then
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"
exit 1
fi
edit_versions() {
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"
edit_versions "version" "VERMAJOR" "$[${VERMAJOR} + 1]" "VERMINOR" "0" "VERMICRO" "0"
}
bump_minor() {
source "./version"
edit_versions "version" "VERMINOR" "$[${VERMINOR} + 1]" "VERMICRO" "0"
}
bump_micro() {
source "./version"
edit_versions "version" "VERMICRO" "$[${VERMICRO} + 1]"
}
bump_somajor() {
source "./src/$1/soversion"
edit_versions "src/$1/soversion" "SOMAJOR" "$[${SOMAJOR} + 1]" "SOMINOR" "0" "SOMICRO" "0"
}
bump_somicro() {
source "./src/$1/soversion"
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
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
# vim:ts=4:sw=4:expandtab