X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Fporterbox%2Ffiles%2Fsetup-dchroot;h=81732c614cf20d9830032ac5674546dc6794debd;hb=ee6c1be33c3361ff9939dc02987ab10cd1fab924;hp=e741b2d844272c46ff8d5292c47ec12befe98741;hpb=07d77a0a6f925852cd744eb1ebd28d6395c03c27;p=dsa-puppet.git diff --git a/modules/porterbox/files/setup-dchroot b/modules/porterbox/files/setup-dchroot index e741b2d8..81732c61 100755 --- a/modules/porterbox/files/setup-dchroot +++ b/modules/porterbox/files/setup-dchroot @@ -38,10 +38,18 @@ 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] - -f overwrite stuff. - -c write config only. - -h this help. + -b basedir place where to put the tarball [$basedir] + -B install less stuff into chroot + -c write config only + -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 KEYRING use an alternate keyring [$keyring] + -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 + -u Ubuntu target + -h this help EOF } @@ -68,21 +76,28 @@ genschrootconf() { local suite="${suite}-${extra}" fi + if [ -n "$sbuildnames" ]; then + local name="${suite}-${arch}-sbuild" + else + local name="${suite}_${arch}-dchroot" + fi + + cat << EOF -[${suite}_${arch}-dchroot] -description=[${suite}_${arch}-dchroot] Debian $suite chroot for $arch +[${name}] +description=[${name}] Debian $suite chroot for $arch type=file file=$target -groups=Debian,guest -root-groups=adm -source-groups=adm -source-root-groups=adm +groups=$groupuser +root-groups=$grouproot +#source-groups=adm +#source-root-groups=adm EOF if dpkg --compare-versions "$(lsb_release --release --short)" '<' 7; then - echo "script-config=dsa/config" + echo "script-config=$personality/config" else - echo "profile=dsa" + echo "profile=$personality" fi if [ "$THISARCH" = "$arch" ]; then @@ -103,12 +118,22 @@ EOF : ;; *) - if [ -z "$extra" ]; then + if [ -z "$extra" ] && [ -z "$ubuntu" ]; then genschrootconf "$suite" "$arch" "$target" "backports" 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 @@ -121,10 +146,18 @@ 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="" +bare="" declare -a cleanup trap do_cleanup EXIT -while getopts "a:b:cfhm:" OPTION +while getopts "a:b:Bcd:fg:hk:m:p:r:su" OPTION do case $OPTION in a) @@ -133,19 +166,43 @@ do b) basedir="$OPTARG" ;; + B) + bare="1" + ;; c) configonly="1" ;; + d) + builddir="$OPTARG" + ;; f) force="1" ;; + g) + groupuser="$OPTARG" + ;; h) - help + usage exit 0 ;; + k) + keyring="$OPTARG" + ;; m) mirror="$OPTARG" ;; + p) + personality="$OPTARG" + ;; + r) + grouproot="$OPTARG" + ;; + s) + sbuildnames="1" + ;; + u) + ubuntu="1" + ;; *) usage >&2 exit 1 @@ -161,7 +218,9 @@ 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." @@ -173,25 +232,49 @@ schrootconfig="/etc/schroot/chroot.d/${tuple}-dchroot" # # 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 \ - --keyring /usr/share/keyrings/debian-archive-keyring.gpg \ + --keyring "$keyring" \ --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" + +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 @@ -210,8 +293,16 @@ 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 "$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 "$target" .) +do_config