From: graysky Date: Mon, 19 Oct 2015 12:24:14 +0000 (-0400) Subject: update vncserver to parse a config file X-Git-Tag: v1.5.90~7^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ddff8d07400f3fd7d4bd741989fdb123bc838f81;p=tigervnc.git update vncserver to parse a config file --- 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";