From ddff8d07400f3fd7d4bd741989fdb123bc838f81 Mon Sep 17 00:00:00 2001 From: graysky Date: Mon, 19 Oct 2015 08:24:14 -0400 Subject: update vncserver to parse a config file --- unix/vncserver | 74 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/unix/vncserver b/unix/vncserver index 64d10c5b..c7fdc655 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -81,6 +81,17 @@ $defaultXStartup "xterm -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n". "twm &\n"); +$defaultConfig + = ("## Supported server options to pass to vncserver upon invocation can be listed\n". + "## in this file. See the following manpages for more: vncserver(1) Xvnc(1).\n". + "## Several common ones are shown below. Uncomment and modify to your liking.\n". + "##\n". + "# securitytypes=vncauth,tlsvnc\n". + "# desktop=sandbox\n". + "# geometry=2000x1200\n". + "# localhost\n". + "# alwaysshared\n"); + chop($host = `uname -n`); if (-d "/etc/X11/fontpath.d") { @@ -252,17 +263,48 @@ if ($opt{'-name'}) { # Now start the X VNC Server $cmd = $exedir."Xvnc :$displayNumber"; -$cmd .= " -desktop " . "edString($desktopName); -$cmd .= " -httpd $vncJavaFiles" if ($vncJavaFiles); -$cmd .= " -auth $xauthorityFile"; -$cmd .= " -geometry $geometry" if ($geometry); -$cmd .= " -depth $depth" if ($depth); -$cmd .= " -pixelformat $pixelformat" if ($pixelformat); -$cmd .= " -rfbwait 30000"; -$cmd .= " -rfbauth $vncUserDir/passwd"; -$cmd .= " -rfbport $vncPort"; -$cmd .= " -fp $fontPath" if ($fontPath); -$cmd .= " -pn"; + +my %default_opts; +my %config; + +$default_opts{desktop} = "edString($desktopName); +$default_opts{httpd} = $vncJavaFiles if ($vncJavaFiles); +$default_opts{auth} = $xauthorityFile; +$default_opts{geometry} = $geometry if ($geometry); +$default_opts{depth} = $depth if ($depth); +$default_opts{pixelformat} = $pixelformat if ($pixelformat); +$default_opts{rfbwait} = 30000; +$default_opts{rfbauth} = "$vncUserDir/passwd"; +$default_opts{rfbport} = $vncPort; +$default_opts{fp} = $fontPath if ($fontPath); +$default_opts{pn} = ""; + +# if a user configuration file already exists +if(stat("$vncUserDir/config")) { + + # loads and parses configuration file + if(open(IN, "$vncUserDir/config")) { + while() { + next if /^#/; + if(my ($k, $v) = /^\s*(\w+)\s*=\s*(.+)$/) { + $config{$k} = $v; + } elsif ($_ =~ m/^\s*(\S+)/) { + $config{$1} = $k; + } + } + close(IN); + } +} + +foreach my $k (sort keys %config) { + $cmd .= " -$k $config{$k}"; + # user's option takes precedence + delete $default_opts{$k}; +} + +foreach my $k (sort keys %default_opts) { + $cmd .= " -$k $default_opts{$k}"; +} # Add color database stuff here, e.g.: # @@ -321,6 +363,16 @@ if (!(-e "$vncUserDir/xstartup")) { chmod 0755, "$vncUserDir/xstartup"; } +# Create the user's config file if necessary. + +if (!(-e "$vncUserDir/config")) { + warn "Creating default config $vncUserDir/config\n"; + open(XSTARTUP, ">$vncUserDir/config"); + print XSTARTUP $defaultConfig; + close(XSTARTUP); + chmod 0644, "$vncUserDir/config"; +} + # Run the X startup script. warn "Starting applications specified in $vncUserDir/xstartup\n"; -- cgit v1.2.3 From 02cbc222caf331d51bfaf50fc7d467ddcf25073c Mon Sep 17 00:00:00 2001 From: graysky Date: Mon, 19 Oct 2015 08:26:44 -0400 Subject: update manpage teaching about ~/.vnc/config --- unix/vncserver.man | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unix/vncserver.man b/unix/vncserver.man index 04a060ec..5ba6b8f1 100644 --- a/unix/vncserver.man +++ b/unix/vncserver.man @@ -134,6 +134,14 @@ A shell script specifying X applications to be run when a VNC desktop is started. If this file does not exist, then vncserver will create a default xstartup script which attempts to launch your chosen window manager. .TP +$HOME/.vnc/config +An optional server config file wherein options to be passed to Xvnc are listed +to avoid hard-coding them to the physical invocation. List options in this file +one per line. For those requiring an argument, simply separate the option from +the argument with an equal sign, for example: "geometry=2000x1200" or +"securitytypes=vncauth,tlsvnc". Options without an argument are simply listed +as a single word, for example: "localhost" or "alwaysshared". +.TP $HOME/.vnc/passwd The VNC password file. .TP -- cgit v1.2.3 From f4e620ac62c61db4090fc241944471b6a2807242 Mon Sep 17 00:00:00 2001 From: graysky Date: Mon, 19 Oct 2015 08:27:27 -0400 Subject: provide a systemd user service unit for vncserver --- contrib/systemd/user/vncserver@.service | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 contrib/systemd/user/vncserver@.service diff --git a/contrib/systemd/user/vncserver@.service b/contrib/systemd/user/vncserver@.service new file mode 100644 index 00000000..7797504b --- /dev/null +++ b/contrib/systemd/user/vncserver@.service @@ -0,0 +1,26 @@ +# +# /usr/lib/systemd/user/vncserver@.service +# +# 1. Switches for vncserver should be entered in ~/.vnc/config rather than +# hard-coded into this unit file. See the vncserver(1) manpage. +# +# 2. Users wishing for the server to continue running after the owner logs +# out MUST enable 'linger' with loginctl like this: +# `loginctl enable-linger username` +# +# 3. The server can be enabled and started like this once configured: +# `systemctl --user start vncserver@:.service` +# `systemctl --user enable vncserver@:.service` + +[Unit] +Description=Remote desktop service (VNC) +After=syslog.target network.target + +[Service] +Type=forking +ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' +ExecStart=/usr/bin/vncserver %i +ExecStop=/usr/bin/vncserver -kill %i + +[Install] +WantedBy=default.target -- cgit v1.2.3