From 7736e1fd6f496a513a9b27fbb0bec423108683ce Mon Sep 17 00:00:00 2001 From: Mathis Rosenhauer <rosenhauer@dkrz.de> Date: Fri, 2 Jun 2017 14:32:31 +0200 Subject: [PATCH] set -u --- startvnc | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/startvnc b/startvnc index 8a8fd6c..15f194a 100755 --- a/startvnc +++ b/startvnc @@ -5,7 +5,8 @@ # Mathis Rosenhauer # Deutsches Klimarechenzentrum GmbH # Bundesstr. 45a -# 20146 Hamburg Germany +# 20146 Hamburg +# Germany # # All rights reserved. # @@ -49,7 +50,7 @@ # TigerVNC and TightVNC are known to work. # -set -e +set -eu # Default settings @@ -74,8 +75,9 @@ SVNC_VNCVIEWER="/usr/bin/vncviewer" # Uncomment this if you use TurboVNC as vncviewer #readonly SVNC_VNC_OPTIONS="-extssh" -# Frontend host. Must be directly accessible from client. Frontend -# and node where vnc server is running need a shared home file system. +# Frontend host. Must be directly accessible from client. The frontend +# and the node where vncserver is running need a shared home file +# system. readonly SVNC_FRONTEND_HOST="mistral.dkrz.de" # Copy vncpassword temporarily to the local workstation @@ -105,7 +107,7 @@ clean_up () { # Remove local vnc PasswordFile if [[ ${SVNC_PASSWORD} = "true" ]]; then - rm -f ${HOME}/vnc_passwd + rm -f "${HOME}/vnc_passwd" fi exit } @@ -117,15 +119,16 @@ usage () { } ssh_frontend () { - local ssh_options="$2 -o ForwardX11=no \ + local command="$1" + local extra_options="${2:-}" + local options="${extra_options} -o ForwardX11=no \ -o ControlPath=${ssh_socket_dir}/control:%h:%p:%r" - ssh ${ssh_options} "${SVNC_USERNAME}@${SVNC_FRONTEND_HOST}" "$1" + ssh ${options} "${SVNC_USERNAME}@${SVNC_FRONTEND_HOST}" "${command}" } parse_options () { local option - while getopts 'A:g:q:t:u:v:x:' option - do + while getopts 'A:g:q:t:u:v:x:' option; do case ${option} in A) SVNC_ACCTCODE="$OPTARG" ;; @@ -142,7 +145,7 @@ parse_options () { x) SVNC_VNC_OPTIONS="$OPTARG" ;; ?) usage - exit 2 + exit 1 ;; esac done @@ -158,7 +161,7 @@ parse_options () { if [[ -z ${SVNC_ACCTCODE} ]] || [[ -z ${SVNC_USERNAME} ]]; then printf "ERROR: Please specify at least username and acctcode.\n\n" >&2 usage - exit 2 + exit 1 fi } @@ -219,7 +222,7 @@ main () { vnc_host=${host_and_display%:*} vnc_display=${host_and_display#*:} - local vnc_options="${SVNC_VNC_OPTIONS} \ + local vnc_options="${SVNC_VNC_OPTIONS:-} \ -via ${SVNC_USERNAME}@${vnc_host}.dkrz.de" if [[ ${SVNC_PASSWORD} = "true" ]]; then ssh_frontend "cat .vnc/passwd" > ${HOME}/vnc_passwd -- GitLab