qvm-console 890 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. print_usage() {
  3. cat >&2 <<USAGE
  4. Usage: $0 vmname
  5. Connects to another VM console using the admin.vm.Console RPC service.
  6. USAGE
  7. }
  8. if [ $# -lt 1 ] ; then
  9. print_usage
  10. exit 1
  11. fi
  12. QREXEC_REQUESTED_TARGET="$1"
  13. qrexec_console() {
  14. QREXEC_REQUESTED_TARGET="$1"
  15. qrexec-client-vm "$QREXEC_REQUESTED_TARGET" admin.vm.Console
  16. # exit code 200 is flock exit code in admin.vm.Console
  17. exit_code=$?
  18. if [ $exit_code -gt 0 ]; then
  19. if [ $exit_code -ne 200 ]; then
  20. printf "Cannot connect to %s" "$QREXEC_REQUESTED_TARGET"
  21. else
  22. printf "A qube is already connected to %s" "$QREXEC_REQUESTED_TARGET"
  23. fi
  24. exit 1
  25. fi
  26. }
  27. export -f qrexec_console
  28. printf "Use '^]' to exit remote console\n"
  29. socat file:/dev/tty,rawer,escape=0x1d EXEC:"/bin/bash -c \'qrexec_console $QREXEC_REQUESTED_TARGET 2>/dev/null\'"
  30. printf '\n'