#!/bin/bash set -e if [ "x${1}" = "x" ] ; then printf "Usage bumpversion major|minor|micro|set|init\n" exit 2 fi cmd="${1}" if [ "${cmd}" = "set" -a "x${2}" = "x" ] ;then printf "ERROR the 'set' command requires a version argument\n" exit 2 fi if [ "${cmd}" != "init" -a ! -f ./VERSION ] ; then printf "ERROR this script must be executed from the repo base directory " printf "where the VERSION file is located.\n" exit 2 fi if [ "${cmd}" != "init" ] ; then PRIOR_VERSION=$(cat VERSION|head -n 1|tr -d "\r\n") printf "INFO Current build version ${VERSION}\n" IFS=. read -r VERSION_MAJOR VERSION_MINOR VERSION_MICRO <<< ${PRIOR_VERSION} if [ "x${VERSION_MAJOR}" = "x" -o "x${VERSION_MINOR}" = "x" -o "x${VERSION_MICRO}" = "x" ] ; then printf "ERROR the VERSION file has not been initialized.\n" exit 2 fi else printf "INFO Initializing build version\n" fi case ${1} in major) ((++VERSION_MAJOR)) VERSION_MINOR=0 VERSION_MICRO=0 ;; minor) ((++VERSION_MINOR)) VERSION_MICRO=0 ;; micro) ((++VERSION_MICRO)) ;; set) IFS=. read -r VERSION_MAJOR VERSION_MINOR VERSION_MICRO <<< ${2} ;; init) VERSION_MAJOR=0 VERSION_MINOR=1 VERSION_MICRO=0 ;; default) printf "ERROR An invalid command argument was provided\n" exit 2 ;; esac VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}" printf "${VERSION}\n" >VERSION printf "INFO New build version ${VERSION}\n" exit 0