Subversion Repositories camp_sysinfo_client_3

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 rodolico 1
#!/usr/bin/env perl
2
 
16 rodolico 3
use warnings;
26 rodolico 4
use strict;
16 rodolico 5
 
45 rodolico 6
# v1.1.0 20161022 RWR
7
# use library sysinfoconf.pm for loading, editing and displaying config
20 rodolico 8
 
45 rodolico 9
our $VERSION = '1.1.0';
10
 
21 rodolico 11
# find our location and use it for searching for libraries
12
BEGIN {
13
   use FindBin;
14
   use File::Spec;
15
   use lib File::Spec->catdir($FindBin::Bin);
11 rodolico 16
}
17
 
21 rodolico 18
use sysinfoconf; # a library of shared routines with install.pl
16 rodolico 19
 
45 rodolico 20
my $config;
16 rodolico 21
 
12 rodolico 22
sub findSendEmail {
23
   my $currentLocation = shift;
24
   my @possibles = ( '/opt/sendEmail/sendEmail', '/opt/sendEmail/sendEmail.pl' );
25
   return $currentLocation if ( $currentLocation && -x $currentLocation );
26
   # well, we didn't find it, so look around some more
27
   # we install it in /opt, so try there
28
   foreach my $current ( @possibles ) {
29
      return $current if -x $current;
30
   }
31
   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" ) ) {
28 rodolico 32
      my $path = `perl getSendEmail.pl`;
12 rodolico 33
      chomp $path;
34
      return $path;
35
   }
36
   return '';
37
}
38
 
11 rodolico 39
sub userConfirmation {
45 rodolico 40
   my $config = shift;
11 rodolico 41
   my $temp;
42
 
45 rodolico 43
   $$config{'clientName'} = &getAnswer( "Client Name ", ($$config{'clientName'}) );
44
   $$config{'serialNumber'} = &getAnswer( "Serial Number ", ($$config{'serialNumber'}) );
45
   $$config{'hostname'} = &getAnswer( "Host Name ", ($$config{'hostname'}) );
11 rodolico 46
 
45 rodolico 47
   $temp = join( ",", @{ $$config{ 'moduleDirs' } } );
11 rodolico 48
   $temp = &getAnswer( "Locations to search for modules (comma separated) ", ($temp) );
45 rodolico 49
   $$config{ 'moduleDirs' } = [ split( ',', $temp ) ];
11 rodolico 50
 
45 rodolico 51
   $temp = join( ",", @{ $$config{ 'scriptDirs' } } );
11 rodolico 52
   $temp = &getAnswer( "Locations to search for scripts (comma separated) ", ($temp) );
45 rodolico 53
   $$config{ 'scriptDirs' } = [ split( ',', $temp ) ];
11 rodolico 54
 
55
}
56
 
16 rodolico 57
sub setUpTransport {
58
   my ($priority, $transport, $fields, $type ) = @_;
59
   $priority = getAnswer( 'Priority', $priority );
60
   $$transport{'sendScript'} = $$fields{'sendScript'} unless $$transport{'sendScript'};
61
   $$transport{'-name-'} = $type unless $$transport{'-name-'};
62
   my $allKeys = $$fields{'keys'};
63
   foreach my $key ( @$allKeys ) {
64
      if ( $key eq 'sendEmailScriptLocation' && ! -e $$transport{$key} ) {
28 rodolico 65
         my $temp = &findSendEmail( $$transport{$key} );
16 rodolico 66
         $$transport{$key} = $temp if $temp;
67
      }
68
      $$transport{$key} = &getAnswer( "$key ", $$transport{$key} ? $$transport{$key} : '' );
69
   }
70
   return ( $priority, $transport );
71
}
72
 
73
sub showAllTransports {
74
   foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
75
      print '='x40 . "\n";
76
      &showTransports( $priority, $$transports{ $priority } );
77
      print '='x40 . "\n";
78
   }
79
}   
80
 
81
sub showTransports {
82
   my ( $priority,$thisOne )  = @_;
83
   print $$thisOne{'-name-'} . " has priority $priority\n";
84
   foreach my $key ( sort keys %$thisOne ) {
85
      next if $key =~ m/^-.*-$/;
86
      print "$key = $$thisOne{$key}\n";
87
   }
88
}
89
 
90
sub doTransports {
91
   my ( $transports ) = @_;
92
 
93
   foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
94
      if ( &yesno( $$transports{$priority}{'-name-'} . " has a priority of $priority, edit it?") ) {
95
         #print Dumper( $sendTypes{$$transports{$priority}{'-name-'}} );
96
         #die;
97
         my ( $newpriority,$temp ) = &setUpTransport( $priority, $$transports{$priority}, $sendTypes{$$transports{$priority}{'-name-'}} );
98
         if ( $newpriority != $priority ) {
99
            delete $$transports{$priority};
100
            $priority = $newpriority;
101
         }
102
         $$transports{$priority} = $temp;
103
      } # if
104
   }
105
 
106
   foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
107
      print '='x40 . "\n";
108
      &showTransports( $priority, $$transports{ $priority } );
109
      print '='x40 . "\n";
110
   }
111
 
112
   while ( &yesno( "Would you like to add any other transport mechanisms?" ) ) {
28 rodolico 113
      my $newType = &getAnswer( 'Type of Transport? ', keys %sendTypes );
16 rodolico 114
      my ( $priority,$temp ) = &setUpTransport( 99, {}, $sendTypes{$newType}, $newType );
115
      $$transports{$priority} = $temp;
116
   }
117
 
118
   foreach my $priority ( sort { $a <=> $b } keys %$transports ) {
119
      print '='x40 . "\n";
120
      &showTransports( $priority, $$transports{ $priority } );
121
      print '='x40 . "\n";
122
   }
123
}
124
 
125
 
45 rodolico 126
&processParameters( @ARGV );
127
 
128
if ( -f $sysinfo3 && &yesno( 'I found an existing configuration, modify it ' ) ) {
129
   print "Loading defaults from existing config $sysinfo3\n";
130
   $config = makeConfig( ( $sysinfo3 )  );
131
   my $content = &showConf( $config );
11 rodolico 132
}
133
 
45 rodolico 134
&userConfirmation( $config );
20 rodolico 135
 
45 rodolico 136
#use Data::Dumper;
137
#print Dumper( $config ); die;
16 rodolico 138
 
45 rodolico 139
&doTransports( $$config{'transports'} );
11 rodolico 140
 
141
print "The following is the configuration I'll write out\n" . '-'x40 . "\n";
45 rodolico 142
print &showConf( $config );
11 rodolico 143
print '-'x40 . "\n";
21 rodolico 144
print &writeConfig( $confDir, $confName, &showConf() ) if &yesno( "Write this configuration" );
11 rodolico 145
 
12 rodolico 146
 
11 rodolico 147
print "sysinfo-client has been installed configured. You can return to\nthis screen at any time by running /opt/camp/sysinfo/config.pl\n";
148
 
149
1;