]> 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 8a2b724b5cd2862b9a0fa04c0f62015b8aea5914..6fa9e66c39648f56fcc28e878433b35a873c6275 100755 (executable)
@@ -39,9 +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.
-    -c         write config only.
-    -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
 }
 
@@ -68,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=[${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
-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)
             :
             ;;
         *)
@@ -117,10 +130,12 @@ 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:cfhm:" OPTION
+while getopts "a:b:cfhk:m:s" OPTION
 do
     case $OPTION in
         a)
@@ -139,9 +154,15 @@ do
             help
             exit 0
             ;;
+        k)
+            keyring="$OPTARG"
+            ;;
         m)
             mirror="$OPTARG"
             ;;
+        s)
+            sbuildnames="1"
+            ;;
         *)
             usage >&2
             exit 1
@@ -179,7 +200,7 @@ cleanup+=("umount $rootdir/sys")
 
 set -x
 debootstrap \
-    --keyring /usr/share/keyrings/debian-archive-keyring.gpg \
+    --keyring "$keyring" \
     --include="apt" \
     --variant=buildd \
     --arch="$arch" \
@@ -210,4 +231,6 @@ chroot "$rootdir" apt-get install -y --no-install-recommends zsh locales-all bui
 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")