Subversion Repositories camp_sysinfo_client_3

Rev

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