Subversion Repositories camp_sysinfo_client_3

Rev

Rev 143 | Rev 161 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 143 Rev 144
Line 28... Line 28...
28
our $VERSION = '2.2.1';
28
our $VERSION = '2.2.1';
29
use warnings;
29
use warnings;
30
use strict;  
30
use strict;  
31
 
31
 
32
#use Data::Dumper;
32
#use Data::Dumper;
33
eval( 'use YAML::Tiny' );
-
 
34
#use YAML::Tiny;
33
use YAML::Tiny;
35
use File::Basename;
34
use File::Basename;
36
 
35
 
37
use Exporter;
36
use Exporter;
38
 
37
 
39
our @ISA = qw( Exporter );
38
our @ISA = qw( Exporter );
40
our @EXPORT = qw( $clientName $serialNumber $hostname @moduleDirs @scriptDirs 
39
our @EXPORT = qw( $clientName $serialNumber $hostname @moduleDirs @scriptDirs 
41
                  $transports $sysinfo3 %sendTypes $binDir $moduleDir
40
                  $transports $sysinfo3 %sendTypes $binDir $moduleDir
42
                  $scriptDir $confDir $binName $confName
41
                  $scriptDir $confDir $binName $confName
43
                  &showConf &transportsToConfig &getAnswer &yesno  
42
                  &showConf &transportsToConfig &getAnswer &yesno  
44
                  &writeConfig &processParameters $TESTING &checkDirectoryExists
43
                  &writeConfig &processParameters $TESTING
45
                  &runCommand &setDryRun &enableModules &makeConfig &findConf &timeStamp
44
                  &setDryRun &enableModules &makeConfig &findConf &timeStamp
46
                );
45
                );
47
 
46
 
48
our $TESTING = 0;
47
our $TESTING = 0;
49
our $dryRun;
48
our $dryRun;
50
our $clientName = '';
49
our $clientName = '';
Line 284... Line 283...
284
   $default = 'yes' unless $default;
283
   $default = 'yes' unless $default;
285
   my $answer = &getAnswer( $prompt, $default eq 'yes' ? ('yes','no' ) : ('no', 'yes') );
284
   my $answer = &getAnswer( $prompt, $default eq 'yes' ? ('yes','no' ) : ('no', 'yes') );
286
   return lc( substr( $answer, 0, 1 ) ) eq 'y';
285
   return lc( substr( $answer, 0, 1 ) ) eq 'y';
287
}
286
}
288
 
287
 
289
# runs a system command. Also, if in testing mode, simply shows what
-
 
290
# would have been done.
-
 
291
sub runCommand {
-
 
292
   while ( my $command = shift ) {
-
 
293
      if ( $dryRun ) {
-
 
294
         print "$command\n";
-
 
295
      } else {
-
 
296
         `$command`;
-
 
297
      }
-
 
298
   }
-
 
299
   return 1;
-
 
300
} # runCommand
-
 
301
 
-
 
302
# checks if a directory exists and, if not, creates it
-
 
303
my %directories; # holds list of directories already created so no need to do an I/O
-
 
304
 
-
 
305
sub checkDirectoryExists {
-
 
306
   my ( $filename,$mod,$owner ) = @_;
-
 
307
   $mod = "0700" unless $mod;
-
 
308
   $owner = "root:root" unless $owner;
-
 
309
   print "Checking Directory for $filename with $mod and $owner\n" if $TESTING > 2;
-
 
310
   my ($fn, $dirname) = fileparse( $filename );
-
 
311
   print "\tParsing out $dirname and $filename\n" if $TESTING > 2;
-
 
312
   return '' if exists $directories{$dirname};
-
 
313
   if ( -d $dirname ) {
-
 
314
      $directories{$dirname} = 1;
-
 
315
      return '';
-
 
316
   }
-
 
317
   if ( &runCommand( "mkdir -p $dirname", "chmod $mod $dirname", "chown $owner $dirname" ) ) {
-
 
318
      $directories{$dirname} = 1;
-
 
319
   }
-
 
320
   return '';   
-
 
321
}
-
 
322
 
-
 
323
sub writeConfig {
288
sub writeConfig {
324
   use File::Temp qw / tempfile /;
289
   use File::Temp qw / tempfile /;
325
   my ( $filename,$content ) = @_;
290
   my ( $filename,$content ) = @_;
326
   if ( $filename ) { # they sent us a filename
291
   if ( $filename ) { # they sent us a filename
327
      my $path;
292
      my $path;