#!/usr/bin/env perl use warnings; use strict; # mergeconfig: complete the sysinfo client config file without asking questions. # # Run by installer/setup (with --quiet). Reads the existing config file (or the file given with # --file), fills blank values from server.info and from discovery (hostname, serial number, UUID), # adds the default directories and the SaveLocal transport when missing, then writes the result. # To change values by hand use configure, which runs dsEdit on the config file. # # v1.1.0 20161022 RWR # use library sysinfoconf.pm for loading, editing and displaying config # # v1.2.0 20190108 RWR # added UUID # # v1.3.0 20191107 RWR # changed the screen to allow the user to see most of the values and decide what to edit # then write the results. # also, parameters are passed that allow the import of a file in old conf format # # v1.3.1 20191112 RWR # Fixed showEntry() to set value to empty string if it is null # # v1.4.0 20261019 Claude # option b edits update.url (where sysinfo_update finds the tarball); entries may have a 'subkey' # # v2.0.0 20261025 Claude # bug 212: moved from configure to installer/mergeconfig. configure is now a wrapper around dsEdit # (the interactive editor); this script is what installer/setup runs (-q) to merge server.info and # defaults into the config file. # # v2.1.0 20261025 Claude # bug 212: the interactive menu and transport prompts are gone (configure/dsEdit do that); the script # never asks anything, so --quiet is accepted but has no effect. --dryrun now says it did not write. use Getopt::Long; use version; our $VERSION = version->declare('2.1.0'); # find our location and use it for searching for libraries (they are in the directory above installer/) BEGIN { use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin, File::Spec->updir()); } use Cwd qw(abs_path); use sysinfoconf; # a library of shared routines with install.pl $binDir = abs_path(File::Spec->catdir($FindBin::Bin, File::Spec->updir())); my $config; # will validate the config, adding modules, scripts and transports if necessary sub testConfig { my $config = shift; my @return; push @return, 'No client name given' unless $config->{'clientName'}; push @return, 'No host name given' unless $config->{'hostname'}; $config->{'serialNumber'} = $config->{'UUID'} if $config->{'serialNumber'} eq 'NotSpecified'; push @return, 'No serial number given' unless $config->{'serialNumber'}; push @return, 'No UUID given' unless $config->{'UUID'}; # if scriptDirs not defined, use installdir/scripts $config->{'scriptDirs'} = [ $binDir . '/scripts' ] unless @{$config->{'scriptDirs'}}; # if moduleDirs not defined, use installdir/modules $config->{'moduleDirs'} = [ $binDir . '/modules' ] unless defined $config->{'moduleDirs'}; # ensure we have the default SaveLocal transport defined unless ( defined $config->{'transports'}{'99'} ) { $config->{'transports'}{'99'} = { 'name'=> 'SaveLocal', 'output directory' => '/tmp', 'sendScript' => 'save_local' }; } return @return ? join ( "\n", @return ) . "\n" : 'Ok'; } sub help { print "$0 version $VERSION\n"; print "Reads a sysinfo configuration file, fills in blank values (from server.info and discovery)\n"; print "and writes it back. Asks no questions; use configure to edit values by hand.\n\n"; print "$0 --file=/full/path/to/input --output=/full/path/to/sysinfo_client.yaml\n"; print " --verbose - accepted for compatibility, no effect\n"; print " --file - config file to read\n"; print " --output - file which will be written to\n"; print " --test - report problems found in the config file\n"; print " --dryrun - do not save result\n"; print " --quiet - accepted for compatibility (this script never asks questions)\n"; print " --help - display this help screen\n\n"; print "All parameters are optional\n"; print "Will search common locations for sysinfo_client.yaml if no --file is given.\n"; print "If no --output is given, writes to the file which was found in the search.\n"; print "All parameters accept the short flag, ie -v, -f, -o and -h\n"; exit; } my $confFileName; my $outputFile; my $verbose; my $help; my $test = 0; my $dryRun = 0; my $quiet = 0; GetOptions ( "verbose|v+" => \$verbose, # accepted for compatibility 'file|f=s' => \$confFileName, # file name to use 'output|o=s' => \$outputFile, # file to save to 'test|t' => \$test, # test the config file 'dryrun|n' => \$dryRun, # do not save result 'quiet|q' => \$quiet, # accepted for compatibility 'help|h' => \$help ) or die "Error parsing command line\n"; if ( $help ) { &help() ; exit; } # look for the standard configuration file in the standard place unless ( $confFileName ) { ( $confDir, $sysinfo3 ) = &findConf( $sysinfo3 ); $outputFile = $confDir . '/' . $sysinfo3 unless $outputFile; $confFileName = $confDir . "/" . $sysinfo3 if ( $confDir ); } print "Loading defaults from existing config\n"; $config = &makeConfig( $outputFile, $confFileName ); my $testResults = &testConfig($config); print "Error found in configuration file; edit it with configure\n" if ( $testResults ne 'Ok' ); print $testResults if $test || $testResults ne 'Ok'; if ( $dryRun ) { print "Dry run: $outputFile not written\n"; } else { print "Config File written to $outputFile\n"; &writeConfig( $outputFile, &showConf( $config ) ); } 1;