blob: 28e88649667e7598c3764103367de8c691a3ca4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#! /usr/bin/env bash
# Get virtual machine console (using screen).
#
# Note: use Ctrl-a k to exit screen (or Ctrl-a a k if running inside screen).
#
usage="usage: $0 <console-socket>"
trap "{ exit 1; }" ERR
set -o errtrace # Trap in functions.
function info () { echo "$*" 1>&2; }
function error () { info "$*"; exit 1; }
con="$1"
if [ -z "$con" ]; then
error "missing console socket"
fi
pty="$(dirname "$con")/$(basename -s .sock "$con").pty"
socat "UNIX-CONNECT:$con" "PTY,link=$pty" &
pid="$!"
# Hack around terminal permission issue when running under `su - <user>`.
#
script -q -c "screen $pty" /dev/null
# Note: socat may have already terminated (e.g., VM was shut down).
#
kill "$pid" 2>/dev/null || true
wait
|