blob: eb19a9da86bb26f7db206be132d3e4c9ee9692e2 [file] [log] [blame]
James Kuszmaul4cb043c2021-01-17 11:25:51 -08001#!/bin/bash -e
2# $Id: make-deb 2770 2013-05-30 08:46:46Z dreibh $
3#
4# Debian Packaging Scripts
5# Copyright (C) 2002-2017 by Thomas Dreibholz
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
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.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20# Contact: dreibh@iem.uni-due.de
21
22
23# ---------------------------------------------------------------------------
24# USAGE:
25# ./make-deb default => for Ubuntu REVU
26# Note: Replaces "Maintainer" by Ubuntu Developers and
27# writes original maintainer entry to "XSBC-Original-Maintainer"
28# ./make-deb unstable => for Debian Mentors
29# ./make-deb natty|maverick|... => for Launchpad PPA
30# ---------------------------------------------------------------------------
31
32
33DISTRIBUTIONS=`\
34( \
35while [ x$1 != "x" ] ; do \
36 echo $1
37 shift
38done \
39) | sort -u`
40if [ "$DISTRIBUTIONS" == "" ] ; then
41 DISTRIBUTIONS="default"
42fi
43
44
45CHANGELOG_HEADER="`head -n1 debian/changelog`"
46
47# The package name, e.g. MyApplication
48PACKAGE=`echo $CHANGELOG_HEADER | sed -e "s/(.*//" -e "s/ //g"`
49
50# The package distribution, e.g. precise, raring, ...
51PACKAGE_DISTRIBUTION=`echo $CHANGELOG_HEADER | sed -e "s/[^)]*)//" -e "s/;.*//g" -e "s/ //g"`
52# The package's version, e.g. 1.2.3-1ubuntu1
53PACKAGE_VERSION=`echo $CHANGELOG_HEADER | sed -e "s/.*(//" -e "s/).*//" -e "s/ //g" -e "s/ //g" -e "s/^[0-9]://g"`
54# The package's output version, e.g. 1.2.3-1ubuntu
55OUTPUT_VERSION=`echo $PACKAGE_VERSION | sed -e "s/\(ubuntu\|ppa\)[0-9]*$/\1/"`
56# The package's Debian version, e.g. 1.2.3-1
57DEBIAN_VERSION=`echo $OUTPUT_VERSION | sed -e "s/\(ubuntu\|ppa\)$//1"`
58# The package's upstream version, e.g. 1.2.3
59UPSTREAM_VERSION=`echo $DEBIAN_VERSION | sed -e "s/-[0-9]*$//"`
60# The package's plain upstream version, e.g. 1.2.3 (without e.g. ~svn<xxxx>)
61PLAIN_VERSION=`echo $UPSTREAM_VERSION | sed -e "s/\([0-9\.]*\)[-+~].*$/\1/"`
62
63
64echo -e "\x1b[34m######################################################################\x1b[0m"
65echo -e "\x1b[34mCHANGELOG_HEADER: $CHANGELOG_HEADER\x1b[0m"
66echo -e "\x1b[34mPACKAGE: $PACKAGE\x1b[0m"
67echo -e "\x1b[34mPACKAGE_DISTRIBUTION: $PACKAGE_DISTRIBUTION\x1b[0m"
68echo -e "\x1b[34mPACKAGE_VERSION $PACKAGE_VERSION\x1b[0m"
69echo -e "\x1b[34mOUTPUT_VERSION: $OUTPUT_VERSION\x1b[0m"
70echo -e "\x1b[34mDEBIAN_VERSION: $DEBIAN_VERSION\x1b[0m"
71echo -e "\x1b[34mUPSTREAM_VERSION: $UPSTREAM_VERSION\x1b[0m"
72echo -e "\x1b[34mPLAIN_VERSION: $PLAIN_VERSION\x1b[0m"
73echo -e "\x1b[34m######################################################################\x1b[0m"
74
75if [ ! -e ./debian.conf ] ; then
76 echo >&2 "ERROR: debian.conf does not exist -> no configuration for the new package!"
77 exit 1
78fi
79. ./debian.conf
80
81
82echo -e ""
83echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Calling wrap-and-sort ==========================================\x1b[0m"
84echo -e ""
85wrap-and-sort -a -v || exit 1
86
87
88echo -e ""
89echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating upstream package ======================================\x1b[0m"
90echo -e ""
91UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.gz" -printf '%f'`"
92UPSTREAM_PACKAGE_TYPE="gz"
93if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
94 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.bz2" -printf '%f'`"
95 UPSTREAM_PACKAGE_TYPE="bz2"
96fi
97if [ ! -e "$UPSTREAM_PACKAGE" ]; then
98 rm -f $PACKAGE-*.gz $PACKAGE"_"*.gz $PACKAGE-*.bz2 $PACKAGE"_"*.bz2
99 echo -e "\x1b[34m------ Running MAKE_DIST ... ------\x1b[0m"
100 echo "\$ $MAKE_DIST"
101 eval "$MAKE_DIST"
102
103 echo -e "\x1b[34m------ Looking for upstream package ... ------\x1b[0m"
104 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.gz -printf '%f'`"
105 UPSTREAM_PACKAGE_TYPE="gz"
106 if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
107 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.bz2 -printf '%f'`"
108 UPSTREAM_PACKAGE_TYPE="bz2"
109 fi
110 if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
111 echo -e "\x1b[34mERROR: No upstrem package found!\x1b[0m"
112 exit 1
113 fi
114fi
115echo -e ""
116echo -e "\x1b[34m==> Upstream package is $UPSTREAM_PACKAGE (type is $UPSTREAM_PACKAGE_TYPE)\x1b[0m"
117echo -e ""
118
119
120echo -e ""
121echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating packages ==============================================\x1b[0m"
122for DISTRIBUTION in $DISTRIBUTIONS ; do
123
124 echo -e ""
125 echo -e "\x1b[34m------ Creating package for $DISTRIBUTION ------\x1b[0m"
126
127 success=1
128 cp ${UPSTREAM_PACKAGE} ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.$UPSTREAM_PACKAGE_TYPE
129 cp ${UPSTREAM_PACKAGE} ${PACKAGE}_$OUTPUT_VERSION.orig.tar.$UPSTREAM_PACKAGE_TYPE
130 cp ${UPSTREAM_PACKAGE} ${PACKAGE}_$DEBIAN_VERSION.orig.tar.$UPSTREAM_PACKAGE_TYPE
131 rm -rf ${PACKAGE}-${UPSTREAM_VERSION}
132 rm -rf ${PACKAGE}-${UPSTREAM_VERSION}.orig
133 if [ "$UPSTREAM_PACKAGE_TYPE" = "gz" ] ; then
134 tar xzf ${UPSTREAM_PACKAGE}
135 elif [ "$UPSTREAM_PACKAGE_TYPE" = "bz2" ] ; then
136 tar xjf ${UPSTREAM_PACKAGE}
137 else
138 echo 2>&1 "ERROR: Bad archive format: $UPSTREAM_PACKAGE"
139 exit 1
140 fi
141 cp -r ${PACKAGE}-${UPSTREAM_VERSION} ${PACKAGE}-${UPSTREAM_VERSION}.orig
142 cp -r debian ${PACKAGE}-${UPSTREAM_VERSION}
143 find ${PACKAGE}-${UPSTREAM_VERSION} -name .svn | xargs --no-run-if-empty rm -rf
144 cd ${PACKAGE}-${UPSTREAM_VERSION}
145 success=0
146
147 if [ $success -ne 0 ] ; then
148 exit 1
149 fi
150
151 if [ "$DISTRIBUTION" != "default" ] ; then
152 if [ "$DISTRIBUTION" = "unstable" -o "$DISTRIBUTION" = "testing" -o "$DISTRIBUTION" = "stable" ] ; then
153 # Debian: Also remove Launchpad Bug IDs.
154 sed -e "s/$PACKAGE_DISTRIBUTION;/$DISTRIBUTION;/1" \
155 -e "s/\(ubuntu\|ppa\)[0-9]//1" \
156 -e "/(LP: #/D" \
157 <debian/changelog | ../filter-empty-entries "$DEBIAN_LAST_ENTRY" >debian/changelog.new
158 else
159 # Ubuntu PPA
160 # Naming example: 2.7.7-0ubuntu1~natty1~ppa0
161 # Ubuntu: Also remove Debian Bug IDs.
162 sed -e "s/$PACKAGE_DISTRIBUTION;/$DISTRIBUTION;/1" \
163 -e "s/$PACKAGE_VERSION/$PACKAGE_VERSION~${DISTRIBUTION}1~ppa0/1" \
164 -e "/(Closes: #/D" \
165 <debian/changelog | ../filter-empty-entries "$UBUNTU_LAST_ENTRY" >debian/changelog.new
166
167 # ------ Old distributions not supporting c++/regex style symbols --
168 if [ "$DISTRIBUTION" = "dapper" -o \
169 "$DISTRIBUTION" = "edgy" -o \
170 "$DISTRIBUTION" = "feisty" -o \
171 "$DISTRIBUTION" = "hardy" -o \
172 "$DISTRIBUTION" = "intrepid" -o \
173 "$DISTRIBUTION" = "jaunty" -o \
174 "$DISTRIBUTION" = "karmic" -o \
175 "$DISTRIBUTION" = "lucid" ] ; then
176 # Just skip the symbols ...
177 find debian/ -maxdepth 1 -name "*.symbols" | xargs --no-run-if-empty rm -f
178 fi
179 fi
180 mv debian/changelog.new debian/changelog
181
182 # ------ Old distributions not supporting new Debian format -----------
183 if [ "$DISTRIBUTION" = "dapper" -o \
184 "$DISTRIBUTION" = "edgy" -o \
185 "$DISTRIBUTION" = "feisty" -o \
186 "$DISTRIBUTION" = "hardy" -o \
187 "$DISTRIBUTION" = "intrepid" -o \
188 "$DISTRIBUTION" = "jaunty" ] ; then
189 rm -rf debian/source
190 fi
191 # ---------------------------------------------------------------------
192 else
193 # Ubuntu: Remove Debian Bug IDs.
194 sed -e "/(Closes: #/D" \
195 <debian/changelog >debian/changelog.new
196 mv debian/changelog.new debian/changelog
197 sed -e "s/^Maintainer:/Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\nXSBC-Original-Maintainer:/g" <debian/control >debian/control.new
198 mv debian/control.new debian/control
199 fi
200
201 echo -e ""
202 echo -e "\x1b[34m------ Creating diff file $PACKAGE-$PACKAGE_VERSION.diff.gz ------\x1b[0m"
203 (
204 cd ..
205 diff -urN "--exclude=*~" "--exclude=.svn" "--exclude=.git" \
206 $PACKAGE-$UPSTREAM_VERSION.orig $PACKAGE-$UPSTREAM_VERSION \
207 | gzip -c >$PACKAGE-$PACKAGE_VERSION.diff.gz
208 )
209
210
211 echo -e ""
212 echo -e "\x1b[34m------ Building source package ------\x1b[0m"
213
214 # Without signature:
215 # debuild -us -uc
216 # For sources:
217 # debuild -S
218 # For binaries:
219 # debuild -b
220 # Use -i to ignore .svn files!
221
222
223 if [ "$SKIP_PACKAGE_SIGNING" = "" ] ; then
224 SKIP_PACKAGE_SIGNING=0
225 fi
226 if [ $SKIP_PACKAGE_SIGNING -eq 1 ] ; then
227 # Build source package without signature:
228 debuild -us -uc -S "-k$MAINTAINER" -i || exit 1
229 else
230 # Build source package including signature:
231 debuild -sa -S "-k$MAINTAINER" -i || exit 1
232 fi
233
234 # Important: In /etc/pbuilderrc, set COMPONENTS="main universe"!
235 # Important: After that, update with option "--override-config"!
236 # sudo pbuilder update --override-config
237
238 cd ..
239
240 if [ "$DISTRIBUTION" = "unstable" -o \
241 "$DISTRIBUTION" = "testing" -o \
242 "$DISTRIBUTION" = "stable" -o \
243 "$DISTRIBUTION" = "default" ] ; then
244 if [ "$DISTRIBUTION" = "default" ] ; then
245 version=${PACKAGE_VERSION}
246 else
247 version=${DEBIAN_VERSION}
248 fi
249 dscFile=`ls ${PACKAGE}_${version}.dsc | tail -n1`
250 else
251 dscFile=`ls ${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9].dsc | tail -n1`
252 fi
253 if [ ! -e $dscFile ] ; then
254 echo -e "\x1b[34mERROR: $dscFile has not been generated successfully -> Aborting!\x1b[0m"
255 exit 1
256 fi
257
258done
259
260
261
262if [ -e "$UPSTREAM_PACKAGE.asc" ] ; then
263 rm -f "$UPSTREAM_PACKAGE.asc"
264fi
265if [ "$SKIP_PACKAGE_SIGNING" != "" -a ! $SKIP_PACKAGE_SIGNING -eq 1 ] ; then
266 echo -e ""
267 echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Sign upstream package ==========================================\x1b[0m"
268 echo -e ""
269 echo -e "\x1b[34mSigning upstream package $UPSTREAM_PACKAGE ...\x1b[0m"
270 gpg -sab "$UPSTREAM_PACKAGE"
271fi
272
273
274
275echo -e ""
276echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Command overview ===============================================\x1b[0m"
277echo -e ""
278
279echo -e "\x1b[34mUpload to PPA:\x1b[0m"
280for DISTRIBUTION in $DISTRIBUTIONS ; do
281 if [ "$DISTRIBUTION" = "unstable" -o \
282 "$DISTRIBUTION" = "testing" -o \
283 "$DISTRIBUTION" = "stable" -o \
284 "$DISTRIBUTION" = "default" ] ; then
285 if [ "$DISTRIBUTION" = "default" ] ; then
286 ppa="revu"
287 version=${PACKAGE_VERSION}
288 else
289 ppa="mentors"
290 version=${DEBIAN_VERSION}
291 fi
292 changesFile=`ls ${PACKAGE}_${version}_source.changes | tail -n1`
293 else
294 ppa="ppa"
295 changesFile=`ls ${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9]_source.changes | tail -n1`
296 fi
297 echo -e "\x1b[34m dput $ppa $changesFile\x1b[0m"
298done
299echo -e ""
300
301
302
303if [ -e make-symbols ] ; then
304 echo -e "\x1b[34m################################################################\x1b[0m"
305 echo -e "\x1b[34mDo not forget to run make-symbols after library version changes!\x1b[0m"
306 echo -e "\x1b[34m################################################################\x1b[0m"
307 echo -e ""
308fi
309
310echo -e "\x1b[34mBuild Test Commands:\x1b[0m"
311for DISTRIBUTION in $DISTRIBUTIONS ; do
312 if [ "$DISTRIBUTION" = "unstable" -o \
313 "$DISTRIBUTION" = "testing" -o \
314 "$DISTRIBUTION" = "stable" -o \
315 "$DISTRIBUTION" = "default" ] ; then
316 if [ "$DISTRIBUTION" = "default" ] ; then
317 version=${PACKAGE_VERSION}
318 else
319 version=${DEBIAN_VERSION}
320 fi
321 changesFilesPattern="${PACKAGE}_${version}_*.changes"
322 dscFile=`ls ${PACKAGE}_${version}.dsc | tail -n1`
323 else
324 changesFilesPattern="${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9]_*.changes"
325 dscFile=`ls ${PACKAGE}_${PACKAGE_VERSION}~${DISTRIBUTION}[0-9]~ppa[0-9].dsc | tail -n1`
326 fi
327 echo -e "\x1b[34m sudo pbuilder build $dscFile && lintian -iIEv --pedantic /var/cache/pbuilder/result/$changesFilesPattern\x1b[0m"
328done
329echo -e ""