Subversion Repositories camp_sysinfo_client_3

Rev

Rev 42 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 43
Line 12... Line 12...
12
#
12
#
13
# Version 1.1.7 20161010 RWR
13
# Version 1.1.7 20161010 RWR
14
# Added ability to validate required libraries are installed
14
# Added ability to validate required libraries are installed
15
#
15
#
16
 
16
 
17
our $VERSION = '1.1.6';
17
our $VERSION = '1.1.7';
18
 
18
 
19
# find our location and use it for searching for libraries
19
# find our location and use it for searching for libraries
20
BEGIN {
20
BEGIN {
21
   use FindBin;
21
   use FindBin;
22
   use File::Spec;
22
   use File::Spec;
Line 145... Line 145...
145
                  'ipfire' => {
145
                  'ipfire' => {
146
                     'bindir' => '/opt/camp/sysinfo-client',
146
                     'bindir' => '/opt/camp/sysinfo-client',
147
                     'confdir' => '/etc/camp/sysinfo-client',
147
                     'confdir' => '/etc/camp/sysinfo-client',
148
                     'crontab' => 'ln -s <bindir>sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
148
                     'crontab' => 'ln -s <bindir>sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
149
                     'modules' => '((ipfire)|(unix))',
149
                     'modules' => '((ipfire)|(unix))',
150
                  }
150
                  },
-
 
151
                  'freebsd' => {
-
 
152
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
-
 
153
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
-
 
154
                     'crontab' => 'ln -s <bindir>sysinfo-client /etc/periodic/daily/sysinfo-client',
-
 
155
                     'modules' => '((bsd)|(unix))',
151
                  );
156
                  },
-
 
157
                  
-
 
158
                );
152
 
159
 
153
# list of libraries used by the system. We will offer to install them if
160
# list of libraries used by the system. We will offer to install them if
154
# we know how. NOTE: I have chosen to put the full installation command
161
# we know how. NOTE: I have chosen to put the full installation command
155
# for each library. This allows us to use the package selector OR a different
162
# for each library. This allows us to use the package selector OR a different
156
# piece of code on a per-library basis, but results in something like
163
# piece of code on a per-library basis, but results in something like
Line 160... Line 167...
160
#      apt-get -y install libwww-perl perl-modules
167
#      apt-get -y install libwww-perl perl-modules
161
# flexibility vs efficiency in this case.
168
# flexibility vs efficiency in this case.
162
my %libraries = ( 
169
my %libraries = ( 
163
                  'File::Basename' => { 'debian' => 'apt-get -y install perl-modules' },
170
                  'File::Basename' => { 'debian' => 'apt-get -y install perl-modules' },
164
                  'Exporter' => { 'debian' => 'apt-get -y install perl-base' },
171
                  'Exporter' => { 'debian' => 'apt-get -y install perl-base' },
165
                  'LWP' => { 'debian' => 'apt-get -y install libwww-perl' },
172
                  'LWP' => { 'debian' => 'apt-get -y install libwww-perl',
-
 
173
                             'freebsd' => 'pkg install p5-libwww' },
166
                );
174
                );
167
 
175
 
-
 
176
# utilities md5sum
-
 
177
# freebsd isomd5sum
-
 
178
 
168
# validates the libraries needed exist
179
# validates the libraries needed exist
169
# simply eval's each library. If it doesn't exist, creates a list of
180
# simply eval's each library. If it doesn't exist, creates a list of
170
# commands to be executed to install it, and displays missing libraries
181
# commands to be executed to install it, and displays missing libraries
171
# offering to install them if possible.
182
# offering to install them if possible.
172
sub validateLibraries {
183
sub validateLibraries {
Line 368... Line 379...
368
            );
379
            );
369
   } # foreach file
380
   } # foreach file
370
   return 1;
381
   return 1;
371
}
382
}
372
 
383
 
-
 
384
sub makeConfig {
-
 
385
   my @configFileNames = @_;
-
 
386
   my %config;
-
 
387
   my $clientName;
-
 
388
   my $serialNumber;
-
 
389
   my $hostname;
-
 
390
   my @moduleDirs;
-
 
391
   my @scriptDirs;
-
 
392
   my $transports = {};
-
 
393
 
-
 
394
   foreach my $config ( @configFileNames ) {
-
 
395
      open CONF,"<$config" or die "could not open $config: $!\n";
-
 
396
      my $contents = join( '', <CONF> );
-
 
397
      close CONF;
-
 
398
      # now, eval the information we just read.
-
 
399
      # NOTE: we must turn off strict while doing this, and we die if something breaks.
-
 
400
      no strict "vars"; eval( $contents ); use strict "vars"; die "Error during eval: $@\n" if $@;
-
 
401
   }
-
 
402
 
-
 
403
   $config{'clientName'} = $clientName;
-
 
404
   $config{'serialNumber'} = $serialNumber;
-
 
405
   $config{'hostname'} = $hostname;
-
 
406
   $config{'moduleDirs'} = [ @moduleDirs ];
-
 
407
   $config{'scriptDirs'} = [ @scriptDirs ];
-
 
408
   $config{'transports'} = $transports;
-
 
409
   return \%config;
-
 
410
}
-
 
