Skip to content

Commit

Permalink
[RPM] Update makesrpm.sh to not use genversion.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
amadio committed Jun 5, 2023
1 parent 43a59b8 commit 67a83e3
Showing 1 changed file with 15 additions and 56 deletions.
71 changes: 15 additions & 56 deletions packaging/makesrpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
# Author: Lukasz Janyst <ljanyst@cern.ch> (10.03.2011)
#-------------------------------------------------------------------------------

RCEXP='^[0-9]+\.[0-9]+\.[0-9]+\-rc.*$'
CERNEXP='^[0-9]+\.[0-9]+\.[0-9]+\-[0-9]+\.CERN.*$'

#-------------------------------------------------------------------------------
# Find a program
#-------------------------------------------------------------------------------
function findProg()
{
for prog in $@; do
if test -x "$(command -v $prog 2>/dev/null)"; then
echo $prog
break
fi
done
}

#-------------------------------------------------------------------------------
# Print help
#-------------------------------------------------------------------------------
Expand All @@ -39,7 +23,7 @@ function printHelp()
#-------------------------------------------------------------------------------
# Parse the commandline, if only we could use getopt... :(
#-------------------------------------------------------------------------------
SOURCEPATH="../"
SOURCEPATH=$(realpath $(dirname $0)/..)
OUTPUTPATH="."
PRINTHELP=0

Expand All @@ -65,7 +49,7 @@ while test ${#} -ne 0; do
echo "--version parameter needs an argument" 1>&2
exit 1
fi
USER_VERSION="--version ${2}"
VERSION="${2}"
shift
elif test x${1} = x--define; then
if test ${#} -lt 2; then
Expand Down Expand Up @@ -108,12 +92,12 @@ fi
#-------------------------------------------------------------------------------
# Check if we have all the necassary components
#-------------------------------------------------------------------------------
if test x`findProg rpmbuild` = x; then
if ! command -v rpmbuild 2>/dev/null; then
echo "[!] Unable to find rpmbuild, aborting..." 1>&2
exit 1
fi

if test x`findProg git` = x; then
if ! command -v git 2>/dev/null; then
echo "[!] Unable to find git, aborting..." 1>&2
exit 1
fi
Expand All @@ -126,55 +110,30 @@ if test ! -d $SOURCEPATH/.git; then
exit 2
fi

#-------------------------------------------------------------------------------
# Check the version number
#-------------------------------------------------------------------------------
if test ! -x $SOURCEPATH/genversion.sh; then
echo "[!] Unable to find the genversion script" 1>&2
exit 3
fi
: ${VERSION:=$(git --git-dir=$SOURCEPATH/.git describe)}
: ${RELEASE:=1}

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
fi

echo "[i] Working with version: $VERSION"

if test x${VERSION:0:1} = x"v"; then
VERSION=${VERSION:1}
fi

#-------------------------------------------------------------------------------
# Deal with release candidates
# Sanitize version to work with RPMs
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Versioning/
#-------------------------------------------------------------------------------
RELEASE=1
if test x`echo $VERSION | grep -E $RCEXP` != x; then
RELEASE=0.`echo $VERSION | sed 's/.*-rc/rc/'`
VERSION=`echo $VERSION | sed 's/-rc.*//'`
fi

#-------------------------------------------------------------------------------
# Deal with CERN releases
#-------------------------------------------------------------------------------
if test x`echo $VERSION | grep -E $CERNEXP` != x; then
RELEASE=`echo $VERSION | sed 's/.*-//'`
VERSION=`echo $VERSION | sed 's/-.*\.CERN//'`
fi
VERSION=${VERSION#v} # remove "v" prefix
VERSION=${VERSION/-rc/~rc} # release candidates use ~ in RPMs
VERSION=${VERSION/-g/^$(date +%Y%m%d)git} # snapshots use a caret
VERSION=${VERSION/-/.post} # handle git describe for post releases
VERSION=${VERSION//-/.} # replace remaining dashes with dots

#-------------------------------------------------------------------------------
# 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
# CentOS 7 cannot handle snapshot versions, filter out
[[ `rpm -E '%{dist}'` =~ el7 ]] && VERSION=${VERSION/^*/}

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

#-------------------------------------------------------------------------------
Expand Down

0 comments on commit 67a83e3

Please sign in to comment.