]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/porterbox/files/setup-dchroot
Speed up dpkg by using unasfe-io on porterbox chroots
[dsa-puppet.git] / modules / porterbox / files / setup-dchroot
index 130feac70fb6fbd3989b00225954f1d132efd1c1..e99e54af211b750b308865902aed81700b19faf1 100755 (executable)
@@ -42,8 +42,10 @@ OPTIONS:
     -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
@@ -85,10 +87,10 @@ 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
+groups=$groupuser
+root-groups=$grouproot
+#source-groups=adm
+#source-root-groups=adm
 EOF
 
     if dpkg --compare-versions "$(lsb_release --release --short)" '<' 7; then
@@ -121,6 +123,16 @@ EOF
     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
@@ -138,10 +150,12 @@ keyring=/usr/share/keyrings/debian-archive-keyring.gpg
 personality="dsa"
 sbuildnames=""
 ubuntu=""
+groupuser="Debian,guest"
+grouproot=""
 declare -a cleanup
 trap do_cleanup EXIT
 
-while getopts "a:b:cd:fhk:m:p:su" OPTION
+while getopts "a:b:cd:fg:hk:m:p:r:su" OPTION
 do
     case $OPTION in
         a)
@@ -159,6 +173,9 @@ do
         f)
             force="1"
             ;;
+        g)
+            groupuser="$OPTARG"
+            ;;
         h)
             usage
             exit 0
@@ -172,6 +189,9 @@ do
         p)
             personality="$OPTARG"
             ;;
+        r)
+            grouproot="$OPTARG"
+            ;;
         s)
             sbuildnames="1"
             ;;
@@ -207,9 +227,11 @@ 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 "$builddir/create-$suite-XXXXXX")
 cleanup+=("rm -r $rootdir")
@@ -223,9 +245,10 @@ debootstrap \
     --arch="$arch" \
     "$suite" "$rootdir" "$mirror"
 echo "$tuple" > $rootdir/etc/debian_chroot
+echo "force-unsafe-io" > $rootdir/etc/dpkg/dpkg.cfg.d/force-unsafe-io
 
 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
 
@@ -244,11 +267,14 @@ while true; do
 done
 EOF
 chmod +x "$rootdir/usr/local/sbin/policy-rc.d"
-[ -z "$ubuntu" ] && chroot "$rootdir" apt-get install -y --no-install-recommends locales-all
-chroot "$rootdir" apt-get install -y --no-install-recommends zsh 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 zsh build-essential less vim fakeroot devscripts gdb
 rm -f "$rootdir/etc/apt/sources.list" "$rootdir/etc/apt/sources.list.d/*"
+chroot "$rootdir" apt-get clean
 umount "$rootdir/sys" || true
 
 tartmp=$(tempfile --directory "$basedir" --suffix=".tar.gz")
 cleanup+=("rm -f $tartmp")
 (cd "$rootdir" && tar caf "$tartmp" . && mv "$tartmp" "$target")
+
+do_config