view contrib/buildrpm @ 9812:dd2c95fc4fe5

buildrpm: cleanup script
author Gilles Moris <gilles.moris@free.fr>
date Fri, 06 Nov 2009 09:53:23 +0100
parents c92ac5a56f69
children 2059795bb5d0
line wrap: on
line source

#!/bin/sh
#
# Build a Mercurial RPM in place.
#
# Tested on
# - Fedora 8 (with docutils 0.5)
# - Fedora 11
# - OpenSuse 11.2

cd "`dirname $0`/.."
HG="$PWD/hg"
PYTHONPATH="$PWD/mercurial/pure"
export PYTHONPATH

specfile=contrib/mercurial.spec
if [ ! -f $specfile ]; then
    echo "Cannot find $specfile!" 1>&2
    exit 1
fi

if [ ! -d .hg ]; then
    echo 'You are not inside a Mercurial repository!' 1>&2
    exit 1
fi

if $HG id -i | grep '+$' > /dev/null 2>&1; then
    echo -n "Your local changes will NOT be in the RPM. Continue [y/n] ? "
    read answer
    if echo $answer | grep -iv '^y'; then
        exit
    fi
fi

rpmdir="$PWD/rpmbuild"

rm -rf $rpmdir
mkdir -p $rpmdir/RPMS
$HG clone -u . . $rpmdir/BUILD

tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling
# make setup.py build the version string
python setup.py build_py -c -d .
hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'`

if echo $hgversion | grep -- '-' > /dev/null 2>&1; then
    # nightly build case, version is like 1.3.1+250-20b91f91f9ca
    version=`echo $hgversion | cut -d- -f1`
    release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'`
else
    # official tag, version is like 1.3.1
    version=`echo $hgversion | sed -e 's/+.*//'`
    release='0'
fi

sed -e "s,^Version:.*,Version: $version," \
    -e "s,^Release:.*,Release: $release," \
    -e "s,^%prep.*,\n\0," \
    -e 's,^%setup.*,,' \
    $specfile > $tmpspec

cat <<EOF >> $tmpspec
%changelog
* `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release
- Automatically built via $0

EOF
$HG log \
     --template '* {date|rfc822date} {author}\n- {desc|firstline}\n\n' \
     .hgtags \
  | sed -e 's/^\(\* [MTWFS][a-z][a-z]\), \([0-3][0-9]\) \([A-Z][a-z][a-z]\) /\1 \3 \2 /' \
        -e '/^\* [MTWFS][a-z][a-z] /{s/ [012][0-9]:[0-9][0-9]:[0-9][0-9] [+-][0-9]\{4\}//}' \
   >> $tmpspec

rpmbuild --define "_topdir $rpmdir" -bb $tmpspec --clean
if [ $? = 0 ]; then
    mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS
    echo
    echo "Packages are in $rpmdir:"
    ls -l $rpmdir/*.rpm
fi