##// END OF EJS Templates
buildrpm: do not break in presence of custom user configs...
muxator -
r33649:5aac617a default
parent child Browse files
Show More
@@ -1,161 +1,163
1 #!/bin/bash -e
1 #!/bin/bash -e
2 #
2 #
3 # Build a Mercurial RPM from the current repo
3 # Build a Mercurial RPM from the current repo
4 #
4 #
5 # Tested on
5 # Tested on
6 # - Fedora 20
6 # - Fedora 20
7 # - CentOS 5
7 # - CentOS 5
8 # - centOS 6
8 # - centOS 6
9
9
10 . $(dirname $0)/packagelib.sh
10 . $(dirname $0)/packagelib.sh
11
11
12 BUILD=1
12 BUILD=1
13 RPMBUILDDIR="$PWD/rpmbuild"
13 RPMBUILDDIR="$PWD/rpmbuild"
14 export HGPLAIN=
15
14 while [ "$1" ]; do
16 while [ "$1" ]; do
15 case "$1" in
17 case "$1" in
16 --prepare )
18 --prepare )
17 shift
19 shift
18 BUILD=
20 BUILD=
19 ;;
21 ;;
20 --withpython | --with-python)
22 --withpython | --with-python)
21 shift
23 shift
22 PYTHONVER=2.7.10
24 PYTHONVER=2.7.10
23 PYTHONMD5=d7547558fd673bd9d38e2108c6b42521
25 PYTHONMD5=d7547558fd673bd9d38e2108c6b42521
24 ;;
26 ;;
25 --rpmbuilddir )
27 --rpmbuilddir )
26 shift
28 shift
27 RPMBUILDDIR="$1"
29 RPMBUILDDIR="$1"
28 shift
30 shift
29 ;;
31 ;;
30 * )
32 * )
31 echo "Invalid parameter $1!" 1>&2
33 echo "Invalid parameter $1!" 1>&2
32 exit 1
34 exit 1
33 ;;
35 ;;
34 esac
36 esac
35 done
37 done
36
38
37 cd "`dirname $0`/.."
39 cd "`dirname $0`/.."
38
40
39 specfile=$PWD/contrib/mercurial.spec
41 specfile=$PWD/contrib/mercurial.spec
40 if [ ! -f $specfile ]; then
42 if [ ! -f $specfile ]; then
41 echo "Cannot find $specfile!" 1>&2
43 echo "Cannot find $specfile!" 1>&2
42 exit 1
44 exit 1
43 fi
45 fi
44
46
45 if [ ! -d .hg ]; then
47 if [ ! -d .hg ]; then
46 echo 'You are not inside a Mercurial repository!' 1>&2
48 echo 'You are not inside a Mercurial repository!' 1>&2
47 exit 1
49 exit 1
48 fi
50 fi
49
51
50 gethgversion
52 gethgversion
51
53
52 # TODO: handle distance/node set, and type set
54 # TODO: handle distance/node set, and type set
53
55
54 if [ -z "$type" ] ; then
56 if [ -z "$type" ] ; then
55 release=1
57 release=1
56 else
58 else
57 release=0.9_$type
59 release=0.9_$type
58 fi
60 fi
59
61
60 if [ -n "$distance" ] ; then
62 if [ -n "$distance" ] ; then
61 release=$release+$distance_$node
63 release=$release+$distance_$node
62 fi
64 fi
63
65
64 if [ "$PYTHONVER" ]; then
66 if [ "$PYTHONVER" ]; then
65 release=$release+$PYTHONVER
67 release=$release+$PYTHONVER
66 RPMPYTHONVER=$PYTHONVER
68 RPMPYTHONVER=$PYTHONVER
67 else
69 else
68 RPMPYTHONVER=%{nil}
70 RPMPYTHONVER=%{nil}
69 fi
71 fi
70
72
71 mkdir -p $RPMBUILDDIR/{SOURCES,BUILD,SRPMS,RPMS}
73 mkdir -p $RPMBUILDDIR/{SOURCES,BUILD,SRPMS,RPMS}
72 $HG archive -t tgz $RPMBUILDDIR/SOURCES/mercurial-$version-$release.tar.gz
74 $HG archive -t tgz $RPMBUILDDIR/SOURCES/mercurial-$version-$release.tar.gz
73 if [ "$PYTHONVER" ]; then
75 if [ "$PYTHONVER" ]; then
74 (
76 (
75 mkdir -p build
77 mkdir -p build
76 cd build
78 cd build
77 PYTHON_SRCFILE=Python-$PYTHONVER.tgz
79 PYTHON_SRCFILE=Python-$PYTHONVER.tgz
78 [ -f $PYTHON_SRCFILE ] || curl -Lo $PYTHON_SRCFILE http://www.python.org/ftp/python/$PYTHONVER/$PYTHON_SRCFILE
80 [ -f $PYTHON_SRCFILE ] || curl -Lo $PYTHON_SRCFILE http://www.python.org/ftp/python/$PYTHONVER/$PYTHON_SRCFILE
79 if [ "$PYTHONMD5" ]; then
81 if [ "$PYTHONMD5" ]; then
80 echo "$PYTHONMD5 $PYTHON_SRCFILE" | md5sum -w -c
82 echo "$PYTHONMD5 $PYTHON_SRCFILE" | md5sum -w -c
81 fi
83 fi
82 ln -f $PYTHON_SRCFILE $RPMBUILDDIR/SOURCES/$PYTHON_SRCFILE
84 ln -f $PYTHON_SRCFILE $RPMBUILDDIR/SOURCES/$PYTHON_SRCFILE
83
85
84 DOCUTILSVER=`sed -ne "s/^%global docutilsname docutils-//p" $specfile`
86 DOCUTILSVER=`sed -ne "s/^%global docutilsname docutils-//p" $specfile`
85 DOCUTILS_SRCFILE=docutils-$DOCUTILSVER.tar.gz
87 DOCUTILS_SRCFILE=docutils-$DOCUTILSVER.tar.gz
86 [ -f $DOCUTILS_SRCFILE ] || curl -Lo $DOCUTILS_SRCFILE http://downloads.sourceforge.net/project/docutils/docutils/$DOCUTILSVER/$DOCUTILS_SRCFILE
88 [ -f $DOCUTILS_SRCFILE ] || curl -Lo $DOCUTILS_SRCFILE http://downloads.sourceforge.net/project/docutils/docutils/$DOCUTILSVER/$DOCUTILS_SRCFILE
87 DOCUTILSMD5=`sed -ne "s/^%global docutilsmd5 //p" $specfile`
89 DOCUTILSMD5=`sed -ne "s/^%global docutilsmd5 //p" $specfile`
88 if [ "$DOCUTILSMD5" ]; then
90 if [ "$DOCUTILSMD5" ]; then
89 echo "$DOCUTILSMD5 $DOCUTILS_SRCFILE" | md5sum -w -c
91 echo "$DOCUTILSMD5 $DOCUTILS_SRCFILE" | md5sum -w -c
90 fi
92 fi
91 ln -f $DOCUTILS_SRCFILE $RPMBUILDDIR/SOURCES/$DOCUTILS_SRCFILE
93 ln -f $DOCUTILS_SRCFILE $RPMBUILDDIR/SOURCES/$DOCUTILS_SRCFILE
92 )
94 )
93 fi
95 fi
94
96
95 mkdir -p $RPMBUILDDIR/SPECS
97 mkdir -p $RPMBUILDDIR/SPECS
96 rpmspec=$RPMBUILDDIR/SPECS/mercurial.spec
98 rpmspec=$RPMBUILDDIR/SPECS/mercurial.spec
97
99
98 sed -e "s,^Version:.*,Version: $version," \
100 sed -e "s,^Version:.*,Version: $version," \
99 -e "s,^Release:.*,Release: $release," \
101 -e "s,^Release:.*,Release: $release," \
100 $specfile > $rpmspec
102 $specfile > $rpmspec
101
103
102 echo >> $rpmspec
104 echo >> $rpmspec
103 echo "%changelog" >> $rpmspec
105 echo "%changelog" >> $rpmspec
104
106
105 if echo $version | grep '+' > /dev/null 2>&1; then
107 if echo $version | grep '+' > /dev/null 2>&1; then
106 latesttag="`echo $version | sed -e 's/+.*//'`"
108 latesttag="`echo $version | sed -e 's/+.*//'`"
107 $HG log -r .:"$latesttag" -fM \
109 $HG log -r .:"$latesttag" -fM \
108 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' | python -c '
110 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' | python -c '
109 import sys, time
111 import sys, time
110
112
111 def datestr(date, format):
113 def datestr(date, format):
112 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
114 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
113
115
114 changelog = []
116 changelog = []
115 for l in sys.stdin.readlines():
117 for l in sys.stdin.readlines():
116 tok = l.split("\t")
118 tok = l.split("\t")
117 hgdate = tuple(int(v) for v in tok[0].split())
119 hgdate = tuple(int(v) for v in tok[0].split())
118 changelog.append((datestr(hgdate, "%F"), tok[1], hgdate, tok[2]))
120 changelog.append((datestr(hgdate, "%F"), tok[1], hgdate, tok[2]))
119 prevtitle = ""
121 prevtitle = ""
120 for l in sorted(changelog, reverse=True):
122 for l in sorted(changelog, reverse=True):
121 title = "* %s %s" % (datestr(l[2], "%a %b %d %Y"), l[1])
123 title = "* %s %s" % (datestr(l[2], "%a %b %d %Y"), l[1])
122 if prevtitle != title:
124 if prevtitle != title:
123 prevtitle = title
125 prevtitle = title
124 print
126 print
125 print title
127 print title
126 print "- %s" % l[3].strip()
128 print "- %s" % l[3].strip()
127 ' >> $rpmspec
129 ' >> $rpmspec
128
130
129 else
131 else
130
132
131 $HG log \
133 $HG log \
132 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' \
134 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' \
133 .hgtags | python -c '
135 .hgtags | python -c '
134 import sys, time
136 import sys, time
135
137
136 def datestr(date, format):
138 def datestr(date, format):
137 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
139 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
138
140
139 for l in sys.stdin.readlines():
141 for l in sys.stdin.readlines():
140 tok = l.split("\t")
142 tok = l.split("\t")
141 hgdate = tuple(int(v) for v in tok[0].split())
143 hgdate = tuple(int(v) for v in tok[0].split())
142 print "* %s %s\n- %s" % (datestr(hgdate, "%a %b %d %Y"), tok[1], tok[2])
144 print "* %s %s\n- %s" % (datestr(hgdate, "%a %b %d %Y"), tok[1], tok[2])
143 ' >> $rpmspec
145 ' >> $rpmspec
144
146
145 fi
147 fi
146
148
147 sed -i \
149 sed -i \
148 -e "s/^%define withpython.*$/%define withpython $RPMPYTHONVER/" \
150 -e "s/^%define withpython.*$/%define withpython $RPMPYTHONVER/" \
149 $rpmspec
151 $rpmspec
150
152
151 if [ "$BUILD" ]; then
153 if [ "$BUILD" ]; then
152 rpmbuild --define "_topdir $RPMBUILDDIR" -ba $rpmspec --clean
154 rpmbuild --define "_topdir $RPMBUILDDIR" -ba $rpmspec --clean
153 if [ $? = 0 ]; then
155 if [ $? = 0 ]; then
154 echo
156 echo
155 echo "Built packages for $version-$release:"
157 echo "Built packages for $version-$release:"
156 find $RPMBUILDDIR/*RPMS/ -type f -newer $rpmspec
158 find $RPMBUILDDIR/*RPMS/ -type f -newer $rpmspec
157 fi
159 fi
158 else
160 else
159 echo "Prepared sources for $version-$release $rpmspec are in $RPMBUILDDIR/SOURCES/ - use like:"
161 echo "Prepared sources for $version-$release $rpmspec are in $RPMBUILDDIR/SOURCES/ - use like:"
160 echo "rpmbuild --define '_topdir $RPMBUILDDIR' -ba $rpmspec --clean"
162 echo "rpmbuild --define '_topdir $RPMBUILDDIR' -ba $rpmspec --clean"
161 fi
163 fi
General Comments 0
You need to be logged in to leave comments. Login now