buildrpm
72 lines
| 2.1 KiB
| text/plain
|
TextLexer
/ contrib / buildrpm
mpm@selenic.com
|
r564 | #!/bin/sh | ||
# | ||||
# Build a Mercurial RPM in place. | ||||
# | ||||
# Bryan O'Sullivan <bos@serpentine.com> | ||||
Mads Kiilerich
|
r8867 | # | ||
# Tested on | ||||
# - Fedora 10 | ||||
# - Fedora 11 | ||||
# - Centos 5.3 (with Fedora EPEL repo for asciidoc) | ||||
mpm@selenic.com
|
r564 | |||
Mads Kiilerich
|
r8869 | HG="`dirname $0`/../hg" | ||
PYTHONPATH="`dirname $0`/../mercurial/pure" | ||||
export PYTHONPATH | ||||
Mads Kiilerich
|
r7431 | |||
Mads Kiilerich
|
r8869 | root="`$HG root 2>/dev/null`" | ||
mpm@selenic.com
|
r564 | specfile=contrib/mercurial.spec | ||
if [ -z "$root" ]; then | ||||
echo 'You are not inside a Mercurial repository!' 1>&2 | ||||
exit 1 | ||||
fi | ||||
Mads Kiilerich
|
r7277 | rpmdir=/tmp/"`basename $root | sed 's/ /_/'`"-rpm # FIXME: Insecure /tmp handling | ||
mpm@selenic.com
|
r564 | |||
cd "$root" | ||||
rm -rf $rpmdir | ||||
mkdir -p $rpmdir/RPMS | ||||
Mads Kiilerich
|
r8869 | $HG clone "$root" $rpmdir/BUILD | ||
mpm@selenic.com
|
r564 | |||
if [ ! -f $specfile ]; then | ||||
echo "Cannot find $specfile!" 1>&2 | ||||
exit 1 | ||||
fi | ||||
Mads Kiilerich
|
r7277 | tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling | ||
mpm@selenic.com
|
r564 | # Use the most recent tag as the version. | ||
Mads Kiilerich
|
r8869 | version=`$HG tags | python -c 'import sys; print [l for l in sys.stdin.readlines() if l[0].isdigit()][0].split()[0]'` | ||
mpm@selenic.com
|
r564 | # Compute the release number as the difference in revision numbers | ||
# between the tip and the most recent tag. | ||||
Mads Kiilerich
|
r8869 | release=`$HG tags | python -c 'import sys; l = sys.stdin.readlines(); print int(l[0].split()[1].split(":")[0]) - int([x for x in l if x[0].isdigit()][0].split()[1].split(":")[0])'` | ||
tip=`$HG -q tip` | ||||
mpm@selenic.com
|
r564 | |||
# Beat up the spec file | ||||
sed -e 's,^Source:.*,Source: /dev/null,' \ | ||||
-e "s,^Version:.*,Version: $version," \ | ||||
-e "s,^Release:.*,Release: $release," \ | ||||
-e "s,^%prep.*,Changeset: $tip\n\0," \ | ||||
-e 's,^%setup.*,,' \ | ||||
$specfile > $tmpspec | ||||
Adam Spiers
|
r4754 | cat <<EOF >> $tmpspec | ||
%changelog | ||||
Stefano Tortarolo
|
r8906 | * `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release | ||
Adam Spiers
|
r4754 | - Automatically built via $0 | ||
EOF | ||||
Mads Kiilerich
|
r8869 | $HG log \ | ||
Adam Spiers
|
r4754 | --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 | ||||
mpm@selenic.com
|
r564 | rpmbuild --define "_topdir $rpmdir" -bb $tmpspec | ||
if [ $? = 0 ]; then | ||||
rm -rf $tmpspec $rpmdir/BUILD | ||||
mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS | ||||
echo | ||||
Mads Kiilerich
|
r7277 | echo "Packages are in $rpmdir:" | ||
ls -l $rpmdir/*.rpm | ||||
mpm@selenic.com
|
r564 | fi | ||