]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/schroot/files/setup-dchroot
setup-dchroot: use linux32 personality on mips/mipsel
[dsa-puppet.git] / modules / schroot / files / setup-dchroot
1 #!/bin/bash
2
3 ##
4 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
5 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
6 ##
7
8 # Copyright (c) 2013 Peter Palfrader
9 #
10 # Permission is hereby granted, free of charge, to any person
11 # obtaining a copy of this software and associated documentation
12 # files (the "Software"), to deal in the Software without
13 # restriction, including without limitation the rights to use,
14 # copy, modify, merge, publish, distribute, sublicense, and/or sell
15 # copies of the Software, and to permit persons to whom the
16 # Software is furnished to do so, subject to the following
17 # conditions:
18 #
19 # The above copyright notice and this permission notice shall be
20 # included in all copies or substantial portions of the Software.
21 #
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 # OTHER DEALINGS IN THE SOFTWARE.
30
31 THISARCH=$(dpkg --print-architecture)
32
33 usage()
34 {
35 cat << EOF
36 usage: $0 <suite>
37
38 OPTIONS:
39     -a ARCH    debootstrap arch [$arch]
40     -m MIRROR  http mirror to use [$mirror]
41     -b basedir place where to put the tarball [$basedir]
42     -B         install less stuff into chroot [$bare]
43     -c         write config only
44     -D         set up a buildd schroot - changes conffile name and
45                various defaults.  Run -D -h.  Also creates more aliases.
46     -d dir     place where to build the chroot [${builddir:-$basedir}]
47     -f         overwrite config and target tarball
48     -g GROUPS  groups that should have access to the schroot [$groupuser]
49     -K         keep old tarballs around for a while (4 iterations)
50     -k KEYRING use an alternate keyring [$keyring]
51     -o USER    users that should have access to the schroot [$users]
52     -O USER    users that should have root in the schroot [$usersroot]
53     -p PERS    use a different sbuild personality [$personality]
54     -r GROUPS  groups that should have root in the schroot [$grouproot]
55     -s         use sbuild compatible naming scheme [$sbuildnames]
56     -S SUFFIX  conffile suffix [$suffix]
57     -u         Ubuntu target
58     -h         this help
59 EOF
60 }
61
62 die() {
63     echo >&2 "$*"
64     exit 1
65 }
66
67 do_cleanup() {
68     local cnt
69     cnt=$((${#cleanup[*]}-1))
70     for i in $(seq ${cnt} -1 0); do
71         ${cleanup[$i]} || true
72     done
73 }
74
75 genschrootconf() {
76     local suite="$1"; shift
77     local arch="$1"; shift
78     local target="$1"; shift
79     local extra="${1:-}"; shift || true
80
81     if [ -n "$extra" ]; then
82         local suite="${suite}-${extra}"
83     fi
84
85     if [ -n "$sbuildnames" ]; then
86         local name="${suite}-${arch}-sbuild"
87     else
88         local name="${suite}_${arch}-dchroot"
89     fi
90
91
92 cat << EOF
93 [${name}]
94 description=[${name}] Debian $suite chroot for $arch
95 type=file
96 file=$target
97 EOF
98 [ -n "$groupuser" ] && echo "groups=$groupuser"
99 [ -n "$grouproot" ] && echo "root-groups=$grouproot"
100 [ -n "$users" ] &&     echo "users=$users"
101 [ -n "$usersroot" ] && echo "root-users=$usersroot"
102
103     echo "profile=$personality"
104
105     if [ "$THISARCH" = "$arch" ] && [ -z "$buildd" ]; then
106         echo "aliases=$suite"
107     fi
108     case "$arch" in
109         armel|armhf|i386|mips|mipsel|powerpc|s390|sparc)
110             echo "personality=linux32"
111             ;;
112     esac
113     echo
114
115     case "$suite" in
116         sid)
117             genschrootconf "experimental" "$arch" "$target"
118             ;;
119         experimental)
120             :
121             ;;
122         *)
123             if [ -z "$extra" ] && [ -z "$ubuntu" ]; then
124                 genschrootconf "$suite" "$arch" "$target" "backports"
125                 [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "backports-sloppy"
126                 [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "kfreebsd"
127                 [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "lts"
128                 [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "proposed-updates"
129                 [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "security"
130             fi
131     esac
132     return 0
133 }
134
135 do_config() {
136     local tmpschrootconf=$(tempfile)
137     cleanup+=("rm -f $tmpschrootconf")
138     genschrootconf "$suite" "$arch" "$target" > "$tmpschrootconf"
139     if ! [ -e "$schrootconfig" ] || ! diff "$schrootconfig" "$tmpschrootconf" > /dev/null; then
140         mv "$tmpschrootconf" "$schrootconfig"
141         chmod 644 "$schrootconfig"
142     fi
143 }
144
145
146 set -e
147 set -u
148
149 arch="$THISARCH"
150 if [ -e /etc/schroot/dsa/default-mirror ]; then
151     mirror=$(cat /etc/schroot/dsa/default-mirror )
152 fi
153 mirror="${mirror:-http://ftp.debian.org/debian}"
154 configonly=""
155 force=""
156 basedir="/srv/chroot"
157 builddir=""
158 keyring=/usr/share/keyrings/debian-archive-keyring.gpg
159 personality="dsa"
160 sbuildnames=""
161 ubuntu=""
162 groupuser="Debian,guest,d-i"
163 grouproot=""
164 include="apt,fakeroot"
165 users=""
166 usersroot=""
167 bare=""
168 keep=""
169 suffix="dchroot"
170 declare -a cleanup
171 cleanup+=(":")
172 trap do_cleanup EXIT
173 buildd=""
174
175 while getopts "a:b:Bcd:Dfg:hI:Kk:m:o:O:p:r:sS:u" OPTION
176 do
177     case $OPTION in
178         a)
179             arch="$OPTARG"
180             ;;
181         b)
182             basedir="$OPTARG"
183             ;;
184         B)
185             bare="1"
186             ;;
187         c)
188             configonly="1"
189             ;;
190         D)
191             buildd="1"
192             sbuildnames="0"
193             bare="1"
194             groupuser=""
195             grouproot=""
196             users="buildd,buildd2"
197             usersroot="buildd,buildd2"
198             personality="buildd"
199             suffix="sbuild"
200             ;;
201         d)
202             builddir="$OPTARG"
203             ;;
204         f)
205             force="1"
206             ;;
207         g)
208             groupuser="$OPTARG"
209             ;;
210         h)
211             usage
212             exit 0
213             ;;
214         I)
215             include="$include,$OPTARG"
216             ;;
217         K)
218             keep="4"
219             ;;
220         k)
221             keyring="$OPTARG"
222             ;;
223         m)
224             mirror="$OPTARG"
225             ;;
226         o)
227             users="$OPTARG"
228             ;;
229         O)
230             usersroot="$OPTARG"
231             ;;
232         p)
233             personality="$OPTARG"
234             ;;
235         r)
236             grouproot="$OPTARG"
237             ;;
238         s)
239             sbuildnames="1"
240             ;;
241         S)
242             suffix="$OPTARG"
243             ;;
244         u)
245             ubuntu="1"
246             ;;
247         *)
248             usage >&2
249             exit 1
250             ;;
251     esac
252 done
253 shift $(($OPTIND - 1))
254
255 if [ "$#" != 1 ]; then
256     usage >&2
257     exit 1
258 fi
259 suite="$1"; shift
260 tuple="${suite}_${arch}"
261
262 if [ -z "${builddir:-}" ]; then
263   builddir=${builddir:-$basedir}
264   for u in schroot-unpack unpack; do
265     # if one of these directories exists and is on a different filesystem, prefer it.
266     candidate="$builddir/$u"
267     if [ -e "$candidate" ] &&
268        [ "$(stat -f --printf '%i\n' "$builddir" )" != "$(stat -f --printf '%i\n' "$candidate")" ]; then
269       builddir="$candidate"
270     fi
271   done
272 fi
273 [ -d "$basedir" ] || die "Error: $basedir does not exist (or is not a directory)."
274 [ -d "$builddir" ] || die "Error: $builddir does not exist (or is not a directory)."
275
276 target="$basedir/$tuple.tar.gz"
277 ! [ -e "$target" ] || [ -n "$force" ] || die "Error: $target already exists."
278
279 schrootconfig="/etc/schroot/chroot.d/${tuple}-$suffix"
280 ! [ -e "$schrootconfig" ] || [ -n "$force" ] || die "Error: $schrootconfig already exists."
281
282 suite_alias="$suite"
283 case "$arch" in
284     kfreebsd-*)
285         case "$suite" in
286             jessie)
287                 suite_alias="$suite-kfreebsd"
288                 ;;
289         esac
290         ;;
291 esac
292
293
294 #
295 # let's go
296 #
297
298 if [ -n "$configonly" ]; then
299     do_config
300     exit 0
301 fi
302
303 rootdir=$(mktemp -d "$builddir/create-$suite-XXXXXX")
304 cleanup+=("rm -r $rootdir")
305 cleanup+=("umount $rootdir/sys")
306 script=/usr/share/debootstrap/scripts/"$suite"
307 if ! [ -e "$script" ]; then
308     if [ -z "$ubuntu" ]; then
309         script=/usr/share/debootstrap/scripts/sid
310     else
311         script=/usr/share/debootstrap/scripts/gutsy
312     fi
313 fi
314
315 set -x
316 debootstrap \
317     --keyring "$keyring" \
318     --include="$include" \
319     --variant=buildd \
320     --arch="$arch" \
321     "$suite_alias" "$rootdir" "$mirror" "$script"
322 echo "$tuple" > "$rootdir/etc/debian_chroot"
323 echo "force-unsafe-io" > "$rootdir/etc/dpkg/dpkg.cfg.d/force-unsafe-io"
324 echo "force-confnew" > "$rootdir/etc/dpkg/dpkg.cfg.d/force-confnew"
325
326 cleanup+=("umount $rootdir/dev")
327 case "$(uname -s)" in
328   Linux)
329     ;;
330   GNU/kFreeBSD)
331     mount -t devfs none "$rootdir/dev"
332     ;;
333   *)
334     echo >&2 "Warning: Unexpected uname -s output."
335     ;;
336 esac
337
338
339 chroot "$rootdir" apt-get update
340 chroot "$rootdir" apt-get install -y --no-install-recommends policyrcd-script-zg2
341 cat > "$rootdir/usr/local/sbin/policy-rc.d" << 'EOF'
342 #!/bin/sh
343
344 # policy-rc.d script for chroots.
345 # Copyright (c) 2007 Peter Palfrader <peter@palfrader.org>
346
347 while true; do
348     case "$1" in
349         -*)      shift ;;
350         makedev) exit 0;;
351         *)
352             echo "Not running services in chroot."
353             exit 101
354             ;;
355     esac
356 done
357 EOF
358 chmod +x "$rootdir/usr/local/sbin/policy-rc.d"
359 [ -z "$bare" ] && [ -z "$ubuntu" ] && chroot "$rootdir" apt-get install -y --no-install-recommends locales-all
360 chroot "$rootdir" apt-get install -y --no-install-recommends build-essential
361 [ -z "$bare" ] && chroot "$rootdir" apt-get install -y --no-install-recommends zsh less vim fakeroot devscripts gdb
362 rm -f "$rootdir/etc/apt/sources.list" "$rootdir/etc/apt/sources.list.d/*"
363 chroot "$rootdir" apt-get clean
364 umount "$rootdir/dev" 2>/dev/null || true
365 umount "$rootdir/sys" 2>/dev/null || true
366
367 tartmp=$(tempfile --directory "$basedir" --suffix=".tar.gz")
368 cleanup+=("rm -f $tartmp")
369 (
370   cd "$rootdir"
371   tar caf "$tartmp" .
372   if ! [ -z "$keep" ]; then
373     savelog -l -c 4 "$target"
374   fi
375   mv "$tartmp" "$target"
376 )
377
378 do_config