aboutsummaryrefslogtreecommitdiff
path: root/roles/tigervnc/files/vnc-server-wrapper
blob: ee25926f0f15841e17d2f4a8028e55c0ae108eb6 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -euo pipefail

VNC_PORT=5901
DISP_NUM=1
LOGFILE="/tmp/vnc-${USER}.log"

usage() {
    printf "%s\n" \
        "wrapper script to manage tigervnc server sessions" \
        "usage: $(basename $0) <start | stop | list>" \
        "" \
        "start      start tigervnc on port ${VNC_PORT}" \
        "stop       loop 1 through 10 and kill any tigervnc server displays" \
        "list       list running tigervnc servers"
    exit 1
}

case "${1:-}" in
    start)
        printf "%s\n" \
            "linux connection options:" \
            "  ssh -fL ${VNC_PORT}:localhost:${VNC_PORT} user@server sleep 10; vncviewer localhost:${VNC_PORT}" \
            "  vncviewer -via user@server localhost::${VNC_PORT}" \
            "" \
            "windows connection options:" \
            "  PLINK.EXE -no-antispoof -N -L ${VNC_PORT}:localhost:${VNC_PORT} user@server" \
            "  \"C:\\Program Files (x86)\\TigerVNC\\vncviewer.exe\" localhost:${VNC_PORT}"

        printf "%s\n" "[inf] starting tigervnc on :${DISP_NUM}, localhost-only"
        vncserver :${DISP_NUM}      \
            -localhost yes          \
            -rfbport ${VNC_PORT}    \
            -securitytypes none     \
            -geometry 1280x800      \
            -cleanstale &> "${LOGFILE}"
        printf "%s\n" "[inf] vnc started, log: ${LOGFILE}"
        ;;
    stop)
        printf "%s\n" "[inf] stopping all running tigervnc sessions"
        for i in $(seq 1 10); do
            vncserver -kill :$i -clean 2>/dev/null || true
        done
        ;;
    list)
        vncserver -list
        ;;
    *)
        usage
        ;;
esac