chiark / gitweb /
* New `console' mode for userv service.
[autopkgtest.git] / xen / userv-target
1 #!/bin/bash
2 set -e
3 fail () { printf >&2 "%s: %s\n" "$0" "$*"; exit 127; }
4
5 if test -f /etc/lsb-release; then . /etc/lsb-release; fi
6
7 d="${USERV_U_distro:-$DISTRIB_CODENAME}"
8 n="${USERV_U_nominum:-adt}"
9
10 for v in ssh_privkey ssh_keyident_args; do
11         eval "
12                 if [ \"x\$USERV_U_$v\" != x ]; then
13                         export adt_$v=\"\$USERV_U_$v\"
14                 fi
15         "
16 done
17
18 if [ "x$adt_ssh_privkey$adt_ssh_keyident_args" = x ]; then
19         export adt_ssh_keyident_args=' '
20         # There's no point directing userv callers to use the one in
21         # /root/.ssh/id_dsa_adt* since that one is only readable by
22         # root.  So if they don't specify one we just let them have
23         # whatever the default is.
24 fi
25
26 nd="${n}_${d}"
27
28 case "$nd" in
29 */*|.*|*.*|*_*_*)       fail 'dangerous format in distro or nominum'    ;;
30 adt*)   ;;
31 *)      fail 'userv adtxenlvm only supports nominums starting with adt' ;;
32 esac
33
34 nddir=/var/lib/autopkgtest/xenlvm/"$nd"
35 test -d "$nddir" || fail 'unknown distro or nominum'
36
37 run () {
38         base="$1"; shift
39         exec "$base" --adt-distro="$d" --adt-nominum="$n" "$@"
40 }
41
42 case "$1" in
43 with)   run adt-xenlvm-with-testbed sh -c 'echo y && exec cat' ;;
44 pon0)   run adt-xenlvm-on-testbed -- --print0-command ;;
45 console) xm console "$nd" ;;
46 *)      fail 'unknown mode'
47 esac