--- /dev/null
+#!/bin/sh
+# usage:
+# adt-virt-chroot =[CHROOTNAME]
+# uses dchroot (but problems with spaces)
+# spaces in CHROOTNAME also not permitted
+# adt-virt-chroot [-rGAINROOT] /PATH/TO/CHROOT
+# uses GAINROOT chroot
+# GAINROOT will be split up if it has spaces
+
+set -e
+
+fail () { echo >&2 "$0: $@"; exit 16; }
+
+gainroot=''
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --|-) break=break; break; shift ;;
+ -r*) gainroot="${1#-r}" ;;
+ -*) fail "bad usage - unknown option $1" ;;
+ *) break=break; break ;;
+ esac
+ $break
+ shift
+done
+
+[ $# -eq 1 ] || fail "bad usage - need =DCHROOTNAME or /CHROOT/PATH"
+
+case "$1" in
+/*) down="$gainroot chroot $1 --" ;;
+=?*) down="$gainroot dchroot -d\"${1#=}\" -q" ;;
+=) down="$gainroot dchroot -q" ;;
+*) fail "bad usage - unknown chroot specification $1" ;;
+esac
+
+$down true
+echo ok
+
+close_down () {
+ :
+}
+
+trap 'close_down; exit 12;' 0
+
+while read command arg1 arg2; do
+ case "$command" in
+ capabilities)
+ echo 'ok '
+ ;;
+ quit)
+ trap '' 0
+ close_down
+ exit 0
+ ;;
+ *)
+ fail "unrecognised command $command"
+ ;;
+ esac
+done
+
+fail 'unexpected EOF on control channel'