##// END OF EJS Templates
buildrpm: complain when hg command isn't available...
Mads Kiilerich -
r7431:3d827cc6 default
parent child Browse files
Show More
@@ -1,65 +1,72
1 1 #!/bin/sh
2 2 #
3 3 # Build a Mercurial RPM in place.
4 4 # Known to work on:
5 5 # - Fedora 9
6 # - Fedora 10
6 7 #
7 8 # Bryan O'Sullivan <bos@serpentine.com>
8 9
10 if hg --version > /dev/null 2>&1; then :
11 else
12 echo 'hg command not available!' 1>&2
13 exit 1
14 fi
15
9 16 root="`hg root 2>/dev/null`"
10 17 specfile=contrib/mercurial.spec
11 18
12 19 if [ -z "$root" ]; then
13 20 echo 'You are not inside a Mercurial repository!' 1>&2
14 21 exit 1
15 22 fi
16 23
17 24 rpmdir=/tmp/"`basename $root | sed 's/ /_/'`"-rpm # FIXME: Insecure /tmp handling
18 25
19 26 cd "$root"
20 27 rm -rf $rpmdir
21 28 mkdir -p $rpmdir/RPMS
22 29 hg clone "$root" $rpmdir/BUILD
23 30
24 31 if [ ! -f $specfile ]; then
25 32 echo "Cannot find $specfile!" 1>&2
26 33 exit 1
27 34 fi
28 35
29 36 tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling
30 37 # Use the most recent tag as the version.
31 38 version=`hg tags | perl -e 'while(<STDIN>){if(/^(\d\S+)/){print$1;exit}}'`
32 39 # Compute the release number as the difference in revision numbers
33 40 # between the tip and the most recent tag.
34 41 release=`hg tags | perl -e 'while(<STDIN>){($tag,$id)=/^(\S+)\s+(\d+)/;if($tag eq "tip"){$tip = $id}elsif($tag=~/^\d/){print $tip-$id+1;exit}}'`
35 42 tip=`hg -q tip`
36 43
37 44 # Beat up the spec file
38 45 sed -e 's,^Source:.*,Source: /dev/null,' \
39 46 -e "s,^Version:.*,Version: $version," \
40 47 -e "s,^Release:.*,Release: $release," \
41 48 -e "s,^%prep.*,Changeset: $tip\n\0," \
42 49 -e 's,^%setup.*,,' \
43 50 $specfile > $tmpspec
44 51
45 52 cat <<EOF >> $tmpspec
46 53 %changelog
47 54 * `date +'%a %b %d %Y'` `hg showconfig ui.username` $version-$release
48 55 - Automatically built via $0
49 56
50 57 EOF
51 58 hg log \
52 59 --template '* {date|rfc822date} {author}\n- {desc|firstline}\n\n' \
53 60 .hgtags \
54 61 | sed -e 's/^\(\* [MTWFS][a-z][a-z]\), \([0-3][0-9]\) \([A-Z][a-z][a-z]\) /\1 \3 \2 /' \
55 62 -e '/^\* [MTWFS][a-z][a-z] /{s/ [012][0-9]:[0-9][0-9]:[0-9][0-9] [+-][0-9]\{4\}//}' \
56 63 >> $tmpspec
57 64
58 65 rpmbuild --define "_topdir $rpmdir" -bb $tmpspec
59 66 if [ $? = 0 ]; then
60 67 rm -rf $tmpspec $rpmdir/BUILD
61 68 mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS
62 69 echo
63 70 echo "Packages are in $rpmdir:"
64 71 ls -l $rpmdir/*.rpm
65 72 fi
General Comments 0
You need to be logged in to leave comments. Login now