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
44 -d dir place where to build the chroot [${builddir:-$basedir}]
45 -f overwrite config and target tarball
46 -g GROUPS groups that should have access to the schroot [$groupuser]
47 -k KEYRING use an alternate keyring [$keyring]
48 -p PERS use a different sbuild personality [$personality]
49 -r GROUPS groups that should have root in the schroot [$grouproot]
50 -s use sbuild compatible naming scheme
63 cnt=$((${#cleanup[*]}-1))
64 for i in $(seq ${cnt} -1 0); do
65 ${cleanup[$i]} || true
70 local suite="$1"; shift
71 local arch="$1"; shift
72 local target="$1"; shift
73 local extra="${1:-}"; shift || true
75 if [ -n "$extra" ]; then
76 local suite="${suite}-${extra}"
79 if [ -n "$sbuildnames" ]; then
80 local name="${suite}-${arch}-sbuild"
82 local name="${suite}_${arch}-dchroot"
88 description=[${name}] Debian $suite chroot for $arch
92 root-groups=$grouproot
94 #source-root-groups=adm
97 echo "profile=$personality"
99 if [ "$THISARCH" = "$arch" ]; then
100 echo "aliases=$suite"
103 armel|armhf|i386|powerpc|s390|sparc)
104 echo "personality=linux32"
111 genschrootconf "experimental" "$arch" "$target"
117 if [ -z "$extra" ] && [ -z "$ubuntu" ]; then
118 genschrootconf "$suite" "$arch" "$target" "backports"
124 local tmpschrootconf=$(tempfile)
125 cleanup+=("rm -f $tmpschrootconf")
126 genschrootconf "$suite" "$arch" "$target" > "$tmpschrootconf"
127 if ! [ -e "$schrootconfig" ] || ! diff "$schrootconfig" "$tmpschrootconf" > /dev/null; then
128 mv "$tmpschrootconf" "$schrootconfig"
129 chmod 644 "$schrootconfig"
138 if [ -e /etc/schroot/dsa/default-mirror ]; then
139 mirror=$(cat /etc/schroot/dsa/default-mirror )
141 mirror="${mirror:-http://cdn.debian.net/debian}"
144 basedir="/srv/chroot"
146 keyring=/usr/share/keyrings/debian-archive-keyring.gpg
150 groupuser="Debian,guest"
156 while getopts "a:b:Bcd:fg:hk:m:p:r:su" OPTION
191 personality="$OPTARG"
208 shift $(($OPTIND - 1))
210 if [ "$#" != 1 ]; then
215 tuple="${suite}_${arch}"
217 builddir=${builddir:-$basedir}
218 [ -d "$basedir" ] || die "Error: $basedir does not exist (or is not a directory)."
219 [ -d "$builddir" ] || die "Error: $builddir does not exist (or is not a directory)."
221 target="$basedir/$tuple.tar.gz"
222 ! [ -e "$target" ] || [ -n "$force" ] || die "Error: $target already exists."
224 schrootconfig="/etc/schroot/chroot.d/${tuple}-dchroot"
225 ! [ -e "$schrootconfig" ] || [ -n "$force" ] || die "Error: $schrootconfig already exists."
232 if [ -n "$configonly" ]; then
237 rootdir=$(mktemp -d "$builddir/create-$suite-XXXXXX")
238 cleanup+=("rm -r $rootdir")
239 cleanup+=("umount $rootdir/sys")
240 script=/usr/share/debootstrap/scripts/"$suite"
241 if ! [ -e "$script" ]; then
242 if [ -z "$ubuntu" ]; then
243 script=/usr/share/debootstrap/scripts/sid
245 script=/usr/share/debootstrap/scripts/gutsy
251 --keyring "$keyring" \
255 "$suite" "$rootdir" "$mirror" "$script"
256 echo "$tuple" > "$rootdir/etc/debian_chroot"
257 echo "force-unsafe-io" > "$rootdir/etc/dpkg/dpkg.cfg.d/force-unsafe-io"
259 cleanup+=("umount $rootdir/dev")
260 case "$(uname -s)" in
264 mount -t devfs none "$rootdir/dev"
267 echo >&2 "Warning: Unexpected uname -s output."
272 chroot "$rootdir" apt-get update
273 chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends policyrcd-script-zg2
274 cat > "$rootdir/usr/local/sbin/policy-rc.d" << 'EOF'
277 # policy-rc.d script for chroots.
278 # Copyright (c) 2007 Peter Palfrader <peter@palfrader.org>
285 echo "Not running services in chroot."
291 chmod +x "$rootdir/usr/local/sbin/policy-rc.d"
292 [ -z "$ubuntu" ] && chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends locales-all
293 chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends build-essential
294 [ -z "$bare" ] && chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends zsh less vim fakeroot devscripts gdb
295 rm -f "$rootdir/etc/apt/sources.list" "$rootdir/etc/apt/sources.list.d/*"
296 chroot "$rootdir" apt-get clean
297 umount "$rootdir/dev" 2>/dev/null || true
298 umount "$rootdir/sys" 2>/dev/null || true
300 tartmp=$(tempfile --directory "$basedir" --suffix=".tar.gz")
301 cleanup+=("rm -f $tartmp")
302 (cd "$rootdir" && tar caf "$tartmp" . && mv "$tartmp" "$target")