author | Gilles Moris <gilles.moris@free.fr> |
Fri, 06 Nov 2009 09:35:38 +0100 | |
changeset 9811 | c92ac5a56f69 |
parent 9810 | 326a0a6453a3 |
child 9812 | dd2c95fc4fe5 |
permissions | -rwxr-xr-x |
564 | 1 |
#!/bin/sh |
2 |
# |
|
3 |
# Build a Mercurial RPM in place. |
|
4 |
# |
|
5 |
# Bryan O'Sullivan <bos@serpentine.com> |
|
8867
ff817723280a
contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents:
7431
diff
changeset
|
6 |
# |
ff817723280a
contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents:
7431
diff
changeset
|
7 |
# Tested on |
ff817723280a
contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents:
7431
diff
changeset
|
8 |
# - Fedora 10 |
ff817723280a
contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents:
7431
diff
changeset
|
9 |
# - Fedora 11 |
ff817723280a
contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents:
7431
diff
changeset
|
10 |
# - Centos 5.3 (with Fedora EPEL repo for asciidoc) |
564 | 11 |
|
9811
c92ac5a56f69
buildrpm: enable to start the script from anywhere
Gilles Moris <gilles.moris@free.fr>
parents:
9810
diff
changeset
|
12 |
cd "`dirname $0`/.." |
c92ac5a56f69
buildrpm: enable to start the script from anywhere
Gilles Moris <gilles.moris@free.fr>
parents:
9810
diff
changeset
|
13 |
HG="$PWD/hg" |
c92ac5a56f69
buildrpm: enable to start the script from anywhere
Gilles Moris <gilles.moris@free.fr>
parents:
9810
diff
changeset
|
14 |
PYTHONPATH="$PWD/mercurial/pure" |
8869
d244ee52ac30
contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents:
8868
diff
changeset
|
15 |
export PYTHONPATH |
7431
3d827cc616b6
buildrpm: complain when hg command isn't available
Mads Kiilerich <mads@kiilerich.com>
parents:
7277
diff
changeset
|
16 |
|
8869
d244ee52ac30
contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents:
8868
diff
changeset
|
17 |
root="`$HG root 2>/dev/null`" |
564 | 18 |
specfile=contrib/mercurial.spec |
19 |
||
20 |
if [ -z "$root" ]; then |
|
21 |
echo 'You are not inside a Mercurial repository!' 1>&2 |
|
22 |
exit 1 |
|
23 |
fi |
|
24 |
||
9810
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
25 |
if $HG id -i | grep '+$' > /dev/null 2>&1; then |
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
26 |
echo -n "Your local changes will NOT be in the RPM. Continue [y/n] ? " |
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
27 |
read answer |
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
28 |
if echo $answer | grep -iv '^y'; then |
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
29 |
exit |
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
30 |
fi |
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
31 |
fi |
326a0a6453a3
buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents:
9809
diff
changeset
|
32 |
|
7277
3e000e2bf5f6
Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents:
4755
diff
changeset
|
33 |
rpmdir=/tmp/"`basename $root | sed 's/ /_/'`"-rpm # FIXME: Insecure /tmp handling |
564 | 34 |
|
35 |
cd "$root" |
|
36 |
rm -rf $rpmdir |
|
37 |
mkdir -p $rpmdir/RPMS |
|
9809
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
38 |
$HG clone -u . "$root" $rpmdir/BUILD |
564 | 39 |
|
40 |
if [ ! -f $specfile ]; then |
|
41 |
echo "Cannot find $specfile!" 1>&2 |
|
42 |
exit 1 |
|
43 |
fi |
|
44 |
||
7277
3e000e2bf5f6
Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents:
4755
diff
changeset
|
45 |
tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling |
9809
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
46 |
# make setup.py build the version string |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
47 |
python setup.py build_py -c -d . |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
48 |
hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'` |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
49 |
|
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
50 |
if echo $hgversion | grep -- '-' > /dev/null 2>&1; then |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
51 |
# nightly build case, version is like 1.3.1+250-20b91f91f9ca |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
52 |
version=`echo $hgversion | cut -d- -f1` |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
53 |
release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'` |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
54 |
else |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
55 |
# official tag, version is like 1.3.1 |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
56 |
version=`echo $hgversion | sed -e 's/+.*//'` |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
57 |
release='0' |
ce145bf2ca5e
buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents:
8906
diff
changeset
|
58 |
fi |
8869
d244ee52ac30
contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents:
8868
diff
changeset
|
59 |
tip=`$HG -q tip` |
564 | 60 |
|
61 |
# Beat up the spec file |
|
62 |
sed -e 's,^Source:.*,Source: /dev/null,' \ |
|
63 |
-e "s,^Version:.*,Version: $version," \ |
|
64 |
-e "s,^Release:.*,Release: $release," \ |
|
65 |
-e "s,^%prep.*,Changeset: $tip\n\0," \ |
|
66 |
-e 's,^%setup.*,,' \ |
|
67 |
$specfile > $tmpspec |
|
68 |
||
4754
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
69 |
cat <<EOF >> $tmpspec |
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
70 |
%changelog |
8906
bb255fe7c27e
contrib/buildrpm: force en_US locale during changelog's creation
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
8869
diff
changeset
|
71 |
* `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release |
4754
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
72 |
- Automatically built via $0 |
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
73 |
|
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
74 |
EOF |
8869
d244ee52ac30
contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents:
8868
diff
changeset
|
75 |
$HG log \ |
4754
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
76 |
--template '* {date|rfc822date} {author}\n- {desc|firstline}\n\n' \ |
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
77 |
.hgtags \ |
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
78 |
| sed -e 's/^\(\* [MTWFS][a-z][a-z]\), \([0-3][0-9]\) \([A-Z][a-z][a-z]\) /\1 \3 \2 /' \ |
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
79 |
-e '/^\* [MTWFS][a-z][a-z] /{s/ [012][0-9]:[0-9][0-9]:[0-9][0-9] [+-][0-9]\{4\}//}' \ |
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
80 |
>> $tmpspec |
e5e6dd8ba6bb
buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents:
564
diff
changeset
|
81 |
|
564 | 82 |
rpmbuild --define "_topdir $rpmdir" -bb $tmpspec |
83 |
if [ $? = 0 ]; then |
|
84 |
rm -rf $tmpspec $rpmdir/BUILD |
|
85 |
mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS |
|
86 |
echo |
|
7277
3e000e2bf5f6
Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents:
4755
diff
changeset
|
87 |
echo "Packages are in $rpmdir:" |
3e000e2bf5f6
Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents:
4755
diff
changeset
|
88 |
ls -l $rpmdir/*.rpm |
564 | 89 |
fi |