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
|
#! /bin/bash
# common modules for pbuilder.
# pbuilder -- personal Debian package builder
# Copyright (C) 2001-2003 Junichi Uekawa
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function showhelp () {
cat <<EOF
pbuilder - a personal builder
Copyright 2001-2003 Junichi Uekawa
Distributed under GNU Public License version 2 or later
pbuilder [operation] [pbuilder-options]
pdebuild [pbuilder-options]
command lines:
pbuilder create [--basetgz base.tgz-path] [--distribution woody|sid]
Creates a base.tgz
pbuilder update [--basetgz base.tgz-path] [--distribution woody|sid]
Updates a base.tgz
pbuilder build [--basetgz base.tgz-path] pbuilder_2.2.0-1.dsc
Builds using the base.tgz. Requires a .dsc filename
pbuilder clean
Cleans the temporal build directory.
pbuilder login
pbuilder execute [command]
Logs in to the build environment and execute command.
pbuilder-options:
--basetgz [base.tgz location]
--buildplace [location of build]
--mirror [mirror location]
--nonusmirror [non-US mirror location]
--othermirror [other mirror location in apt deb-line format, delimited with | signs]
--http-proxy [proxy]
--distribution [distribution(potato/woody/sid)]
--buildresult [location-to-copy-build-result]
--removepackages [packages-to-remove on pbuilder create]
--extrapackages [packages-to-add on pbuilder create]
--configfile [configuration file to load]
--hookdir [hook directory]
--debemail [mail address]
--debbuildopts [dpkg-buildpackage options]
--logfile [filename to output log]
--pkgname-logfile
--aptconfdir [overriding apt config dir]
--timeout [timeout time]
--override-config
--binary-arch
--preserve-buildplace
pdebuild-specific pbuilder-options
--pbuilderroot [command to obtain root privilege for pbuilder]
--buildsourceroot [command to obtain root privilege for dpkg-buildpackage]
EOF
exit 1
}
function umount_one () {
echo " -> unmounting $1 filesystem"
if ! umount "$BUILDPLACE/$1"; then
echo "W: Retrying to unmount $1"
sleep 5s
while ! umount "$BUILDPLACE/$1"; do
sleep 5s
cat <<EOF
Could not unmount $1, there might be some program
still using files in /proc (klogd?).
Please check and kill it so that I can unmount $1
EOF
chroot "$BUILDPLACE" bin/sh
done
fi
}
function umountproc () {
if [ "$USEPROC" = "yes" ]; then
umount_one "proc"
fi
if [ "$USEDEVPTS" = "yes" ]; then
umount_one "dev/pts"
fi
if [ "$USEDEVFS" = "yes" ]; then
umount_one "dev"
fi
}
function mountproc () {
if [ "$USEPROC" = "yes" ]; then
echo " -> mounting /proc filesystem"
mkdir -p $BUILDPLACE/proc
mount -t proc /proc "$BUILDPLACE/proc"
fi
if [ "$USEDEVPTS" = "yes" ]; then
echo " -> mounting /dev/pts filesystem"
mkdir -p $BUILDPLACE/dev/pts || true
mount -t devpts /dev/pts "$BUILDPLACE/dev/pts"
fi
if [ "$USEDEVFS" = "yes" ]; then
echo " -> mounting /dev filesystem"
mkdir -p $BUILDPLACE/dev || true
mount -t devfs /dev "$BUILDPLACE/dev"
fi
}
function cleanbuildplace () {
if [ "$?" -ne 0 ]; then
echo " -> Aborting with an error";
fi
if [ "${INTERNAL_BUILD_UML}" != "yes" -a ! \( "${PRESERVE_BUILDPLACE}" = "yes" -a -d "$BUILDPLACE" \) ]; then
if [ -d "$BUILDPLACE" ]; then
echo " -> cleaning the build env "
rm -rf "$BUILDPLACE"
fi;
fi
}
function umountproc_cleanbuildplace () {
# rolling back to abort.
if [ "$?" -ne 0 ]; then
echo " -> Aborting with an error";
fi
umountproc
cleanbuildplace
}
function installaptlines (){
echo " -> Installing apt-lines"
rm -f "$BUILDPLACE"/etc/apt/sources.list
if [ -z "$DISTRIBUTION" ]; then
echo "Distribution not specified, please specify" >&2
exit 1
fi
if [ -n "$OTHERMIRROR" ]; then
echo "$OTHERMIRROR" | tr "|" "\n" >> "$BUILDPLACE"/etc/apt/sources.list
fi
if [ -n "$MIRRORSITE" ] ; then
cat >> "$BUILDPLACE"/etc/apt/sources.list << EOF
deb $MIRRORSITE $DISTRIBUTION main contrib non-free
#deb-src $MIRRORSITE $DISTRIBUTION main contrib non-free
EOF
fi
if [ -n "$NONUSMIRRORSITE" ]; then
cat >> "$BUILDPLACE"/etc/apt/sources.list << EOF
deb $NONUSMIRRORSITE $DISTRIBUTION/non-US main contrib non-free
#deb-src $NONUSMIRRORSITE $DISTRIBUTION/non-US main contrib non-free
EOF
fi
if [ -n "$APTCONFDIR" ]; then
echo " -> Copy " "$APTCONFDIR"/* " to chroot"
cp -a "$APTCONFDIR/"* "$BUILDPLACE"/etc/apt
fi
}
function copy_local_configuration () {
echo " -> copying local configuration"
for a in hosts hostname resolv.conf; do
rm -f "$BUILDPLACE/etc/$a"
cp $( readlink -f "/etc/$a" ) "$BUILDPLACE/etc/$a";
done
}
function extractbuildplace () {
# after calling this function, umountproc, and cleanbuildplace
# needs to be called. Please trap it.
if [ ! "${INTERNAL_BUILD_UML}" = "yes" ]; then
cleanbuildplace
echo "Building the build Environment"
if ! mkdir -p "$BUILDPLACE"; then
echo "E: failed to build the directory to chroot"
exit 1
fi
echo " -> extracting base tarball [${BASETGZ}]"
if [ ! -f "$BASETGZ" ]; then
echo "E: failed to find $BASETGZ, have you done <pbuilder create> to create your base tarball yet?"
exit 1
fi
if ! (cd "$BUILDPLACE" && tar xfzp "$BASETGZ"); then
echo "E: failed to extract $BASETGZ to $BUILDPLACE"
exit 1
fi
echo " -> creating local configuration"
hostname -f > "$BUILDPLACE/etc/mailname"
fi
copy_local_configuration
mountproc
mkdir -p "$BUILDPLACE/tmp/buildd"
if [ "$OVERRIDE_APTLINES" = "yes" ]; then
installaptlines
fi
}
function recover_aptcache() {
local doit
# recover the aptcache archive
if [ -n "$APTCACHE" ]; then
if [ "$APTCACHEHARDLINK" = "yes" ]; then
doit=ln
else
doit=cp
fi
echo "Obtaining the cached apt archive contents"
find "$APTCACHE" -name \*.deb -maxdepth 1 | \
while read A ; do
$doit "$A" "$BUILDPLACE/var/cache/apt/archives/" || true
done
fi
}
function save_aptcache() {
# save the current aptcache archive
local doit
if [ -n "$APTCACHE" ]; then
echo "Copying back the cached apt archive contents"
mkdir -p "$APTCACHE" ;
if [ "$APTCACHEHARDLINK" = "yes" ]; then
doit=ln
else
doit=cp
fi
find "$BUILDPLACE/var/cache/apt/archives/" -name \*.deb -maxdepth 1 | \
while read A ;do
if [ ! -f "$APTCACHE/"$(basename "$A") -a -f "$A" ]; then
echo " -> new cache content "$(basename "$A")" added"
$doit "$A" "$APTCACHE/" || true
fi
done
fi
}
function create_basetgz() {
# create base.tgz
(
if ! cd "$BUILDPLACE"; then
echo "Error: unexpected error in chdir to $BUILDPLACE" >&2
exit 1;
fi
while test -f "${BASETGZ}.tmp"; do
echo " -> Someone else has lock over ${BASETGZ}.tmp, waiting"
sleep 10s
done
echo " -> creating base tarball [${BASETGZ}]"
if ! tar cfz "${BASETGZ}.tmp" * ; then
echo " -> failed building base tarball"
rm -f "${BASETGZ}.tmp"
exit 1;
fi
mv "${BASETGZ}.tmp" "${BASETGZ}"
)
}
#required for some packages to install...
export LANG=C
export LC_ALL=C
|