-
Notifications
You must be signed in to change notification settings - Fork 19
/
make-deb
executable file
·369 lines (324 loc) · 14.8 KB
/
make-deb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/usr/bin/env bash
#
# Debian/Ubuntu Packaging Scripts
# Copyright (C) 2002-2024 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact: [email protected]
# Bash options:
set -e
# ---------------------------------------------------------------------------
# USAGE:
# ./make-deb default => for Ubuntu REVU
# Note: Replaces "Maintainer" by Ubuntu Developers and
# writes original maintainer entry to "XSBC-Original-Maintainer"
# ./make-deb unstable => for Debian Mentors
# ./make-deb bionic|disco|... => for Launchpad PPA
# ---------------------------------------------------------------------------
# Set current Debian debhelper version here
# for building unstable/testing/stable packages
# (See https://packages.qa.debian.org/d/debhelper.html for latest version!)
DEBHELPER_LATEST_VERSION="13"
# ====== Obtain package and version information =============================
DISTRIBUTIONS=`\
( \
while [ x$1 != "x" ] ; do \
echo $1
shift
done \
) | sort -u`
if [ "${DISTRIBUTIONS}" == "" ] ; then
DISTRIBUTIONS="default"
fi
CHANGELOG_HEADER="`head -n1 debian/changelog`"
# The package name, e.g. MyApplication
PACKAGE=`echo ${CHANGELOG_HEADER} | sed -e "s/(.*//" -e "s/ //g"`
# The package distribution, e.g. precise, raring, ...
PACKAGE_DISTRIBUTION=`echo ${CHANGELOG_HEADER} | sed -e "s/[^)]*)//" -e "s/;.*//g" -e "s/ //g"`
# The package's version, e.g. 1.2.3-1ubuntu1
PACKAGE_VERSION=`echo ${CHANGELOG_HEADER} | sed -e "s/.*(//" -e "s/).*//" -e "s/ //g" -e "s/ //g" -e "s/^[0-9]://g"`
# The package's output version, e.g. 1.2.3-1ubuntu
OUTPUT_VERSION=`echo ${PACKAGE_VERSION} | sed -e "s/\(ubuntu\|ppa\)[0-9]*$/\1/"`
# The package's Debian version, e.g. 1.2.3-1
DEBIAN_VERSION=`echo ${OUTPUT_VERSION} | sed -e "s/\(ubuntu\|ppa\)$//1"`
# The package's upstream version, e.g. 1.2.3
UPSTREAM_VERSION=`echo ${DEBIAN_VERSION} | sed -e "s/-[0-9]*$//"`
# The package's plain upstream version, e.g. 1.2.3 (without e.g. ~svn<xxxx>)
PLAIN_VERSION=`echo ${UPSTREAM_VERSION} | sed -e "s/\([0-9\.]*\)[-+~].*$/\1/"`
echo -e "\x1b[34m######################################################################\x1b[0m"
echo -e "\x1b[34mCHANGELOG_HEADER: ${CHANGELOG_HEADER}\x1b[0m"
echo -e "\x1b[34mPACKAGE: ${PACKAGE}\x1b[0m"
echo -e "\x1b[34mPACKAGE_DISTRIBUTION: ${PACKAGE_DISTRIBUTION}\x1b[0m"
echo -e "\x1b[34mPACKAGE_VERSION ${PACKAGE_VERSION}\x1b[0m"
echo -e "\x1b[34mOUTPUT_VERSION: ${OUTPUT_VERSION}\x1b[0m"
echo -e "\x1b[34mDEBIAN_VERSION: ${DEBIAN_VERSION}\x1b[0m"
echo -e "\x1b[34mUPSTREAM_VERSION: ${UPSTREAM_VERSION}\x1b[0m"
echo -e "\x1b[34mPLAIN_VERSION: ${PLAIN_VERSION}\x1b[0m"
echo -e "\x1b[34m######################################################################\x1b[0m"
if [ ! -e ./packaging.conf ] ; then
echo >&2 "ERROR: packaging.conf does not exist -> no configuration for the new package!"
exit 1
fi
. ./packaging.conf
# ====== Run warp-and-sort tool =============================================
if [ -e /usr/bin/wrap-and-sort ] ; then
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Calling wrap-and-sort ==========================================\x1b[0m"
echo -e ""
wrap-and-sort -a -v
fi
# ====== Create upstream source package =====================================
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating upstream package ======================================\x1b[0m"
echo -e ""
if [ "${SKIP_PACKAGE_SIGNING}" != "" -a ${SKIP_PACKAGE_SIGNING} -eq 1 -o "${OVERRIDE_SKIP_PACKAGE_SIGNING}" == "1" ] ; then
./make-upstream-package ${PACKAGE} ${UPSTREAM_VERSION} "${MAKE_DIST}" -skip-signing
else
./make-upstream-package ${PACKAGE} ${UPSTREAM_VERSION} "${MAKE_DIST}"
fi
for UPSTREAM_PACKAGE_TYPE in xz bz2 gz ; do
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "${PACKAGE}-${UPSTREAM_VERSION}.tar.${UPSTREAM_PACKAGE_TYPE}" -printf '%f'`"
if [ -e "${UPSTREAM_PACKAGE}" ] ; then
break
fi
done
if [ ! -e "${UPSTREAM_PACKAGE}" ] ; then
echo -e "\x1b[34mERROR: No upstream package (${PACKAGE}-${UPSTREAM_VERSION}.tar.*) found!\x1b[0m"
exit 1
fi
# ====== Build source packages ==============================================
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Building source packages =======================================\x1b[0m"
for DISTRIBUTION in ${DISTRIBUTIONS} ; do
updatedDebhelperVersion=0
echo -e ""
echo -e "\x1b[34m------ Creating package for ${DISTRIBUTION} ------\x1b[0m"
cp ${UPSTREAM_PACKAGE} ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}
cp ${UPSTREAM_PACKAGE} ${PACKAGE}_${OUTPUT_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}
cp ${UPSTREAM_PACKAGE} ${PACKAGE}_${DEBIAN_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}
if [ ! ${SKIP_PACKAGE_SIGNING} == "1" -a ! "${OVERRIDE_SKIP_PACKAGE_SIGNING}" == "1" ] ; then
cp ${UPSTREAM_PACKAGE}.asc ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}.asc
cp ${UPSTREAM_PACKAGE}.asc ${PACKAGE}_${OUTPUT_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}.asc
cp ${UPSTREAM_PACKAGE}.asc ${PACKAGE}_${DEBIAN_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}.asc
else
rm -f ${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}.asc
rm -f ${PACKAGE}_${OUTPUT_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}.asc
rm -f ${PACKAGE}_${DEBIAN_VERSION}.orig.tar.${UPSTREAM_PACKAGE_TYPE}.asc
fi
rm -rf ${PACKAGE}-${UPSTREAM_VERSION}
rm -rf ${PACKAGE}-${UPSTREAM_VERSION}.orig
if [ "${UPSTREAM_PACKAGE_TYPE}" == "gz" ] ; then
tar xzf ${UPSTREAM_PACKAGE}
elif [ "${UPSTREAM_PACKAGE_TYPE}" == "bz2" ] ; then
tar xjf ${UPSTREAM_PACKAGE}
elif [ "${UPSTREAM_PACKAGE_TYPE}" == "xz" ] ; then
tar xJf ${UPSTREAM_PACKAGE}
else
echo 2>&1 "ERROR: Bad archive format: ${UPSTREAM_PACKAGE}"
exit 1
fi
cp -r debian ${PACKAGE}-${UPSTREAM_VERSION}
find ${PACKAGE}-${UPSTREAM_VERSION} -name .svn | xargs --no-run-if-empty rm -rf
cd ${PACKAGE}-${UPSTREAM_VERSION}
if [ "${DISTRIBUTION}" != "default" ] ; then
if [ "${DISTRIBUTION}" == "unstable" -o "${DISTRIBUTION}" == "testing" -o "${DISTRIBUTION}" == "stable" -o "${DISTRIBUTION}" == "oldstable" ] ; then
# Fetch debian/changelog from Debian, if available.
# If there is a Debian changelog, merge new entries.
if ../fetch-debian-changelog ${PACKAGE} ${DISTRIBUTION} >debian/changelog.dist ; then
../merge-debian-changelogs debian/changelog debian/changelog.dist >debian/changelog.merged && \
mv debian/changelog.merged debian/changelog
fi
rm -f debian/changelog.dist
# Debian: Also remove Launchpad Bug IDs.
sed -e "s/${PACKAGE_DISTRIBUTION};/${DISTRIBUTION};/1" \
-e "s/\(ubuntu\|ppa\)[0-9]//1" \
-e "/(LP: #/D" \
<debian/changelog | ../filter-debian-changelog "${DEBIAN_LAST_ENTRY}" >debian/changelog.new
else
# Ubuntu PPA
# Naming example: 2.7.7-1ubuntu~focal1
# Ubuntu: Also remove Debian Bug IDs.
sed -e "s/${PACKAGE_DISTRIBUTION};/${DISTRIBUTION};/1" \
-e "s/${PACKAGE_VERSION}/${OUTPUT_VERSION}~${DISTRIBUTION}1/1" \
-e "/(Closes: #/D" \
<debian/changelog | ../filter-debian-changelog "${UBUNTU_LAST_ENTRY}" >debian/changelog.new
# ------ Old distributions not supporting c++/regex style symbols --
if [ "${DISTRIBUTION}" == "dapper" -o \
"${DISTRIBUTION}" == "edgy" -o \
"${DISTRIBUTION}" == "feisty" -o \
"${DISTRIBUTION}" == "hardy" -o \
"${DISTRIBUTION}" == "intrepid" -o \
"${DISTRIBUTION}" == "jaunty" -o \
"${DISTRIBUTION}" == "karmic" -o \
"${DISTRIBUTION}" == "lucid" ] ; then
# Just skip the symbols ...
find debian/ -maxdepth 1 -name "*.symbols" | xargs --no-run-if-empty rm -f
fi
fi
# Remove additional newlines at the end of the file:
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' debian/changelog.new
mv debian/changelog.new debian/changelog
# ------ Old distributions not supporting new Debian format -----------
if [ "${DISTRIBUTION}" == "dapper" -o \
"${DISTRIBUTION}" == "edgy" -o \
"${DISTRIBUTION}" == "feisty" -o \
"${DISTRIBUTION}" == "hardy" -o \
"${DISTRIBUTION}" == "intrepid" -o \
"${DISTRIBUTION}" == "jaunty" ] ; then
rm -rf debian/source
fi
# ------ Use latest Debhelper for Debian ------------------------------
if [ "${DISTRIBUTION}" == "unstable" -o "${DISTRIBUTION}" == "testing" -o "${DISTRIBUTION}" == "stable" -o "${DISTRIBUTION}" == "oldstable" ] ; then
# Update debhelper version:
# Also get rid of legacy cmake3 dependency alternative.
sed -e "s/debhelper (.* [0-9]*)/debhelper-compat (= ${DEBHELPER_LATEST_VERSION})/g" \
-e "s/ | cmake3//g" \
<debian/control >debian/control.new
# Newer debhelper does not need "--parallel" for building:
sed -e "s/\(.*dh .. .*--buildsystem=cmake.*\)\(--parallel\)\(.*\)/\1\3/g" -e 's@[[:space:]]*$@@g' \
<debian/rules >debian/rules.new
# There is no need for debian/compat any more:
rm -f debian/compat
mv debian/control.new debian/control
mv debian/rules.new debian/rules
updatedDebhelperVersion=1
fi
else
# Ubuntu: Remove Debian Bug IDs.
sed -e "/(Closes: #/D" \
<debian/changelog >debian/changelog.new
mv debian/changelog.new debian/changelog
sed -e "s/^Maintainer:/Maintainer: Ubuntu Developers <[email protected]>\nXSBC-Original-Maintainer:/g" <debian/control >debian/control.new
mv debian/control.new debian/control
fi
echo -e ""
echo -e "\x1b[34m------ Creating diff file ${PACKAGE}-${PACKAGE_VERSION}.diff.gz ------\x1b[0m"
(
cd ..
diff -urN "--exclude=*~" "--exclude=.svn" "--exclude=.git" \
${PACKAGE}-${UPSTREAM_VERSION}.orig ${PACKAGE}-${UPSTREAM_VERSION} \
| gzip -c >${PACKAGE}-${PACKAGE_VERSION}.diff.gz
)
echo -e ""
echo -e "\x1b[34m------ Building source package ------\x1b[0m"
# Without signature:
# debuild -us -uc
# For sources:
# debuild -S
# For binaries:
# debuild -b
# Use -i to ignore .svn files!
if [ "${SKIP_PACKAGE_SIGNING}" == "" ] ; then
SKIP_PACKAGE_SIGNING=0
fi
if [ $updatedDebhelperVersion -eq 0 ] ; then
opt=""
else
opt="--no-check-builddeps" # Needed for increased debhelper version!
fi
if [ ${SKIP_PACKAGE_SIGNING} -eq 1 -o "${OVERRIDE_SKIP_PACKAGE_SIGNING}" == "1" ] ; then
# Build source package without signature:
debuild ${opt} -us -uc -S -i || exit 1
else
# Build source package including signature:
if [ "${MAINTAINER_KEY}" == "" ] ; then
echo >&2 "ERROR: MAINTAINER_KEY is not set!"
exit 1
fi
debuild ${opt} -sa -S "-k${MAINTAINER_KEY}" -i || exit 1
fi
# Important: In /etc/pbuilderrc, set COMPONENTS="main universe"!
# Important: After that, update with option "--override-config"!
# sudo pbuilder update --override-config
cd ..
if [ "${DISTRIBUTION}" == "unstable" -o \
"${DISTRIBUTION}" == "testing" -o \
"${DISTRIBUTION}" == "stable" -o \
"${DISTRIBUTION}" == "oldstable" -o \
"${DISTRIBUTION}" == "default" ] ; then
if [ "${DISTRIBUTION}" == "default" ] ; then
version=${PACKAGE_VERSION}
else
version=${DEBIAN_VERSION}
fi
dscFile=`ls ${PACKAGE}_${version}.dsc | tail -n1`
else
dscFile=`ls ${PACKAGE}_${OUTPUT_VERSION}~${DISTRIBUTION}[0-9].dsc | tail -n1`
fi
if [ ! -e "${dscFile}" ] ; then
echo -e "\x1b[34mERROR: ${dscFile} has not been generated successfully -> Aborting!\x1b[0m"
exit 1
fi
done
# ====== Show results =======================================================
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Results overview ============================================\x1b[0m"
echo -e ""
echo -e "\x1b[34mUpload to PPA:\x1b[0m"
for DISTRIBUTION in ${DISTRIBUTIONS} ; do
if [ "${DISTRIBUTION}" == "unstable" -o \
"${DISTRIBUTION}" == "testing" -o \
"${DISTRIBUTION}" == "stable" -o \
"${DISTRIBUTION}" == "oldstable" -o \
"${DISTRIBUTION}" == "default" ] ; then
if [ "${DISTRIBUTION}" == "default" ] ; then
ppa="revu"
version=${PACKAGE_VERSION}
else
ppa="mentors"
version=${DEBIAN_VERSION}
fi
changesFile=`ls ${PACKAGE}_${version}_source.changes | tail -n1`
else
ppa="ppa"
changesFile=`ls ${PACKAGE}_${OUTPUT_VERSION}~${DISTRIBUTION}[0-9]_source.changes | tail -n1`
fi
echo -e "\x1b[34m dput ${ppa} $changesFile\x1b[0m"
done
echo -e ""
if [ -e make-symbols ] ; then
echo -e "\x1b[34m################################################################\x1b[0m"
echo -e "\x1b[34mDo not forget to run make-symbols after library version changes!\x1b[0m"
echo -e "\x1b[34m################################################################\x1b[0m"
echo -e ""
fi
echo -e "\x1b[34mBuild Test Commands:\x1b[0m"
for DISTRIBUTION in ${DISTRIBUTIONS} ; do
if [ "${DISTRIBUTION}" == "unstable" -o \
"${DISTRIBUTION}" == "testing" -o \
"${DISTRIBUTION}" == "stable" -o \
"${DISTRIBUTION}" == "oldstable" -o \
"${DISTRIBUTION}" == "default" ] ; then
if [ "${DISTRIBUTION}" == "default" ] ; then
version=${PACKAGE_VERSION}
else
version=${DEBIAN_VERSION}
fi
changesFilesPattern="${PACKAGE}_${version}_*.changes"
dscFile=`ls ${PACKAGE}_${version}.dsc | tail -n1`
else
changesFilesPattern="${PACKAGE}_${OUTPUT_VERSION}~${DISTRIBUTION}[0-9]_*.changes"
dscFile=`ls ${PACKAGE}_${OUTPUT_VERSION}~${DISTRIBUTION}[0-9].dsc | tail -n1`
fi
profile="ubuntu"
if [ "${DISTRIBUTION}" == "unstable" -o \
"${DISTRIBUTION}" == "testing" -o \
"${DISTRIBUTION}" == "stable" -o \
"${DISTRIBUTION}" == "oldstable" ] ; then
profile="debian"
fi
echo -e "\x1b[34m sudo pbuilder build ${dscFile} && lintian -iIEv --profile ${profile} --pedantic /var/cache/pbuilder/result/$changesFilesPattern\x1b[0m"
done
echo -e ""