#!/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 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