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