chiark / gitweb /
merge changes 0.9.0 -> 0.9.3 etc
[autopkgtest.git] / xen / userv-target
index e9ad631ac0cf3cb7382e09b56b149bcc54cdfc56..362d5cf5f0e827223795e33e3a0555cb8de4230d 100755 (executable)
@@ -1,8 +1,47 @@
 #!/bin/bash
 set -e
-d="$USERV_U_distro"
 fail () { printf >&2 "%s: %s\n" "$0" "$*"; exit 127; }
 
-test "x$d" = "x${d#/*}" || fail 'distro may not contain slashes'
-test -d /var/lib/autopkgtest/xenlvm/adt_"$d" || fail 'unknown distro'
-exec adt-xenlvm-with-testbed --adt-distro="$d" sh -c 'echo y && exec cat'
+if test -f /etc/lsb-release; then . /etc/lsb-release; fi
+
+d="${USERV_U_distro:-$DISTRIB_CODENAME}"
+n="${USERV_U_nominum:-adt}"
+
+for v in ssh_privkey ssh_keyident_args; do
+       eval "
+               if [ \"x\$USERV_U_$v\" != x ]; then
+                       export adt_$v=\"\$USERV_U_$v\"
+               fi
+       "
+done
+
+if [ "x$adt_ssh_privkey$adt_ssh_keyident_args" = x ]; then
+       export adt_ssh_keyident_args=' '
+       # There's no point directing userv callers to use the one in
+       # /root/.ssh/id_dsa_adt* since that one is only readable by
+       # root.  So if they don't specify one we just let them have
+       # whatever the default is.
+fi
+
+nd="${n}_${d}"
+
+case "$nd" in
+*/*|.*|*.*|*_*_*)      fail 'dangerous format in distro or nominum'    ;;
+adt*)  ;;
+*)     fail 'userv adtxenlvm only supports nominums starting with adt' ;;
+esac
+
+nddir=/var/lib/autopkgtest/xenlvm/"$nd"
+test -d "$nddir" || fail 'unknown distro or nominum'
+
+run () {
+       base="$1"; shift
+       exec "$base" --adt-distro="$d" --adt-nominum="$n" "$@"
+}
+
+case "$1" in
+with)  run adt-xenlvm-with-testbed sh -c 'echo y && exec cat' ;;
+pon0)  run adt-xenlvm-on-testbed -- --print0-command ;;
+console) xm console "$nd" ;;
+*)     fail 'unknown mode'
+esac