Skip to content

Commit

Permalink
[Packaging] Make RPM version configurable by the user.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Jun 20, 2017
1 parent a80aaa0 commit f319725
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
18 changes: 16 additions & 2 deletions genversion.sh
Expand Up @@ -80,9 +80,10 @@ function getVersionFromLog()
function printHelp()
{
echo "Usage:" 1>&2
echo "${0} [--help|--print-only] [SOURCEPATH]" 1>&2
echo "${0} [--help|--print-only|--version] [SOURCEPATH]" 1>&2
echo " --help prints this message" 1>&2
echo " --print-only prints the version to stdout and quits" 1>&2
echo " --version VERSION sets the version manually" 1>&2
}

#-------------------------------------------------------------------------------
Expand All @@ -93,6 +94,13 @@ while test ${#} -ne 0; do
PRINTHELP=1
elif test x${1} = x--print-only; then
PRINTONLY=1
elif test x${1} = x--version; then
if test ${#} -lt 2; then
echo "--version parameter needs an argument" 1>&2
exit 1
fi
USER_VERSION=${2}
shift
else
SOURCEPATH=${1}
fi
Expand Down Expand Up @@ -143,6 +151,12 @@ if test ! -d ${SOURCEPATH}.git; then
fi
fi

#-------------------------------------------------------------------------------
# Check if the version has been specified by the user
#-------------------------------------------------------------------------------
elif test x$USER_VERSION != x; then
VERSION=$USER_VERSION

#-------------------------------------------------------------------------------
# We're in a git repo so we can try to determine the version using that
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -184,7 +198,7 @@ fi
#-------------------------------------------------------------------------------
# Make sure the version string is not longer than 25 characters
#-------------------------------------------------------------------------------
if test ${#VERSION} -gt 25; then
if test ${#VERSION} -gt 25 and x$USER_VERSION = x; then
VERSION="${VERSION:0:19}...${VERSION: -3}"
fi

Expand Down
21 changes: 20 additions & 1 deletion packaging/makesrpm.sh
Expand Up @@ -32,6 +32,7 @@ function printHelp()
echo " defaults to ../" 1>&2
echo " --output PATH the directory where the source rpm" 1>&2
echo " should be stored, defaulting to ." 1>&2
echo " --version VERSION the version provided by user" 1>&2
}

#-------------------------------------------------------------------------------
Expand All @@ -58,6 +59,13 @@ while test ${#} -ne 0; do
fi
OUTPUTPATH=${2}
shift
elif test x${1} = x--version; then
if test ${#} -lt 2; then
echo "--version parameter needs an argument" 1>&2
exit 1
fi
USER_VERSION="--version ${2}"
shift
fi
shift
done
Expand Down Expand Up @@ -112,7 +120,7 @@ if test ! -x $SOURCEPATH/genversion.sh; then
exit 3
fi

VERSION=`$SOURCEPATH/genversion.sh --print-only $SOURCEPATH 2>/dev/null`
VERSION=`$SOURCEPATH/genversion.sh --print-only $USER_VERSION $SOURCEPATH 2>/dev/null`
if test $? -ne 0; then
echo "[!] Unable to figure out the version number" 1>&2
exit 4
Expand Down Expand Up @@ -141,6 +149,17 @@ if test x`echo $VERSION | egrep $CERNEXP` != x; then
VERSION=`echo $VERSION | sed 's/-.*\.CERN//'`
fi

#-------------------------------------------------------------------------------
# In case of user version check if the release number has been provided
#-------------------------------------------------------------------------------
if test x"$USER_VERSION" != x; then
TMP=`echo $VERSION | sed 's#.*-##g'`
if test $TMP != $VERSION; then
RELEASE=$TMP
VERSION=`echo $VERSION | sed 's#-[^-]*$##'`
fi
fi

VERSION=`echo $VERSION | sed 's/-/./g'`
echo "[i] RPM compliant version: $VERSION-$RELEASE"

Expand Down

0 comments on commit f319725

Please sign in to comment.