| Line 1... |
Line 1... |
| 1 |
#!/usr/bin/env perl
|
1 |
#!/usr/bin/env perl
|
| 2 |
|
2 |
|
| 3 |
my $seedFile = 'sysinfo-client.seed';
|
3 |
my $seedFile = 'sysinfo-client.seed';
|
| 4 |
my $sysinfo2 = '/etc/sysinfo/sysinfo.conf';
|
4 |
my $sysinfo2 = '/etc/sysinfo/sysinfo.conf';
|
| 5 |
my $sysinfo3 = '/etc/camp/sysinfo-client.conf';
|
5 |
my $sysinfo3 = '/etc/camp/sysinfo-client.conf';
|
| - |
|
6 |
my $configPath = '/etc/camp';
|
| - |
|
7 |
my $configFile = 'sysinfo-client.conf';
|
| 6 |
|
8 |
|
| 7 |
my $clientName = '';
|
9 |
my $clientName = '';
|
| 8 |
my $serialNumber = '';
|
10 |
my $serialNumber = '';
|
| 9 |
my $hostname;
|
11 |
my $hostname;
|
| 10 |
my @moduleDirs = ( '/opt/camp/sysinfo/modules', '/etc/camp/modules' );
|
12 |
my @moduleDirs = ( '/opt/camp/sysinfo/modules', '/etc/camp/modules' );
|
| Line 20... |
Line 22... |
| 20 |
$conf .= "\$serialNumber = '" . $serialNumber . "';\n";
|
22 |
$conf .= "\$serialNumber = '" . $serialNumber . "';\n";
|
| 21 |
$conf .= "\$hostname = '" . $hostname . "';\n";
|
23 |
$conf .= "\$hostname = '" . $hostname . "';\n";
|
| 22 |
$conf .= "\@moduleDirs = ('" . join( "','", @moduleDirs ). "');\n";
|
24 |
$conf .= "\@moduleDirs = ('" . join( "','", @moduleDirs ). "');\n";
|
| 23 |
$conf .= "\@scriptDirs = ('" . join( "','", @scriptDirs ). "');\n";
|
25 |
$conf .= "\@scriptDirs = ('" . join( "','", @scriptDirs ). "');\n";
|
| 24 |
foreach my $key ( keys %$iSendReports ) {
|
26 |
foreach my $key ( keys %$iSendReports ) {
|
| 25 |
$conf .= "\$\$iSendReports{'$key'} = \"" . $$iSendReports{$key} . "\";\n";
|
27 |
$conf .= "\$\$iSendReports{'$key'} = '" . $$iSendReports{$key} . "';\n";
|
| 26 |
}
|
28 |
}
|
| 27 |
return $conf;
|
29 |
return $conf;
|
| 28 |
}
|
30 |
}
|
| 29 |
|
31 |
|
| 30 |
# prompt the user for a response, then allow them to enter it
|
32 |
# prompt the user for a response, then allow them to enter it
|
| Line 48... |
Line 50... |
| 48 |
}
|
50 |
}
|
| 49 |
|
51 |
|
| 50 |
sub yesno {
|
52 |
sub yesno {
|
| 51 |
my $prompt = shift;
|
53 |
my $prompt = shift;
|
| 52 |
my $answer = &getAnswer( $prompt, ('yes','no' ) );
|
54 |
my $answer = &getAnswer( $prompt, ('yes','no' ) );
|
| 53 |
return lc( substr( $answer, 1, 1 ) ) ne 'y';
|
55 |
return lc( substr( $answer, 0, 1 ) ) eq 'y';
|
| - |
|
56 |
}
|
| - |
|
57 |
|
| - |
|
58 |
sub findSendEmail {
|
| - |
|
59 |
my $currentLocation = shift;
|
| - |
|
60 |
my @possibles = ( '/opt/sendEmail/sendEmail', '/opt/sendEmail/sendEmail.pl' );
|
| - |
|
61 |
return $currentLocation if ( $currentLocation && -x $currentLocation );
|
| - |
|
62 |
# well, we didn't find it, so look around some more
|
| - |
|
63 |
# we install it in /opt, so try there
|
| - |
|
64 |
foreach my $current ( @possibles ) {
|
| - |
|
65 |
return $current if -x $current;
|
| - |
|
66 |
}
|
| - |
|
67 |
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" ) ) {
|
| - |
|
68 |
$path = `perl getSendEmail.pl`;
|
| - |
|
69 |
chomp $path;
|
| - |
|
70 |
return $path;
|
| - |
|
71 |
}
|
| - |
|
72 |
return '';
|
| 54 |
}
|
73 |
}
|
| 55 |
|
74 |
|
| 56 |
sub userConfirmation {
|
75 |
sub userConfirmation {
|
| 57 |
my $temp;
|
76 |
my $temp;
|
| 58 |
|
77 |
|
| Line 70... |
Line 89... |
| 70 |
|
89 |
|
| 71 |
$temp = &getAnswer( "How do you want to send the reports ", ('sendEmailScript', 'http', 'sendmail' ) );
|
90 |
$temp = &getAnswer( "How do you want to send the reports ", ('sendEmailScript', 'http', 'sendmail' ) );
|
| 72 |
|
91 |
|
| 73 |
if ( $temp eq 'sendEmailScript' ) {
|
92 |
if ( $temp eq 'sendEmailScript' ) {
|
| 74 |
$$iSendReports{'sendScript'} = 'sendEmailScript';
|
93 |
$$iSendReports{'sendScript'} = 'sendEmailScript';
|
| - |
|
94 |
$$iSendReports{'sendEmailScriptLocation'} = &findSendEmail( $$iSendReports{'sendEmailScriptLocation'} );
|
| - |
|
95 |
|
| 75 |
# get rid of http keys
|
96 |
# get rid of http keys
|
| 76 |
delete @{$iSendReports} {@sendHTTPKeys};
|
97 |
delete @{$iSendReports} {@sendHTTPKeys};
|
| 77 |
for $key ( @sendEmailScriptKeys ) {
|
98 |
for $key ( @sendEmailScriptKeys ) {
|
| 78 |
$$iSendReports{$key} = &getAnswer( "For key $key", ( $$iSendReports{$key} ) );
|
99 |
$$iSendReports{$key} = &getAnswer( "For key $key", ( $$iSendReports{$key} ) );
|
| 79 |
}
|
100 |
}
|
| Line 143... |
Line 164... |
| 143 |
`ln -s /opt/camp/sysinfo/sysinfo-client /etc/cron.daily/sysinfo.cron`
|
164 |
`ln -s /opt/camp/sysinfo/sysinfo-client /etc/cron.daily/sysinfo.cron`
|
| 144 |
if &yesno( 'Add link to cron.daily' );
|
165 |
if &yesno( 'Add link to cron.daily' );
|
| 145 |
if ( `dpkg --get-selections | grep sysinfo-client | grep install`
|
166 |
if ( `dpkg --get-selections | grep sysinfo-client | grep install`
|
| 146 |
&& &yesno ('It looks like sysinfo version 2 is installed via apt, should I remove it' ) ) {
|
167 |
&& &yesno ('It looks like sysinfo version 2 is installed via apt, should I remove it' ) ) {
|
| 147 |
if ( &yesno( 'Back up old configuration? ') ) {
|
168 |
if ( &yesno( 'Back up old configuration? ') ) {
|
| 148 |
`tar -czvf /root/sysinfo.2.config.tgz /etc/sysinfo`
|
169 |
`tar -czvf /root/sysinfo.2.config.tgz /etc/sysinfo`;
|
| 149 |
print "Old configuration copied to /root/sysinfo.2.config.tgz\n";
|
170 |
print "Old configuration copied to /root/sysinfo.2.config.tgz\n";
|
| 150 |
}
|
171 |
}
|
| 151 |
`apt-get -y --purge remove sysinfo-client`;
|
172 |
`apt-get -y --purge remove sysinfo-client`;
|
| 152 |
print "There may be some unused packages now. You can remove them with\napt-get autoremove\n\n";
|
173 |
print "There may be some unused packages now. You can remove them with\napt-get autoremove\n\n";
|
| 153 |
}
|
174 |
}
|
| Line 161... |
Line 182... |
| 161 |
`chmod 0700 $MODULES_DIR/$module`;
|
182 |
`chmod 0700 $MODULES_DIR/$module`;
|
| 162 |
}
|
183 |
}
|
| 163 |
print "All debian specific modules have been enabled\n";
|
184 |
print "All debian specific modules have been enabled\n";
|
| 164 |
}
|
185 |
}
|
| 165 |
|
186 |
|
| - |
|
187 |
sub writeConfig {
|
| - |
|
188 |
my ($path,$filename,$content) = @_;
|
| - |
|
189 |
my $return;
|
| - |
|
190 |
`mkdir -p $path` unless -d $path;
|
| - |
|
191 |
$filename = $path . '/' . $filename;
|
| - |
|
192 |
if ( -e $filename ) {
|
| - |
|
193 |
`cp $filename $filename.bak` if ( -e $filename );
|
| - |
|
194 |
$return .= "Old config copied to $filename.bak\n";
|
| - |
|
195 |
}
|
| - |
|
196 |
open CONF,">$filename" or die "Could not write to $filename: $!\n";
|
| - |
|
197 |
print CONF $content;
|
| - |
|
198 |
close CONF;
|
| - |
|
199 |
$return .= "Configuration successfully written to $filename\n";
|
| - |
|
200 |
return $return;
|
| - |
|
201 |
}
|
| - |
|
202 |
|
| 166 |
# See if existing configuration. If so, offer to load it
|
203 |
# See if existing configuration. If so, offer to load it
|
| 167 |
if ( -f $sysinfo3 && &yesno( 'I found an existing configuration, modify it ' ) ) {
|
204 |
if ( -f $sysinfo3 && &yesno( 'I found an existing configuration, modify it ' ) ) {
|
| 168 |
print "Loading defaults from existing config $sysinfo3\n";
|
205 |
print "Loading defaults from existing config $sysinfo3\n";
|
| 169 |
my $client_name;
|
206 |
my $client_name;
|
| 170 |
open SEED, "<$sysinfo3" or die "Could not open $sysinfo3: $!\n";
|
207 |
open SEED, "<$sysinfo3" or die "Could not open $sysinfo3: $!\n";
|
| Line 199... |
Line 236... |
| 199 |
&userConfirmation();
|
236 |
&userConfirmation();
|
| 200 |
|
237 |
|
| 201 |
print "The following is the configuration I'll write out\n" . '-'x40 . "\n";
|
238 |
print "The following is the configuration I'll write out\n" . '-'x40 . "\n";
|
| 202 |
print &showConf( );
|
239 |
print &showConf( );
|
| 203 |
print '-'x40 . "\n";
|
240 |
print '-'x40 . "\n";
|
| 204 |
print "Ok, I'll write it\n" if &yesno( "Write this configuration" );
|
241 |
print &writeConfig( $configPath, $configFile, &showConf() ) if &yesno( "Write this configuration" );
|
| - |
|
242 |
|
| 205 |
|
243 |
|
| 206 |
my $os = &getOperatingSystem();
|
244 |
my $os = &getOperatingSystem();
|
| 207 |
if ( $os && &yesno( "I recognize this system, may I automatically set up a few things" ) ) {
|
245 |
if ( $os && &yesno( "I recognize this system, may I automatically set up a few things" ) ) {
|
| 208 |
&ipFire() if $os = 'ipfire';
|
246 |
&ipFire() if $os eq 'ipfire';
|
| 209 |
&debian() if $os = 'debian';
|
247 |
&debian() if $os eq 'debian';
|
| 210 |
}
|
248 |
}
|
| 211 |
|
249 |
|
| 212 |
print "sysinfo-client has been installed configured. You can return to\nthis screen at any time by running /opt/camp/sysinfo/config.pl\n";
|
250 |
print "sysinfo-client has been installed configured. You can return to\nthis screen at any time by running /opt/camp/sysinfo/config.pl\n";
|
| 213 |
|
251 |
|
| 214 |
1;
|
252 |
1;
|