411
 
373
sub postInstall {
412
sub postInstall {
374
   my $install = shift;
413
   my $install = shift;
375
 
414
 
376
   # set up crontab, if necessary
415
   # set up crontab, if necessary
377
   &runCommand( $$install{'crontab'} ) if defined ( $$install{'crontab'} );
416
   &runCommand( $$install{'crontab'} ) if defined ( $$install{'crontab'} );
378
   
417
   
379
   # seed configuration, if needed
418
   # seed configuration, if needed
380
   if ( $$install{'build config'} ) {
419
   if ( $$install{'build config'} ) {
381
      my %config;
420
      my $config;
-
 
421
      my @fileList;
382
      my $seedFile = $$install{'configuration'}{'configuration seed file'};
422
      my $seedFile = $$install{'configuration'}{'configuration seed file'};
383
      my $confFile = $$install{'configuration'}{'configuration file'};
423
      my $confFile = $$install{'configuration'}{'configuration file'};
384
      my $content;
-
 
385
 
-
 
386
      my $clientName;
-
 
387
      my $serialNumber;
-
 
388
      my $hostname;
-
 
389
      my @moduleDirs;
-
 
390
      my @scriptDirs;
-
 
391
      my $transports = {};
-
 
392
 
424
 
393
      
-
 
394
      if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
425
      if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
395
         print "Loading seed file $seedFile\n";
426
         push @fileList, $seedFile;
396
         open SEED, "<$seedFile" or die "Could not open $seedFile: $!\n";
-
 
397
         $content = join( '', <SEED> );
-
 
398
         close SEED;
-
 
399
         # now, eval the information we just read.
-
 
400
         # NOTE: we must turn off strict while doing this, and we die if something breaks.
-
 
401
         no strict "vars"; eval( $content ); use strict "vars"; die "Error during eval: $@\n" if $@;
-
 
402
      } # if preload seed file
427
      } # if preload seed file
403
 
428
 
404
      if (  -f $confFile  ) {
429
      if (  -f $confFile  ) {
405
         print "Loading configuration file $confFile\n";
430
         push @fileList, $confFile;
406
         open SEED, "<$confFile" or die "Could not open $confFile: $!\n";
-
 
407
         $content = join( '', <SEED> );
-
 
408
         close SEED;
-
 
409
         # now, eval the information we just read.
-
 
410
         # NOTE: we must turn off strict while doing this, and we die if something breaks.
-
 
411
         no strict "vars"; eval( $content ); use strict "vars"; die "Error during eval: $@\n" if $@;
-
 
412
      }
431
      }
413
      $config{'clientName'} = $clientName;
-
 
414
      $config{'serialNumber'} = $serialNumber;
-
 
415
      $config{'hostname'} = $hostname;
-
 
416
      $config{'moduleDirs'} = [ @moduleDirs ];
432
      $config = makeConfig( @fileList );
417
      $config{'scriptDirs'} = [ @scriptDirs ];
-
 
418
      $config{'transports'} = $transports;
-
 
419
 
-
 
420
      $content = &showConf( \%config );
433
      my $content = &showConf( $config );
421
      print $content;
434
      print $content;
422
      print &writeConfig( $$install{'configuration'}{'configuration file'} , $content ) . "\n"
435
      print &writeConfig( $$install{'configuration'}{'configuration file'} , $content ) . "\n"
423
         if ( &yesno( "Write the above configuration to $$install{'configuration'}{'configuration file'}?" ) );
436
         if ( &yesno( "Write the above configuration to $$install{'configuration'}{'configuration file'}?" ) );
424
   } # if we are building/merging configuration
437
   } # if we are building/merging configuration
425
   
438
   
Line 459... Line 472...
459
# figure out if we know our operating system
472
# figure out if we know our operating system
460
$os = &getOS( \%install, \%operatingSystems, $os );
473
$os = &getOS( \%install, \%operatingSystems, $os );
461
 
474
 
462
&validateLibraries( \%libraries, $os );
475
&validateLibraries( \%libraries, $os );
463
 
476
 
464
die;
-
 
465
 
-
 
466
$installType = &getInstallActions( \%install );
477
$installType = &getInstallActions( \%install );
467
 
478
 
468
# based on the defaults, flesh out the install hash
479
# based on the defaults, flesh out the install hash
469
$status = &populateSourceDir( \%install, $sourceDir );
480
$status = &populateSourceDir( \%install, $sourceDir );
470
 
481