]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/porterbox/files/setup-dchroot
Replace the target tarfile atomically
[dsa-puppet.git] / modules / porterbox / files / setup-dchroot
index 0cba6fa12f1e5af1958e1dc22e0e269757aca444..6fa9e66c39648f56fcc28e878433b35a873c6275 100755 (executable)
@@ -39,8 +39,11 @@ 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.
-    -h         this help.
+    -c         write config only
+    -f         overwrite config and target tarball
+    -k KEYRING use an alternate keyring [$keyring]
+    -s         use sbuild compatible naming scheme
+    -h         this help
 EOF
 }
 
@@ -67,34 +70,45 @@ 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=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
-script-config=dsa/config
 EOF
 
+    if dpkg --compare-versions "$(lsb_release --release --short)" '<' 7; then
+        echo "script-config=dsa/config"
+    else
+        echo "profile=dsa"
+    fi
+
     if [ "$THISARCH" = "$arch" ]; then
         echo "aliases=$suite"
-    else
-        case "$arch" in
-            i386)
-                echo "personality=linux32"
-                ;;
-        esac
     fi
+    case "$arch" in
+        armel|armhf|i386|powerpc|s390|sparc)
+            echo "personality=linux32"
+            ;;
+    esac
     echo
 
     case "$suite" in
         sid)
             genschrootconf "experimental" "$arch" "$target"
             ;;
-        experimental)
+        experimental|jessie)
             :
             ;;
         *)
@@ -112,13 +126,16 @@ arch="$THISARCH"
 if [ -e /etc/schroot/dsa/default-mirror ]; then
     mirror=$(cat /etc/schroot/dsa/default-mirror )
 fi
-mirror="${mirror:-cdn.debian.net}"
+mirror="${mirror:-http://cdn.debian.net/debian}"
+configonly=""
 force=""
 basedir="/srv/chroot"
+keyring=/usr/share/keyrings/debian-archive-keyring.gpg
+sbuildnames=""
 declare -a cleanup
 trap do_cleanup EXIT
 
-while getopts "a:b:fhm:" OPTION
+while getopts "a:b:cfhk:m:s" OPTION
 do
     case $OPTION in
         a)
@@ -127,6 +144,9 @@ do
         b)
             basedir="$OPTARG"
             ;;
+        c)
+            configonly="1"
+            ;;
         f)
             force="1"
             ;;
@@ -134,9 +154,15 @@ do
             help
             exit 0
             ;;
+        k)
+            keyring="$OPTARG"
+            ;;
         m)
             mirror="$OPTARG"
             ;;
+        s)
+            sbuildnames="1"
+            ;;
         *)
             usage >&2
             exit 1
@@ -166,17 +192,19 @@ schrootconfig="/etc/schroot/chroot.d/${tuple}-dchroot"
 #
 genschrootconf "$suite" "$arch" "$target" | tee "$schrootconfig"
 
+if [ -n "$configonly" ]; then exit 0; fi
+
 rootdir=$(mktemp -d "$basedir/create-$suite-XXXXXX")
 cleanup+=("rm -r $rootdir")
 cleanup+=("umount $rootdir/sys")
 
 set -x
 debootstrap \
-    --keyring /usr/share/keyrings/debian-archive-keyring.gpg \
+    --keyring "$keyring" \
     --include="apt" \
     --variant=buildd \
     --arch="$arch" \
-    "$suite" "$rootdir" "http://$mirror/debian"
+    "$suite" "$rootdir" "$mirror"
 echo "$tuple" > $rootdir/etc/debian_chroot
 
 chroot "$rootdir" apt-get update
@@ -199,8 +227,10 @@ 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 vim fakeroot devscripts gdb
+chroot "$rootdir" apt-get install -y --no-install-recommends zsh locales-all build-essential less vim fakeroot devscripts gdb
 rm -f "$rootdir/etc/apt/sources.list" "$rootdir/etc/apt/sources.list.d/*"
 umount "$rootdir/sys" || true
 
-(cd "$rootdir" && tar caf "$target" .)
+tartmp=$(tempfile --directory "$basedir" --suffix=".tar.gz")
+cleanup+=("rm -f $tartmp")
+(cd "$rootdir" && tar caf "$tartmp" . && mv "$tartmp" "$target")