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