From 596d82d2a53a9073d09d75af98ab58fd758d94f2 Mon Sep 17 00:00:00 2001
From: Mathis Rosenhauer <rosenhauer@dkrz.de>
Date: Tue, 6 Aug 2019 16:13:15 +0200
Subject: [PATCH] start-vnc: CLI option for server options

---
 start-vnc | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/start-vnc b/start-vnc
index 3d873cd..f609d9b 100755
--- a/start-vnc
+++ b/start-vnc
@@ -68,13 +68,14 @@ SVNC_USERNAME="$(id -un)"
 #
 # If your local vnc client is not in the search path or named
 # differently (e.g. TurboVNC, macOS), then change this parameter.
-SVNC_VNCVIEWER="vncviewer"
+SVNC_CLIENT="vncviewer"
 
-# Resolution of remote desktop window
+# Server options
 #
-# This is just the initial resolution. Resizing the vncviewer window
-# later should also work.
-SVNC_GEOMETRY="1920x1200"
+# More options for the vncserver. TurboVNC on A Mac may produce
+# a 'javax.net.ssl.SSLHandshakeException' in this case adding
+# ' -securitytypes none' to SVNC_SERVER_OPTIONS may help.
+SVNC_SERVER_OPTIONS="-geometry1920x1200"
 
 # Session run time in minutes
 SVNC_RUNTIME=240
@@ -96,7 +97,7 @@ SVNC_CONSTRAINT=""
 # implementation of ssh which dosen't support public key auth among other
 # things.
 #
-# readonly SVNC_VNC_OPTIONS="-extssh"
+# readonly SVNC_CLIENT_OPTIONS="-extssh"
 
 # Frontend host
 #
@@ -150,9 +151,9 @@ Available values for OPTION include:
 
   -A acctcode  acctcode of job
   -C list      constraint for feature selection
-  -g geometry  initial geometry of vnc window
   -n nodes     number of nodes
   -q qos       job qos
+  -s options   addidtional options for vncserver
   -t time      job runtime
   -u username  use username for login
   -v path      path to vncviewer program
@@ -172,25 +173,25 @@ ssh_frontend () {
 
 parse_options () {
     local option
-    while getopts 'A:C:g:n:q:t:u:v:x:' option; do
+    while getopts 'A:C:n:q:s:t:u:v:x:' option; do
         case ${option} in
             A) SVNC_ACCTCODE="$OPTARG"
                ;;
             C) SVNC_CONSTRAINT="$OPTARG"
                ;;
-            g) SVNC_GEOMETRY="$OPTARG"
-               ;;
             n) SVNC_NODES="$OPTARG"
                ;;
             q) SVNC_QOS="$OPTARG"
                ;;
+            s) SVNC_SERVER_OPTIONS="$OPTARG"
+               ;;
             t) SVNC_RUNTIME="$OPTARG"
                ;;
             u) SVNC_USERNAME="$OPTARG"
                ;;
-            v) SVNC_VNCVIEWER="$OPTARG"
+            v) SVNC_CLIENT="$OPTARG"
                ;;
-            x) SVNC_VNC_OPTIONS="$OPTARG"
+            x) SVNC_CLIENT_OPTIONS="$OPTARG"
                ;;
             ?) usage
             exit 1
@@ -200,12 +201,12 @@ parse_options () {
 
     readonly SVNC_ACCTCODE
     readonly SVNC_CONSTRAINT
-    readonly SVNC_GEOMETRY
+    readonly SVNC_SERVER_OPTIONS
     readonly SVNC_QOS
     readonly SVNC_RUNTIME
     readonly SVNC_USERNAME
-    readonly SVNC_VNCVIEWER
-    readonly SVNC_VNC_OPTIONS
+    readonly SVNC_CLIENT
+    readonly SVNC_CLIENT_OPTIONS
 
     if [[ -z ${SVNC_ACCTCODE} ]]; then
         printf "ERROR: Please specify an acctcode.\n\n" >&2
@@ -246,7 +247,7 @@ ${sbatch_resources}
 #SBATCH --parsable
 #SBATCH --dkrzepilog=0
 cd \${HOME}
-/opt/TurboVNC/bin/vncserver -fg -geometry "${SVNC_GEOMETRY}" -localhost -securitytypes none
+/opt/TurboVNC/bin/vncserver -fg -localhost ${SVNC_SERVER_OPTIONS}
 EOF
 }
 
@@ -292,15 +293,15 @@ main () {
         -Nf \
         "${SVNC_USERNAME}@${vnc_host}.dkrz.de";
 
-    local vnc_options
-    vnc_options="${SVNC_VNC_OPTIONS:-}"
+    local client_options
+    client_options="${SVNC_CLIENT_OPTIONS:-}"
     if [[ ${SVNC_PASSWORD} = "true" ]]; then
         echo "Fetching password from frontend."
         ssh_frontend "cat .vnc/passwd" > vnc_passwd
-        vnc_options+=" -passwd vnc_passwd"
+        client_options+=" -passwd vnc_passwd"
     fi
     echo "Connecting vncviewer to ${vnc_host}.dkrz.de"
-    "${SVNC_VNCVIEWER}" ${vnc_options} :${vnc_display}
+    "${SVNC_CLIENT}" ${client_options} :${vnc_display}
 }
 
 main "$@"
-- 
GitLab