forked from wrouesnel/wrouesnel-pbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pbuilderrc
247 lines (211 loc) · 8.25 KB
/
.pbuilderrc
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
# Will
# Rather more complicated support for sending build results to user home
# directory and signing with a default pbuilder key.
#
# debsign key is set in ~/.devscripts
# uses the detect-http-proxy script to set http proxy.
#
# 2008-08-13 tyler
# support building multiple distributions and architecture
# this is an ugly hack to try and let pbuilder know which user it should
# be working with. Basically we define check if an environment variable exists
# and if it does not, define it - this should catch the correct user.
if [ -z $pbuilder_user ]; then
pbuilder_user=$SUDO_USER
export pbuilder_user
fi
echo "PBuilder User: $pbuilder_user"
# determine if we're invoked by pbuilder
if [ -z $BASEPATH ]; then
IS_PBUILDER=1
fi
# Get the distribution names
: ${DIST:=$(lsb_release --short --codename)}
: ${ARCH:=$(dpkg --print-architecture)}
# Do any remapping for Linux Mint
export PBUILDERHOOKS=~/.pbuilder-hooks
. $PBUILDERHOOKS/common-name-remapping
# detect and set http_proxy using local script
APT_PROXY_CMD=$(cat /etc/apt/apt.conf /etc/apt/apt.conf.d/* 2> /dev/null |
grep -v -e ^# -e ^\/\/ -e ^$ |
grep Acquire::http::ProxyAutoDetect |
sed 's/Acquire::http::ProxyAutoDetect\ //' | sed '$s/;$//')
# did we get an apt proxy cmd?
if [ ! -z $APT_PROXY_CMD ]; then
echo "Trying to detect proxy using apt script..."
deb_proxy=$(bash -c $APT_PROXY_CMD)
else
# try and get just a regular proxy
deb_proxy=$(cat /etc/apt/apt.conf /etc/apt/apt.conf.d/* 2> /dev/null |
grep -v -e ^# -e ^\/\/ -e ^$ |
grep 'Acquire::http::ProxyAutoDetect ' |
sed 's/Acquire::http::Proxy\ //' | sed '$s/;$//' | tr -d '"' )
fi
if [ ! -z $deb_proxy ]; then
echo "pbuilder will use proxy: $deb_proxy"
else
echo "No proxy will be used."
fi
# Try and match names to mirror sites
shopt -s extglob
UBUNTUNAMES="@($(cat $PBUILDERHOOKS/ubuntu-names))"
OLDUBUNTUNAMES="@($(cat $PBUILDERHOOKS/oldubuntu-names))"
DEBIANNAMES="@($(cat $PBUILDERHOOKS/debian-names))"
case "$DIST" in
$UBUNTUNAMES) # ubuntu specific
MIRRORSITE="http://archive.ubuntu.com/ubuntu/"
COMPONENTS="main restricted universe multiverse"
;;
$OLDUBUNTUNAMES) # old ubuntu
MIRRORSITE="http://old-releases.ubuntu.com/ubuntu/"
COMPONENTS="main restricted universe multiverse"
;;
$DEBIANNAMES) # debian specific
MIRRORSITE="http://mirrors.kernel.org/debian/"
COMPONENTS="main contrib non-free"
;;
*) # Try and determine if there's a new release
echo "Unknown distribution: $DIST"
echo "Attempting to match new Ubuntu release:"
UBUNTULIST=$(wget -qO- "http://archive.ubuntu.com/ubuntu/dists/" | \
sed -n 's/.*href="\(.*\)\/".*/\1/p')
for UBUNTULISTITEM in $UBUNTULIST; do
if [[ "$UBUNTULISTITEM" == "$DIST" ]]; then
echo "New release found in Ubuntu archives!"
echo "Adding it to the known release list."
echo "$DIST|$(cat $PBUILDERHOOKS/ubuntu-names)" \
> $PBUILDERHOOKS/ubuntu-names
MIRRORSITE="http://archive.ubuntu.com/ubuntu/"
COMPONENTS="main restricted universe multiverse"
RESOLVEDUNKNOWN=1
break
fi
done
if [ -z $RESOLVEDUNKNOWN ]; then
echo "Couldn't find a mirror for the new specified release."
exit 1
fi
;;
esac
# If DIST evaluates to a suitable line in the local apt configuration, use that
# and take advantage of the likely primed cache if there's any proxy's in front
# of us.
#LOCAL_CONFIGURED_MIRROR=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2> /dev/null |
# grep -v -e ^# -e ^\/\/ -e ^$ |
# grep "^deb " |
# grep -e "$DIST $COMPONENTS" | sed s/deb\ // | cut -d' ' -f1)
#if [ ! -z $LOCAL_CONFIGURED_MIRROR ]; then
# echo "Found alternative mirrors."
# MIRRORSITE=$LOCAL_CONFIGURED_MIRROR
#fi
# Packages needed to support deb details
EXTRAPACKAGES="apt-utils lsb-release"
# configure dist specific packages
case "$DIST" in
$UBUNTUNAMES|$OLDUBUNTUNAMES) # ubuntu specific
if [ "$DIST" \> "lucid" ]; then
echo "enabling eatmydata for > lucid release"
EXTRAPACKAGES="$EXTRAPACKAGES eatmydata"
fi
;;
esac
# Add local keyrings. Due to changes, we actually need to create and manage
# a combined trusted keyring to keep everything working.
PBUILDERREPO=$HOME/pbuilder-repo
echo "Merging host keyrings into $PBUILDERREPO/host-trusted.gpg"
echo $PBUILDERREPO
if [ -e $PBUILDERREPO/host-trusted.gpg ]; then
mv -f $PBUILDERREPO/host-trusted.gpg $PBUILDERREPO/host-trusted.gpg.bak
fi
gpg --no-options --no-default-keyring --export -a --keyring /etc/apt/trusted.gpg | \
gpg --no-options --no-default-keyring --keyring $PBUILDERREPO/host-trusted.gpg --import -a || true
find /etc/apt/trusted.gpg.d/ -type f -name '*.gpg' -print | while read f; do
gpg --no-options --no-default-keyring --export -a --keyring $f | \
gpg --no-options --no-default-keyring --keyring $PBUILDERREPO/host-trusted.gpg --import -a || true
done
DEBOOTSTRAPOPTS="--keyring=$PBUILDERREPO/host-trusted.gpg"
# sign packages - if I'm building them they're trusted by me at least
AUTO_DEBSIGN="yes"
NAME="$DIST-$ARCH"
DISTRIBUTION="$DIST"
DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")
BUILDRESULT="/var/cache/pbuilder/$NAME/result"
DEBBUILDOPTS="-j4 "
# Regular pbuilder support
BASETGZ="$(dirname $BASETGZ)/$NAME-base.tgz"
# QemuBuilder/CowDancer
BASEPATH="(dirname $BASEPATH)/$NAME-base.qemu"
# TODO: replace with something that automatically acquires the right kernel
KERNEL="/vmlinuz"
INITRD="/initrd.img"
ARCHITECTURE="$ARCH"
# Disable apt-cache since we use apt-cacher-ng
APTCACHE=""
# Don't rebuild source files (.diff.gz, .dsc), or list them in .changes
# See Ubuntu bug 118181
#DEBBUILDOPTS=""
# Dump out some information about what's going on here
echo "Environment name: $NAME"
echo "Distribution is: $DIST"
echo "DEBOOTSTRAPOPTS is: ${DEBOOTSTRAPOPTS[@]}"
# Adjust output according to pbuilder/qemubuilder
if [ -z $IS_PBUILDER ]; then
echo "Environment will be stored in: $BASEPATH"
else
echo "Environment will be stored in: $BASETGZ"
fi
# Local pbuilder result repository
PBUILDER_REPO=$(eval echo ~${pbuilder_user})/pbuilder-repo
echo "Local pbuilder repository: $PBUILDER_REPO"
BINDMOUNTS="$PBUILDER_REPO $BUILDRESULT $PBUILDERHOOKS"
OTHERMIRROR="deb file:$PBUILDER_REPO/$NAME ./"
HOOKDIR="$PBUILDERHOOKS"
# Setup the build destination
if [ ! -d $BUILDRESULT ] ; then
mkdir -p $BUILDRESULT
# set permissions so I can delete files
chgrp $pbuilder_user $BUILDRESULT
chmod g+rwx $BUILDRESULT
fi
# Setup the local build repository
if [ ! -d $PBUILDER_REPO/$NAME ] ; then
mkdir -p $PBUILDER_REPO/$NAME
# set permissions so I can delete files
chgrp $pbuilder_user $PBUILDER_REPO/$NAME
chmod g+rwxs $PBUILDER_REPO/$NAME
fi
if [ ! -e $PBUILDER_REPO/$NAME/apt-ftparchive.conf ]; then
cat << EOF > $PBUILDER_REPO/$NAME/apt-ftparchive.conf
# Configuration file for the pbuilder flat-file archive.
APT::FTPArchive::Release::Codename "$DIST";
APT::FTPArchive::Release::Origin "pbuilder";
APT::FTPArchive::Release::Components "main";
APT::FTPArchive::Release::Label "pbuilder";
APT::FTPArchive::Release::Architectures "$ARCH source";
APT::FTPArchive::Release::Description "Automatic Repository for pbuilder.";
EOF
fi
# PBuilder create will fail if apt errors out trying to download a non-existent
# packages file. It should always exist, so create it here if it doesn't.
if [ ! -e $PBUILDER_REPO/$NAME/Packages ]; then
touch $PBUILDER_REPO/$NAME/Packages
fi
# Make sure the chroot knows where files for the local repo will go.
if [ -e $BUILDRESULT/.local_repository_location ] ; then
rm $BUILDRESULT/.local_repository_location
fi
touch $BUILDRESULT/.local_repository_location
cat << EOF > $BUILDRESULT/.local_repository_location
$PBUILDER_REPO
EOF
# enable eatmydata to speed up pbuilder
if [[ $EXTRAPACKAGES = *eatmydata* ]]; then
if [ -z "$LD_PRELOAD" ]; then
LD_PRELOAD=/usr/lib/libeatmydata/libeatmydata.so
else
LD_PRELOAD="$LD_PRELOAD":/usr/lib/libeatmydata/libeatmydata.so
fi
fi
export LD_PRELOAD
# Set the detected Deb proxy to the http proxy
export http_proxy=$deb_proxy