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
8 # Copyright (c) 2013 Peter Palfrader
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
19 # The above copyright notice and this permission notice shall be
20 # included in all copies or substantial portions of the Software.
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.
31 THISARCH=$(dpkg --print-architecture)
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]
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]
69 cnt=$((${#cleanup[*]}-1))
70 for i in $(seq ${cnt} -1 0); do
71 ${cleanup[$i]} || true
76 local suite="$1"; shift
77 local arch="$1"; shift
79 if [ -n "$sbuildnames" ]; then
80 local name="${suite}-${arch}-sbuild"
82 local name="${suite}_${arch}-dchroot"
90 local suite="$1"; shift
91 local arch="$1"; shift
92 local target="$1"; shift
93 local extra="${1:-}"; shift || true
96 if [ -n "$extra" ]; then
97 local suite="${suite}-${extra}"
100 local name="$(genname "$suite" "$arch")"
102 local fullname="$name"
106 # FreeBSD only allows relatively short paths to mountpoints
107 # therefore saving a few charakters making the chroot dir fit
108 name=${name/kfreebsd-amd64/k-a}
109 name=${name/kfreebsd-i386/k-i}
115 description=[${fullname}] Debian $suite chroot for $arch
119 [ -n "$groupuser" ] && echo "groups=$groupuser"
120 [ -n "$grouproot" ] && echo "root-groups=$grouproot"
121 [ -n "$users" ] && echo "users=$users"
122 [ -n "$usersroot" ] && echo "root-users=$usersroot"
124 echo "profile=$personality"
126 if [ "$THISARCH" = "$arch" ] && [ -z "$buildd" ]; then
127 if [ -z "$aliases" ] ; then
130 aliases="$aliases,$suite"
133 if [ -n "$aliases" ] ; then
134 echo "aliases=$aliases"
137 armel|armhf|i386|mips|mipsel|powerpc|s390|sparc)
138 echo "personality=linux32"
145 genschrootconf "experimental" "$arch" "$target"
151 if [ -z "$extra" ] && [ -z "$ubuntu" ]; then
152 genschrootconf "$suite" "$arch" "$target" "backports"
153 if [ -n "$buildd" ] ; then
154 genschrootconf "$suite" "$arch" "$target" "backports-sloppy"
155 genschrootconf "$suite" "$arch" "$target" "proposed-updates"
156 genschrootconf "$suite" "$arch" "$target" "security"
159 genschrootconf "$suite" "$arch" "$target" "kfreebsd"
160 genschrootconf "$suite" "$arch" "$target" "kfreebsd-security"
170 local tmpschrootconf=$(tempfile)
171 cleanup+=("rm -f $tmpschrootconf")
172 genschrootconf "$suite" "$arch" "$target" > "$tmpschrootconf"
173 if ! [ -e "$schrootconfig" ] || ! diff "$schrootconfig" "$tmpschrootconf" > /dev/null; then
174 mv "$tmpschrootconf" "$schrootconfig"
175 chmod 644 "$schrootconfig"
184 if [ -e /etc/schroot/dsa/default-mirror ]; then
185 mirror=$(cat /etc/schroot/dsa/default-mirror )
187 mirror="${mirror:-https://deb.debian.org/debian}"
188 smirror="https://deb.debian.org/debian-security"
191 basedir="/srv/chroot"
193 keyring=/usr/share/keyrings/debian-archive-keyring.gpg
197 groupuser="Debian,guest,d-i"
199 include="apt,fakeroot,ca-certificates"
210 while getopts "a:b:Bcd:Dfg:hI:Kk:m:o:O:p:r:sS:u" OPTION
231 users="buildd,buildd2"
232 usersroot="buildd,buildd2"
250 include="$include,$OPTARG"
268 personality="$OPTARG"
288 shift $(($OPTIND - 1))
290 if [ "$#" != 1 ]; then
295 tuple="${suite}_${arch}"
297 if [ -z "${builddir:-}" ]; then
298 builddir=${builddir:-$basedir}
299 for u in schroot-unpack unpack; do
300 # if one of these directories exists and is on a different filesystem, prefer it.
301 candidate="$builddir/$u"
302 if [ -e "$candidate" ] &&
303 [ "$(stat -f --printf '%i\n' "$builddir" )" != "$(stat -f --printf '%i\n' "$candidate")" ]; then
304 builddir="$candidate"
308 [ -d "$basedir" ] || die "Error: $basedir does not exist (or is not a directory)."
309 [ -d "$builddir" ] || die "Error: $builddir does not exist (or is not a directory)."
311 target="$basedir/$tuple.tar.gz"
312 ! [ -e "$target" ] || [ -n "$force" ] || die "Error: $target already exists."
314 schrootconfig="/etc/schroot/chroot.d/${tuple}-$suffix"
315 ! [ -e "$schrootconfig" ] || [ -n "$force" ] || die "Error: $schrootconfig already exists."
322 suite_alias="$suite-kfreebsd"
333 if [ -n "$configonly" ]; then
338 rootdir=$(mktemp -d "$builddir/create-$suite-XXXXXX")
339 cleanup+=("rm -r $rootdir")
340 cleanup+=("umount $rootdir/sys")
341 script=/usr/share/debootstrap/scripts/"$suite"
342 if ! [ -e "$script" ]; then
343 if [ -z "$ubuntu" ]; then
344 script=/usr/share/debootstrap/scripts/sid
346 script=/usr/share/debootstrap/scripts/gutsy
351 stretch|jessie|precise|trusty|xenial)
352 include="$include,apt-transport-https"
357 cleanup+=("rm -r $bindir")
358 cat > "$bindir/wget" << 'EOF'
360 exec /usr/bin/wget --ca-directory=/etc/ssl/ca-global "$@"
362 chmod +x "$bindir/wget"
365 PATH="$bindir:$PATH" \
367 --keyring "$keyring" \
368 --include="$include" \
372 "$suite_alias" "$rootdir" "$mirror" "$script"
373 echo "$tuple" > "$rootdir/etc/debian_chroot"
374 echo "force-unsafe-io" > "$rootdir/etc/dpkg/dpkg.cfg.d/force-unsafe-io"
375 echo "force-confnew" > "$rootdir/etc/dpkg/dpkg.cfg.d/force-confnew"
377 cleanup+=("umount $rootdir/dev")
378 case "$(uname -s)" in
382 mount -t devfs none "$rootdir/dev"
385 echo >&2 "Warning: Unexpected uname -s output."
390 chroot "$rootdir" apt-get update
391 chroot "$rootdir" apt-get install -y --no-install-recommends policyrcd-script-zg2
392 cat > "$rootdir/usr/local/sbin/policy-rc.d" << 'EOF'
395 # policy-rc.d script for chroots.
396 # Copyright (c) 2007 Peter Palfrader <peter@palfrader.org>
403 echo "Not running services in chroot."
409 chmod +x "$rootdir/usr/local/sbin/policy-rc.d"
412 jessie) # LTS updates
413 echo "deb ${smirror} ${suite}/updates main" >> "$rootdir/etc/apt/sources.list"
414 chroot "$rootdir" apt-get update
415 chroot "$rootdir" apt-get dist-upgrade -y
418 if [ -n "$ubuntu" ]; then
419 echo "deb $mirror ${suite}-updates main" >> "$rootdir/etc/apt/sources.list"
420 echo "deb $mirror ${suite}-security main" >> "$rootdir/etc/apt/sources.list"
421 chroot "$rootdir" apt-get update
422 chroot "$rootdir" apt-get dist-upgrade -y
425 [ -z "$bare" ] && [ -z "$ubuntu" ] && chroot "$rootdir" apt-get install -y --no-install-recommends locales-all
426 chroot "$rootdir" apt-get install -y --no-install-recommends build-essential
427 [ -z "$bare" ] && chroot "$rootdir" apt-get install -y --no-install-recommends zsh less vim fakeroot devscripts gdb
428 rm -f "$rootdir/etc/apt/sources.list" "$rootdir/etc/apt/sources.list.d/*"
429 chroot "$rootdir" apt-get clean
430 umount "$rootdir/dev" 2>/dev/null || true
431 umount "$rootdir/sys" 2>/dev/null || true
433 tartmp=$(tempfile --directory "$basedir" --suffix=".tar.gz")
434 cleanup+=("rm -f $tartmp")
437 chmod 0755 "$rootdir"
439 if ! [ -z "$keep" ]; then
440 savelog -l -c 2 "$target"
442 mv "$tartmp" "$target"