Rev 45 | Blame | Last modification | View Log | RSS feed
#!/usr/bin/env perl
use warnings;
use strict;
# v1.1.0 20161022 RWR
# use library sysinfoconf.pm for loading, editing and displaying config
our $VERSION = '1.1.0';
# find our location and use it for searching for libraries
BEGIN {
use FindBin;
use File::Spec;
use lib File::Spec->catdir($FindBin::Bin);
}
use sysinfoconf; # a library of shared routines with install.pl
my $config;
sub findSendEmail {
my $currentLocation = shift;
my @possibles = (
'/usr/local/opt/sendEmail/sendEmail',
'/usr/local/opt/sendEmail/sendEmail.pl',
'/opt/sendEmail/sendEmail',
'/opt/sendEmail/sendEmail.pl'
);
return $currentLocation if ( $currentLocation && -x $currentLocation );
# well, we didn't find it, so look around some more
# we install it in /opt, so try there
foreach my $current ( @possibles ) {
return $current if -x $current;
}
if ( &yesno( "You are asking for sendEmail, but I don't see it on the system\nWould you like me to automatically download and install" ) ) {
my $path = `perl getSendEmail.pl`;
chomp $path;
return $path;
}
return '';
}
sub userConfirmation {
my $config = shift;
my $temp;
$$config{'clientName'} = &getAnswer( "Client Name ", ($$config{'clientName'}) );
$$config{'serialNumber'} = &getAnswer( "Serial Number ", ($$config{'serialNumber'}) );
$$config{'hostname'} = &getAnswer( "Host Name ", ($$config{'hostname'}) );
$temp = join( ",", @{ $$config{ 'moduleDirs' } } ) if $$config{ 'moduleDirs' };
$temp = &getAnswer( "Locations to search for modules (comma separated) ", ($temp) );
$$config{ 'moduleDirs' } = [ split( ',', $temp ) ];
$temp = join( ",", @{ $$config{ 'scriptDirs' } } );
$temp = &getAnswer( "Locations to search for scripts (comma separated) ", ($temp) );
$$config{ 'scriptDirs' } = [ split( ',', $temp ) ];
}
sub setUpTransport {
my ($priority, $transport, $fields, $type ) = @_;
$priority = getAnswer( 'Priority', $priority );
$$transport{'sendScript'} = $$fields{'sendScript'} unless $$transport{'sendScript'};
$$transport{'-name-'} = $type unless $$transport{'-name-'};
my $allKeys = $$fields{'keys'};
foreach my $key ( @$allKeys ) {
if ( $key eq 'sendEmailScriptLocation' && ! -e $$transport{$key} ) {
my $temp = &findSendEmail( $$transport{$key} );
$$transport{$key} = $temp if $temp;
}
$$transport{$key} = &getAnswer( "$key ", $$transport{$key} ? $$transport{$key} : '' );
}
return ( $priority, $transport );
}
sub showAllTransports {
foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
print '='x40 . "\n";
&showTransports( $priority, $$transports{ $priority } );
print '='x40 . "\n";
}
}
sub showTransports {
my ( $priority,$thisOne ) = @_;
print $$thisOne{'-name-'} . " has priority $priority\n";
foreach my $key ( sort keys %$thisOne ) {
next if $key =~ m/^-.*-$/;
print "$key = $$thisOne{$key}\n";
}
}
sub doTransports {
my ( $transports ) = @_;
foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
if ( &yesno( $$transports{$priority}{'-name-'} . " has a priority of $priority, edit it?") ) {
#print Dumper( $sendTypes{$$transports{$priority}{'-name-'}} );
#die;
my ( $newpriority,$temp ) = &setUpTransport( $priority, $$transports{$priority}, $sendTypes{$$transports{$priority}{'-name-'}} );
if ( $newpriority != $priority ) {
delete $$transports{$priority};
$priority = $newpriority;
}
$$transports{$priority} = $temp;
} # if
}
foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
print '='x40 . "\n";
&showTransports( $priority, $$transports{ $priority } );
print '='x40 . "\n";
}
while ( &yesno( "Would you like to add any other transport mechanisms?" ) ) {
my $newType = &getAnswer( 'Type of Transport? ', keys %sendTypes );
my ( $priority,$temp ) = &setUpTransport( 99, {}, $sendTypes{$newType}, $newType );
$$transports{$priority} = $temp;
}
foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
print '='x40 . "\n";
&showTransports( $priority, $$transports{ $priority } );
print '='x40 . "\n";
}
}
&processParameters( @ARGV );
$sysinfo3 = findConf( $sysinfo3 );
if ( -f $sysinfo3 && &yesno( 'I found an existing configuration, modify it ' ) ) {
print "Loading defaults from existing config $sysinfo3\n";
$config = makeConfig( ( $sysinfo3 ) );
my $content = &showConf( $config );
}
&userConfirmation( $config );
#use Data::Dumper;
#print Dumper( $config ); die;
&doTransports( $$config{'transports'} );
print "The following is the configuration I'll write out\n" . '-'x40 . "\n";
print &showConf( $config );
print '-'x40 . "\n";
print &writeConfig( $confDir, $confName, &showConf() ) if &yesno( "Write this configuration" );
print "sysinfo-client has been installed configured. You can return to\nthis screen at any time by running /opt/camp/sysinfo/config.pl\n";
1;