-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebutil-build
276 lines (213 loc) · 6.37 KB
/
debutil-build
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
#!/bin/sh
# -*- sh -*-
#
# This script intends to simplify building debian packages from source
# repository by wrapping the commonly used upstream packaging system
# and debian build steps in a few simple options.
#
# This script relies on a working, clean and complete usptream
# packaging and the presence of a debian folder inside the source tree.
# That constraint may be lifted later.
# It also relies on a working sbuild setup that should be taken care of
# with a yet to be written script in order to not bloat this one.
set -e
# PKG INFORMATION
get_version() {
sed -n -r 's/Version: //p' "${1}"
}
get_epoch() {
get_version "${1}" | sed -r -n 's/([0-9]+):(.*)-(.*)$/\1/p'
}
get_upstream_version() {
get_version "${1}" | sed -r -n 's/([0-9]+:)?(.*)-(.*)$/\2/p'
}
get_revision() {
get_version "${1}" | sed -r -n 's/([0-9]+:)?(.*)-(.*)$/\3/p'
}
get_source_name() {
sed -n -r 's/Source: //p' "${1}"
}
get_package_name() {
sed -n -r 's/Package: //p' "${1}"
}
# FILE FUNCTIONS
get_orig_file() {
local src_tar dsc_file
dsc_file="${SOURCE_PKG}_${OLD_VERSION}.dsc"
src_tar="$(find . -type f -name "${SOURCE_PKG}-${UVERSION}.tar.*")"
# If dsc exists, use it to find origin tarball
if [ -f "${dsc_file}" ]; then
src_tar="$(sed -r -n "/.orig.tar/ { s/.* //p; q }" "${dsc_file}")"
fi
# If everything else failed, try to find find a .orig.tar.* file
if [ -z "${src_tar}" ]; then
src_tar="$(find . -type f -name "${SOURCE_PKG}_${UVERSION}.orig.tar.*")"
fi
echo "${src_tar}"
}
# MISC HELPERS
has() {
local needle=$1
shift
local x
for x in "$@"; do
[ "${x}" = "${needle}" ] && return 0
done
return 1
}
# BUILD STUFF
clean() {
local binpkg
set +e
rm -r "${SOURCE_PKG}-${UVERSION}"/
if [ -z "${REVISION}" ]; then
rm "${SOURCE_PKG}_${UVERSION}".tar.*
else
rm "${SOURCE_PKG}_${UVERSION}".orig.tar.*
rm "${SOURCE_PKG}_${VERSION}".debian.tar.gz
fi
for binpkg in ${BINARY_PKG} ; do
rm "${binpkg}_${VERSION}_"*.deb
done
for fileext in diff.gz changes dsc build ; do
rm "${SOURCE_PKG}_${VERSION}"*.${fileext}
done
set -e
}
dist_uscan() {
[ ! -e debian/watch ] && return 1
uscan --report-status || true
local upstream_url
upstream_url="$(uscan --force-download --download-current-version \
--destdir=. --dehs | xmllint --xpath 'string(/dehs/upstream-url)' -)"
if echo "${upstream_url}" | grep -q "\.zip$"; then
rm -rf "$(echo "${upstream_url}" | sed -r 's|.*/([^/]+\.zip)|\1|')"
uscan --force-download --download-current-version --destdir=. --repack
fi
}
dist_autotools() {
[ ! -e configure.ac -a ! -e configure.in ] && return 1
[ ! -e configure ] && autoreconf -vif
./configure
make dist
}
dist_setuppy() {
[ ! -e ./setup.py ] && return 1
python -B ./setup.py sdist --dist-dir=.
if [ ! -e "${SOURCE_PKG}-${UVERSION}.tar.gz" ]; then
# Rename -dev to ~dev, setuptools does not like ~
mv "$(echo "${SOURCE_PKG}-${UVERSION}".tar.gz | sed 's/~/-/')" \
"${SOURCE_PKG}-${UVERSION}.tar.gz"
fi
}
dist_get_orig_source() {
grep -q 'get-orig-source' debian/rules || return 1
./debian/rules get-orig-source
mv ${SOURCE_PKG}_${UVERSION}.orig.tar.gz ${SOURCE_PKG}-${UVERSION}.tar.gz
}
dist() {
# If this is a new debian revision, download .orig tarball
if [ -z "${UGLY}" -a "${EPOCH}${UVERSION}" = "${OLD_EPOCH}${OLD_UVERSION}" ]; then
apt-get source --download-only ${PKG_NAME}=${OLD_VERSION}
: && return 0
fi
local method
for method in setuppy uscan autotools get_orig_source ; do
dist_$method && break
done
mv "${SOURCE_PKG}-${UVERSION}.tar.gz" "${SOURCE_PKG}_${UVERSION}.orig.tar.gz"
}
pre_build() {
local src_dir orig_file
src_dir="${SOURCE_PKG}-${UVERSION}"
orig_file="$(get_orig_file)"
mkdir "${src_dir}"
tar -C "${src_dir}" \
--strip-components=1 \
-xf "${orig_file}"
rsync --archive --cvs-exclude --delete debian/ "${src_dir}"/debian/
dpkg-source -b "${src_dir}"
rm -r "${src_dir}"
}
build() {
local arch_build arch_list dsc_file sbuild_chroot schroot_list sbuild_opts
dsc_file="${SOURCE_PKG}_${VERSION}.dsc"
schroot_list="$(schroot -l)"
# Extract target architectures
arch_list="$(sed -r -n 's/Architecture: //p' "${dsc_file}" | sort | uniq)"
# Translate any to supported architectures
if has "any" "${arch_list}"; then
arch_list="$(echo "${arch_list} $(dpkg-architecture -L)" | \
tr -s ' ' '\n' | sed '/any/d' | sort | uniq)"
fi
# Build packages
# XXX: maybe it is not useful to check chroot existance at all
for arch_build in "${arch_list}"; do
sbuild_opts="--nolog --source --dist ${RELEASE}"
if [ "${arch_build}" = "all" ]; then
sbuild_opts="${sbuild_opts} --arch-all --debbuildopt=-A"
sbuild_chroot="${RELEASE}-$(dpkg --print-architecture)-sbuild"
else
sbuild_opts="${sbuild_opts} --arch ${arch_build}"
sbuild_chroot="${RELEASE}-${arch_build}-sbuild"
fi
if has "chroot:${sbuild_chroot}" ${schroot_list}; then
sbuild ${sbuild_opts} --chroot "${sbuild_chroot}" "${dsc_file}"
fi
done
# Handle .changes
:
}
post_build() {
# RUN LINTIAN AND OTHER POST BUILD STEPS
:
}
# SETUP GLOBAL VARIABLES
setup() {
# Extract all needed information from debian packaging
local changelog_n changelog_n_1
changelog_n="$(mktemp)"
changelog_n_1="$(mktemp)"
dpkg-parsechangelog --count 1 -o0 > "${changelog_n}"
dpkg-parsechangelog --count 1 -o1 > "${changelog_n_1}"
VERSION="$(get_version ${changelog_n})"
OLD_VERSION="$(get_version ${changelog_n_1})"
UVERSION="$(get_upstream_version ${changelog_n})"
OLD_UVERSION="$(get_upstream_version ${changelog_n_1})"
EPOCH="$(get_epoch ${changelog_n})"
OLD_EPOCH="$(get_epoch ${changelog_n_1})"
REVISION="$(get_revision ${changelog_n})"
OLD_REVISION="$(get_revision ${changelog_n})"
SOURCE_PKG="$(get_source_name ${changelog_n})"
BINARY_PKG="$(get_package_name debian/control)"
if [ -z "${RELEASE}" ]; then
RELEASE="$(sed -r -n 's/Distribution: //p' "${changelog_n}")"
fi
rm "${changelog_n}" "${changelog_n_1}"
}
# MAIN
usage() {
cat <<EOF
Usage: $(basename $0) [OPTIONS]
Options:
-a, --arch Target architecture to build for
-h, --help Shows this help message
-r, --release Distribution release to target build for
EOF
}
set -- `getopt -u -o a:hr:u --long arch:,help,release:,ugly -n "$0" -- "$@"`
while true ; do
case "$1" in
-a|--arch) shift; ARCH=$1; shift ;;
-r|--release) shift; RELEASE=$1 ; shift ;;
-u|--ugly) shift; UGLY="true" ;;
--) shift ; break ;;
*) usage ; exit 1 ;;
esac
done
setup
clean
dist
pre_build
build
post_build