chiark / gitweb /
initial skeleton for adt-virt-chroot
authorIan Jackson <ian@anarres>
Tue, 6 Dec 2005 18:32:08 +0000 (18:32 +0000)
committerIan Jackson <ian@anarres>
Tue, 6 Dec 2005 18:32:08 +0000 (18:32 +0000)
virt-chroot/adt-virt-chroot [new file with mode: 0755]

diff --git a/virt-chroot/adt-virt-chroot b/virt-chroot/adt-virt-chroot
new file mode 100755 (executable)
index 0000000..7bb7555
--- /dev/null
@@ -0,0 +1,61 @@
+#!/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'