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