Handled dsc being hardlinked into backup subdirectory
[xapian.git] / xapian-maintainer-tools / debian / backport-source-packages
blob510b0f66b35f5ecb42ea22892507150f45ad842b
1 #!/bin/sh
2 # Backport Debian source packages for Xapian.
4 # Copyright (C) 2004 Richard Boulton
5 # Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2015,2016 Olly Betts
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 # USA
22 # Dependencies:
23 # dch from package devscripts.
25 set -e
27 #MIRROR=http://ftp.de.debian.org/debian/
28 MIRROR=http://ftp.nz.debian.org/debian/
30 # Can't backport direct to squeeze from stretch
31 DEBIAN_CODENAMES='jessie wheezy'
32 UBUNTU_CODENAMES='wily trusty precise'
33 UBUNTU_FIRST=`echo "$UBUNTU_CODENAMES"|sed 's/.* //'`
35 V_OPT=
36 case $1 in
37 -v)
38 V_OPT="$1$2"
39 shift
40 shift
42 -v*)
43 V_OPT=$1
44 shift
46 esac
48 if [ x"$1" = x--help -o $# -lt 2 ] ; then
49 echo "Usage: $0 [-v <last uploaded version>] SOURCE_PKG VERSION [CODENAME...]"
50 echo
51 echo "e.g.: $0 xapian-core 1.2.15-1 precise"
52 echo 'If no codenames are specified, the default is to backport for all of them.'
53 echo
54 echo "Currently, the recognised values are:"
55 echo " $DEBIAN_CODENAMES"
56 echo " $UBUNTU_CODENAMES"
57 echo "And the magic values which expand to the above lists:"
58 echo " debian ubuntu"
59 exit 0
62 PKG=$1
63 VERSION=$2
64 shift
65 shift
67 SUFFIX=`echo "$VERSION"|sed 's/.*-/-/'`
68 VERSION=`echo "$VERSION"|sed 's/-[^-]*$//'`
70 # Debian/Ubuntu codename or codenames to build for.
71 # This will be overridden by the command line arguments, if any were passed.
72 CODENAMES="$DEBIAN_CODENAMES $UBUNTU_CODENAMES"
74 # Options to pass to dpkg-buildpackage when building source packages
75 BUILDPACKAGE_SRC_OPTS="-us -uc -d -S $V_OPT"
77 # Add entry to changelog if we're backporting.
78 adjust_changelog() {
79 if [ sid != "$CODENAME" ] ; then
80 base_version=`dpkg-parsechangelog|sed 's/^Version: //p;d'`
81 backport_version=$base_version$BACKPORT_SUFFIX
82 # --force-bad-version needed for backporting, since the "new" version may
83 # be less than the "old". Direct stdin from /dev/null to prevent dch
84 # stopping to confirm the bad version is OK.
85 if [ 1 = "$ubuntu" ] ; then
86 distribution=$CODENAME
87 elif [ "`echo "$DEBIAN_CODENAMES"|cut -d' ' -f1`" = "$CODENAME" ] ; then
88 # Backport for the most recent stable debian release.
89 distribution=$CODENAME-backports
90 else
91 distribution=$CODENAME-backports-sloppy
93 dch --force-bad-version -v "$backport_version" -D "$distribution" \
94 "Rebuild for $CODENAME backports." < /dev/null
98 build_it() {
99 adjust_changelog
101 case `grep -c '^[^#]*\<CODENAME\>' debian/rules` in
103 echo 'Failed to grep debian/rules'
104 exit 1
106 [01])
107 # Run maintclean and maint targets, if they exist.
108 fakeroot debian/rules maintclean || true
109 fakeroot debian/rules maint || true
112 # If debian/rules has at least two non-commented out references to
113 # CODENAME then create debian/codename.
114 echo "$CODENAME" > debian/codename
115 # Generates control from control.in (and maybe other files).
116 fakeroot debian/rules maintclean CODENAME="$CODENAME"
117 fakeroot debian/rules maint CODENAME="$CODENAME" $overrides
119 esac
121 # We don't really want to upload the orig tarball for all Ubuntu backports,
122 # only if it isn't already in the archive. So for now, just upload it for
123 # the first codename in alphabetical order.
124 if [ "$UBUNTU_FIRST" = "$CODENAME" ] ; then
125 include_src_opt=-sa
126 else
127 # The default is -si, which used to check for -0 or -1, but now looks for
128 # a change in upstream version number. Once that change is in all releases
129 # we care about, we can remove this setting (FIXME).
130 include_src_opt=-sd
132 debuild ${BUILDPACKAGE_SRC_OPTS} $include_src_opt
134 if [ 1 != "$ubuntu" ] ; then
135 # Debian
136 echo "sbuild --debbuildopt=$V_OPT -d $CODENAME-backports ${PKG}_$backport_version.dsc"
140 # Get the codename(s) specified by the user.
141 if [ -n "$*" ] ; then
142 CODENAMES=`echo "$*"|sed 's/\<debian\>/'"$DEBIAN_CODENAMES"'/;s/\<ubuntu\>/'"$UBUNTU_CODENAMES"'/'`
145 ubuntu=0
146 for CODENAME in $CODENAMES ; do
147 # Check that the codename is known.
148 DEBIAN_CODENAMES_RE='\('`echo "$DEBIAN_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
149 UBUNTU_CODENAMES_RE='\('`echo "$UBUNTU_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
150 if expr "$CODENAME" : "$DEBIAN_CODENAMES_RE" >/dev/null ; then
151 echo "Making source packages for $CODENAME"
152 if [ -z "$V_OPT" ] ; then
153 echo 'You need to specify -v<last backported version> for debian backports'
154 exit 1
156 elif expr "$CODENAME" : "$UBUNTU_CODENAMES_RE" >/dev/null ; then
157 echo "Making source packages for $CODENAME"
158 ubuntu=1
159 else
160 echo "Codename \"$CODENAME\" not known."
161 echo "Known codenames are: $DEBIAN_CODENAMES $UBUNTU_CODENAMES"
162 exit 1
165 trap "echo \"backport-source-packages failed\"" EXIT
167 # $BACKPORT_SUFFIX holds a suffix to be added to the debian version number for
168 # the backport.
170 # We need to add a suffix to the debian version number for the backported
171 # package to avoid conflicts with the package in unstable.
172 # For Ubuntu we add ".99$CODENAME" since it should sort
173 # before any other modification (and since dapper, Ubuntu codenames are
174 # allocated alphabetically). For Debian releases, we use
175 # backports.org-compatible package versions - e.g. we append "~bpo8+1" for
176 # Debian 8 (jessie) (and a suffix starting "~" sorts as less than no suffix).
177 case $CODENAME in
178 jessie)
179 BACKPORT_SUFFIX='~bpo8+1' ;;
180 wheezy)
181 BACKPORT_SUFFIX='~bpo7+1' ;;
182 squeeze)
183 BACKPORT_SUFFIX='~bpo60+1' ;;
185 if [ x"$ubuntu" = x0 ] ; then
186 echo "Debian codename '$CODENAME' not mapped to a ~bpoN+1 suffix"
187 exit 1
189 BACKPORT_SUFFIX=".99$CODENAME" ;;
190 esac
192 # Unpack distribution tarballs, and put the debian control files into place,
193 # and build source packages
194 mkdir -p build
195 cd build
196 case $PKG in
197 lib*) DIR=`echo $PKG|cut -c1,2,3,4` ;;
198 *) DIR=`echo $PKG|cut -c1` ;;
199 esac
200 DSC=${PKG}_$VERSION$SUFFIX.dsc
201 if [ -f "$DSC" ] ; then
202 [ -d backup ] || mkdir backup
203 if ! mv "$DSC" backup ; then
204 # Handle dsc being hardlinked into backup already.
205 cmp "$DSC" "backup/$DSC" && rm -f "$DSC"
207 dget -b "file://`pwd`/backup/$DSC"
208 else
209 dget "${MIRROR}pool/main/$DIR/$PKG/$DSC"
211 cd ${PKG}-${VERSION}
212 build_it
213 cd ..
214 rm -rf ${PKG}-${VERSION}
215 cd ..
217 echo "Backported ${PKG} ${VERSION} for $CODENAME successfully"
218 done
220 trap - EXIT