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