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