X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fporterbox%2Ffiles%2Fsetup-dchroot;h=3f6179d9b9ccb54ecd0f420259ca1d4b70689b5b;hb=20903357441b34d8c5d656fb1867cfb0898ebdbb;hp=6fa9e66c39648f56fcc28e878433b35a873c6275;hpb=caed4e8a72ed8ee23236d1b9d6829dd935f599a5;p=mirror%2Fdsa-puppet.git diff --git a/modules/porterbox/files/setup-dchroot b/modules/porterbox/files/setup-dchroot index 6fa9e66c3..3f6179d9b 100755 --- a/modules/porterbox/files/setup-dchroot +++ b/modules/porterbox/files/setup-dchroot @@ -38,11 +38,23 @@ usage: $0 OPTIONS: -a ARCH debootstrap arch [$arch] -m MIRROR http mirror to use [$mirror] - -b basedir place where to build the chroot/tarball [$basedir] + -b basedir place where to put the tarball [$basedir] + -B install less stuff into chroot [$bare] -c write config only + -D set up a buildd schroot - changes conffile name and + various defaults. Run -D -h. Also creates more aliases. + -d dir place where to build the chroot [${builddir:-$basedir}] -f overwrite config and target tarball + -g GROUPS groups that should have access to the schroot [$groupuser] + -K keep old tarballs around for a while (4 iterations) -k KEYRING use an alternate keyring [$keyring] - -s use sbuild compatible naming scheme + -o USER users that should have access to the schroot [$users] + -O USER users that should have root in the schroot [$usersroot] + -p PERS use a different sbuild personality [$personality] + -r GROUPS groups that should have root in the schroot [$grouproot] + -s use sbuild compatible naming scheme [$sbuildnames] + -S SUFFIX conffile suffix [$suffix] + -u Ubuntu target -h this help EOF } @@ -82,19 +94,15 @@ cat << EOF description=[${name}] Debian $suite chroot for $arch type=file file=$target -groups=Debian,guest -root-groups=adm -source-groups=adm -source-root-groups=adm EOF +[ -n "$groupuser" ] && echo "groups=$groupuser" +[ -n "$grouproot" ] && echo "root-groups=$grouproot" +[ -n "$users" ] && echo "users=$users" +[ -n "$usersroot" ] && echo "root-users=$usersroot" - if dpkg --compare-versions "$(lsb_release --release --short)" '<' 7; then - echo "script-config=dsa/config" - else - echo "profile=dsa" - fi + echo "profile=$personality" - if [ "$THISARCH" = "$arch" ]; then + if [ "$THISARCH" = "$arch" ] && [ -z "$buildd" ]; then echo "aliases=$suite" fi case "$arch" in @@ -108,16 +116,31 @@ EOF sid) genschrootconf "experimental" "$arch" "$target" ;; - experimental|jessie) + #experimental|jessie) + experimental) : ;; *) - if [ -z "$extra" ]; then + if [ -z "$extra" ] && [ -z "$ubuntu" ]; then genschrootconf "$suite" "$arch" "$target" "backports" + [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "backports-sloppy" + [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "lts" + [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "proposed-updates" + [ -n "$buildd" ] && genschrootconf "$suite" "$arch" "$target" "security" fi esac } +do_config() { + local tmpschrootconf=$(tempfile) + cleanup+=("rm -f $tmpschrootconf") + genschrootconf "$suite" "$arch" "$target" > "$tmpschrootconf" + if ! [ -e "$schrootconfig" ] || ! diff "$schrootconfig" "$tmpschrootconf" > /dev/null; then + mv "$tmpschrootconf" "$schrootconfig" + chmod 644 "$schrootconfig" + fi +} + set -e set -u @@ -130,12 +153,24 @@ mirror="${mirror:-http://cdn.debian.net/debian}" configonly="" force="" basedir="/srv/chroot" +builddir="" keyring=/usr/share/keyrings/debian-archive-keyring.gpg +personality="dsa" sbuildnames="" +ubuntu="" +groupuser="Debian,guest" +grouproot="" +users="" +usersroot="" +bare="" +keep="" +suffix="dchroot" declare -a cleanup +cleanup+=(":") trap do_cleanup EXIT +buildd="" -while getopts "a:b:cfhk:m:s" OPTION +while getopts "a:b:Bcd:Dfg:hKk:m:o:O:p:r:sS:u" OPTION do case $OPTION in a) @@ -144,25 +179,66 @@ do b) basedir="$OPTARG" ;; + B) + bare="1" + ;; c) configonly="1" ;; + D) + buildd="1" + sbuildnames="0" + bare="1" + groupuser="" + grouproot="" + users="buildd" + usersroot="buildd" + personality="buildd" + suffix="sbuild" + ;; + d) + builddir="$OPTARG" + ;; f) force="1" ;; + g) + groupuser="$OPTARG" + ;; h) - help + usage exit 0 ;; + K) + keep="4" + ;; k) keyring="$OPTARG" ;; m) mirror="$OPTARG" ;; + o) + users="$OPTARG" + ;; + O) + usersroot="$OPTARG" + ;; + p) + personality="$OPTARG" + ;; + r) + grouproot="$OPTARG" + ;; s) sbuildnames="1" ;; + S) + suffix="$OPTARG" + ;; + u) + ubuntu="1" + ;; *) usage >&2 exit 1 @@ -178,25 +254,37 @@ fi suite="$1"; shift tuple="${suite}_${arch}" +builddir=${builddir:-$basedir} [ -d "$basedir" ] || die "Error: $basedir does not exist (or is not a directory)." +[ -d "$builddir" ] || die "Error: $builddir does not exist (or is not a directory)." target="$basedir/$tuple.tar.gz" ! [ -e "$target" ] || [ -n "$force" ] || die "Error: $target already exists." -schrootconfig="/etc/schroot/chroot.d/${tuple}-dchroot" +schrootconfig="/etc/schroot/chroot.d/${tuple}-$suffix" ! [ -e "$schrootconfig" ] || [ -n "$force" ] || die "Error: $schrootconfig already exists." # # let's go # -genschrootconf "$suite" "$arch" "$target" | tee "$schrootconfig" -if [ -n "$configonly" ]; then exit 0; fi +if [ -n "$configonly" ]; then + do_config + exit 0 +fi -rootdir=$(mktemp -d "$basedir/create-$suite-XXXXXX") +rootdir=$(mktemp -d "$builddir/create-$suite-XXXXXX") cleanup+=("rm -r $rootdir") cleanup+=("umount $rootdir/sys") +script=/usr/share/debootstrap/scripts/"$suite" +if ! [ -e "$script" ]; then + if [ -z "$ubuntu" ]; then + script=/usr/share/debootstrap/scripts/sid + else + script=/usr/share/debootstrap/scripts/gutsy + fi +fi set -x debootstrap \ @@ -204,11 +292,26 @@ debootstrap \ --include="apt" \ --variant=buildd \ --arch="$arch" \ - "$suite" "$rootdir" "$mirror" -echo "$tuple" > $rootdir/etc/debian_chroot + "$suite" "$rootdir" "$mirror" "$script" +echo "$tuple" > "$rootdir/etc/debian_chroot" +echo "force-unsafe-io" > "$rootdir/etc/dpkg/dpkg.cfg.d/force-unsafe-io" +echo "force-confnew" > "$rootdir/etc/dpkg/dpkg.cfg.d/force-confnew" + +cleanup+=("umount $rootdir/dev") +case "$(uname -s)" in + Linux) + ;; + GNU/kFreeBSD) + mount -t devfs none "$rootdir/dev" + ;; + *) + echo >&2 "Warning: Unexpected uname -s output." + ;; +esac + chroot "$rootdir" apt-get update -chroot "$rootdir" apt-get install -y --no-install-recommends policyrcd-script-zg2 +chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends policyrcd-script-zg2 cat > "$rootdir/usr/local/sbin/policy-rc.d" << 'EOF' #!/bin/sh @@ -227,10 +330,23 @@ while true; do done EOF chmod +x "$rootdir/usr/local/sbin/policy-rc.d" -chroot "$rootdir" apt-get install -y --no-install-recommends zsh locales-all build-essential less vim fakeroot devscripts gdb +[ -z "$bare" ] && [ -z "$ubuntu" ] && chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends locales-all +chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends build-essential +[ -z "$bare" ] && chroot "$rootdir" apt-get install -y --force-yes --no-install-recommends zsh less vim fakeroot devscripts gdb rm -f "$rootdir/etc/apt/sources.list" "$rootdir/etc/apt/sources.list.d/*" -umount "$rootdir/sys" || true +chroot "$rootdir" apt-get clean +umount "$rootdir/dev" 2>/dev/null || true +umount "$rootdir/sys" 2>/dev/null || true tartmp=$(tempfile --directory "$basedir" --suffix=".tar.gz") cleanup+=("rm -f $tartmp") -(cd "$rootdir" && tar caf "$tartmp" . && mv "$tartmp" "$target") +( + cd "$rootdir" + tar caf "$tartmp" . + if ! [ -z "$keep" ]; then + savelog -l -c 4 "$target" + fi + mv "$tartmp" "$target" +) + +do_config