##// END OF EJS Templates
buildrpm: enable to start the script from anywhere...
Gilles Moris -
r9811:c92ac5a5 default
parent child Browse files
Show More
@@ -1,88 +1,89
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 HG="`dirname $0`/../hg"
12 cd "`dirname $0`/.."
13 PYTHONPATH="`dirname $0`/../mercurial/pure"
13 HG="$PWD/hg"
14 PYTHONPATH="$PWD/mercurial/pure"
14 export PYTHONPATH
15 export PYTHONPATH
15
16
16 root="`$HG root 2>/dev/null`"
17 root="`$HG root 2>/dev/null`"
17 specfile=contrib/mercurial.spec
18 specfile=contrib/mercurial.spec
18
19
19 if [ -z "$root" ]; then
20 if [ -z "$root" ]; then
20 echo 'You are not inside a Mercurial repository!' 1>&2
21 echo 'You are not inside a Mercurial repository!' 1>&2
21 exit 1
22 exit 1
22 fi
23 fi
23
24
24 if $HG id -i | grep '+$' > /dev/null 2>&1; then
25 if $HG id -i | grep '+$' > /dev/null 2>&1; then
25 echo -n "Your local changes will NOT be in the RPM. Continue [y/n] ? "
26 echo -n "Your local changes will NOT be in the RPM. Continue [y/n] ? "
26 read answer
27 read answer
27 if echo $answer | grep -iv '^y'; then
28 if echo $answer | grep -iv '^y'; then
28 exit
29 exit
29 fi
30 fi
30 fi
31 fi
31
32
32 rpmdir=/tmp/"`basename $root | sed 's/ /_/'`"-rpm # FIXME: Insecure /tmp handling
33 rpmdir=/tmp/"`basename $root | sed 's/ /_/'`"-rpm # FIXME: Insecure /tmp handling
33
34
34 cd "$root"
35 cd "$root"
35 rm -rf $rpmdir
36 rm -rf $rpmdir
36 mkdir -p $rpmdir/RPMS
37 mkdir -p $rpmdir/RPMS
37 $HG clone -u . "$root" $rpmdir/BUILD
38 $HG clone -u . "$root" $rpmdir/BUILD
38
39
39 if [ ! -f $specfile ]; then
40 if [ ! -f $specfile ]; then
40 echo "Cannot find $specfile!" 1>&2
41 echo "Cannot find $specfile!" 1>&2
41 exit 1
42 exit 1
42 fi
43 fi
43
44
44 tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling
45 tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling
45 # make setup.py build the version string
46 # make setup.py build the version string
46 python setup.py build_py -c -d .
47 python setup.py build_py -c -d .
47 hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'`
48 hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'`
48
49
49 if echo $hgversion | grep -- '-' > /dev/null 2>&1; then
50 if echo $hgversion | grep -- '-' > /dev/null 2>&1; then
50 # nightly build case, version is like 1.3.1+250-20b91f91f9ca
51 # nightly build case, version is like 1.3.1+250-20b91f91f9ca
51 version=`echo $hgversion | cut -d- -f1`
52 version=`echo $hgversion | cut -d- -f1`
52 release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'`
53 release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'`
53 else
54 else
54 # official tag, version is like 1.3.1
55 # official tag, version is like 1.3.1
55 version=`echo $hgversion | sed -e 's/+.*//'`
56 version=`echo $hgversion | sed -e 's/+.*//'`
56 release='0'
57 release='0'
57 fi
58 fi
58 tip=`$HG -q tip`
59 tip=`$HG -q tip`
59
60
60 # Beat up the spec file
61 # Beat up the spec file
61 sed -e 's,^Source:.*,Source: /dev/null,' \
62 sed -e 's,^Source:.*,Source: /dev/null,' \
62 -e "s,^Version:.*,Version: $version," \
63 -e "s,^Version:.*,Version: $version," \
63 -e "s,^Release:.*,Release: $release," \
64 -e "s,^Release:.*,Release: $release," \
64 -e "s,^%prep.*,Changeset: $tip\n\0," \
65 -e "s,^%prep.*,Changeset: $tip\n\0," \
65 -e 's,^%setup.*,,' \
66 -e 's,^%setup.*,,' \
66 $specfile > $tmpspec
67 $specfile > $tmpspec
67
68
68 cat <<EOF >> $tmpspec
69 cat <<EOF >> $tmpspec
69 %changelog
70 %changelog
70 * `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release
71 * `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release
71 - Automatically built via $0
72 - Automatically built via $0
72
73
73 EOF
74 EOF
74 $HG log \
75 $HG log \
75 --template '* {date|rfc822date} {author}\n- {desc|firstline}\n\n' \
76 --template '* {date|rfc822date} {author}\n- {desc|firstline}\n\n' \
76 .hgtags \
77 .hgtags \
77 | sed -e 's/^\(\* [MTWFS][a-z][a-z]\), \([0-3][0-9]\) \([A-Z][a-z][a-z]\) /\1 \3 \2 /' \
78 | sed -e 's/^\(\* [MTWFS][a-z][a-z]\), \([0-3][0-9]\) \([A-Z][a-z][a-z]\) /\1 \3 \2 /' \
78 -e '/^\* [MTWFS][a-z][a-z] /{s/ [012][0-9]:[0-9][0-9]:[0-9][0-9] [+-][0-9]\{4\}//}' \
79 -e '/^\* [MTWFS][a-z][a-z] /{s/ [012][0-9]:[0-9][0-9]:[0-9][0-9] [+-][0-9]\{4\}//}' \
79 >> $tmpspec
80 >> $tmpspec
80
81
81 rpmbuild --define "_topdir $rpmdir" -bb $tmpspec
82 rpmbuild --define "_topdir $rpmdir" -bb $tmpspec
82 if [ $? = 0 ]; then
83 if [ $? = 0 ]; then
83 rm -rf $tmpspec $rpmdir/BUILD
84 rm -rf $tmpspec $rpmdir/BUILD
84 mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS
85 mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS
85 echo
86 echo
86 echo "Packages are in $rpmdir:"
87 echo "Packages are in $rpmdir:"
87 ls -l $rpmdir/*.rpm
88 ls -l $rpmdir/*.rpm
88 fi
89 fi
General Comments 0
You need to be logged in to leave comments. Login now