Subversion Repositories camp_sysinfo_client_3

Rev

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

Rev 92 Rev 94
Line 12... Line 12...
12
# Version 1.1.7 20161010 RWR
12
# Version 1.1.7 20161010 RWR
13
# Added ability to validate required libraries are installed
13
# Added ability to validate required libraries are installed
14
#
14
#
15
# version 1.2 20170327 RWR
15
# version 1.2 20170327 RWR
16
# did some major modifications to correctly work on BSD systems also
16
# did some major modifications to correctly work on BSD systems also
-
 
17
#
-
 
18
# version 2.0 20190330 RWR
-
 
19
# changed it so all configs are YAML
17
 
20
 
18
our $VERSION = '1.2';
21
our $VERSION = '2.0';
19
 
22
 
20
# find our location and use it for searching for libraries
23
# find our location and use it for searching for libraries
21
BEGIN {
24
BEGIN {
22
   use FindBin;
25
   use FindBin;
23
   use File::Spec;
26
   use File::Spec;
24
   use lib File::Spec->catdir($FindBin::Bin);
27
   use lib File::Spec->catdir($FindBin::Bin);
25
}
28
}
26
 
29
 
27
use sysinfoconf;
30
use sysinfoconf;
-
 
31
#use YAML::Tiny; # moved to after the call to check on libraries
28
use YAML::Tiny;
32
use Data::Dumper;
29
use File::Basename;
33
use File::Basename;
30
use Getopt::Long;
34
use Getopt::Long;
31
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
35
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
32
 
36
 
33
# $verbose can have the following values
37
# $verbose can have the following values
Line 52... Line 56...
52
                 'default group' => 'root',
56
                 'default group' => 'root',
53
                 'default owner' => 'root',
57
                 'default owner' => 'root',
54
                 'default permission' => '0700',
58
                 'default permission' => '0700',
55
                 'configuration' => {
59
                 'configuration' => {
56
                          'configurator' => '<bindir>/configure.pl',
60
                          'configurator' => '<bindir>/configure.pl',
57
                          'configuration file' => '<confdir>/sysinfo-client.conf',
61
                          'configuration file' => '<confdir>/sysinfo-client.yaml',
58
                          'configuration seed file' => 'sysinfo-client.seed',
62
                          'configuration seed file' => 'sysinfo-client.seed.yaml',
-
 
63
                          'old configuration file' => '<confdir>/sysinfo-client.conf',
59
                          'permission' => '700',
64
                          'permission' => '700',
60
                          'owner'      => '<default owner>',
65
                          'owner'      => '<default owner>',
61
                          'target'     => '<confdir>'
66
                          'target'     => '<confdir>'
62
                            },
67
                            },
63
                 'files' => {
68
                 'files' => {
Line 83... Line 88...
83
                                 'type' => 'file',
88
                                 'type' => 'file',
84
                                 'permission' => '600', 
89
                                 'permission' => '600', 
85
                                 'owner' => '<default owner>:<default group>', 
90
                                 'owner' => '<default owner>:<default group>', 
86
                                 'target' =>  '<bindir>'
91
                                 'target' =>  '<bindir>'
87
                              },
92
                              },
88
                           'sysinfo-client.conf.template' => { 
93
                           'sysinfo-client.conf.template.yaml' => { 
89
                                 'type' => 'file',
94
                                 'type' => 'file',
90
                                 'permission' => '600', 
95
                                 'permission' => '600', 
91
                                 'owner' => '<default owner>:<default group>', 
96
                                 'owner' => '<default owner>:<default group>', 
92
                                 'target' =>  '<bindir>' 
97
                                 'target' =>  '<bindir>' 
93
                              },
98
                              },
Line 107... Line 112...
107
                                 'type' => 'file',
112
                                 'type' => 'file',
108
                                 'permission' => '600', 
113
                                 'permission' => '600', 
109
                                 'owner' => '<default owner>:<default group>', 
114
                                 'owner' => '<default owner>:<default group>', 
110
                                 'target' =>  '<bindir>' 
115
                                 'target' =>  '<bindir>' 
111
                              },
116
                              },
112
                           'sysinfo-client.seed.example' => { 
117
                           'sysinfo-client.seed.example.yaml' => { 
113
                                 'type' => 'file',
118
                                 'type' => 'file',
114
                                 'permission' => '600', 
119
                                 'permission' => '600', 
115
                                 'owner' => '<default owner>:<default group>', 
120
                                 'owner' => '<default owner>:<default group>', 
116
                                 'target' =>  '<bindir>' 
121
                                 'target' =>  '<bindir>' 
117
                              },
122
                              },
Line 161... Line 166...
161
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
166
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
162
                     'modules' => '((bsd)|(unix)|(all))',
167
                     'modules' => '((bsd)|(unix)|(all))',
163
                    'default group' => 'wheel',
168
                    'default group' => 'wheel',
164
                    'default owner' => 'root',
169
                    'default owner' => 'root',
165
                  },
170
                  },
-
 
171
                  'opnsense' => {
-
 
172
                     'fileexists' => '/conf/config.xml',
-
 
173
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
-
 
174
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
-
 
175
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
-
 
176
                     'modules' => '((bsd)|(unix)|(all))',
-
 
177
                    'default group' => 'wheel',
-
 
178
                    'default owner' => 'root',
-
 
179
                 },
166
                  
180
                  
167
                );
181
                );
168
 
182
 
169
my %configuration;
183
my %configuration;
170
 
184
 
Line 182... Line 196...
182
                  'Exporter' => { 'debian' => 'apt-get -y install perl-base' },
196
                  'Exporter' => { 'debian' => 'apt-get -y install perl-base' },
183
                  'LWP' => { 
197
                  'LWP' => { 
184
                             'debian' => 'apt-get -y install libwww-perl',
198
                             'debian' => 'apt-get -y install libwww-perl',
185
                             'freebsd' => 'pkg install -y p5-libwww'
199
                             'freebsd' => 'pkg install -y p5-libwww'
186
                           },
200
                           },
-
 
201
                  'YAML::Tiny' => {
-
 
202
                              'debian' => 'apt-get -y install libyaml-tiny-perl',
-
 
203
                              'freebsd' => 'installYAML.pl'
-
 
204
                           },
187
                );
205
                );
188
 
206
 
189
# utilities md5sum
207
# utilities md5sum
190
# freebsd isomd5sum
208
# freebsd isomd5sum
191
 
209
 
Line 218... Line 236...
218
                            join( ' ', @missingLibs ) . 
236
                            join( ' ', @missingLibs ) . 
219
                            "\nand I don't know how to do this. Abort?" );
237
                            "\nand I don't know how to do this. Abort?" );
220
      }
238
      }
221
   } # if
239
   } # if
222
} # validateLibraries
240
} # validateLibraries
223
                  
-
 
224
 
241
 
-
 
242
# checks various flags to 
-
 
243
 
-
 
244
sub determineOS {
225
# attempt to locate the operating system.
245
   my $operatingSystems = shift;
-
 
246
   my $osType;
226
# if found, will set some defaults for it.
247
   # first, look through our entries for fileexists
227
sub getOS {
248
   unless ( $os ) {
228
   my ( $install, $operatingSystems, $os ) = @_;
249
      foreach $osType ( keys %operatingSystems ) {
-
 
250
         next unless defined $operatingSystems->{$osType}->{'fileexists'};
229
   if ( ! $os ) { # we don't know, so we must try to figure it out
251
         if (  -e $operatingSystems->{$osType}->{'fileexists'} ) {
-
 
252
            return $osType;
-
 
253
         } # if
-
 
254
      } # foreach
-
 
255
   } # unless
-
 
256
   # next, look for uname and see if that gives us a clue
-
 
257
   unless ( $os ) {
230
      my $osString = `uname -a`;
258
      my $osString = `uname -a`;
231
      foreach my $osType ( keys %$operatingSystems ) {
259
      foreach $osType ( keys %$operatingSystems ) {
-
 
260
         next unless defined $operatingSystems->{$osType}->{'regex'};
232
         print "Checking if OS is $osType in $osString\n" if $verbose > 2;
261
         print "Checking if OS is $osType in $osString\n" if $verbose > 2;
233
         next unless $osString =~ m/$$operatingSystems{$osType}{'regex'}/i;
262
         if ( $osString =~ m/$$operatingSystems{$osType}{'regex'}/i ) {
234
         print "Yes, it is $osType\n" if $verbose > 2;
263
            print "Yes, it is $osType\n" if $verbose > 2;
235
         # We found the OS, set up some defaults
264
            return $osType;
236
         $os = $osType;
265
         }
237
      } # foreach
266
      } # foreach
-
 
267
   } # unless
-
 
268
   return '';
238
   }
269
}
-
 
270
 
-
 
271
# attempt to locate the operating system.
-
 
272
# if found, will set some defaults for it.
-
 
273
sub setUpOperatingSystemSpecific {
-
 
274
   my ( $install, $operatingSystems, $os ) = @_;
-
 
275
   $os = &determineOS( $operatingSystems ) unless $os;
239
   if ( $os ) {
276
   if ( $os ) {
-
 
277
      # We found the OS, set up some defaults
240
      $$install{'os'} = $os;
278
      $$install{'os'} = $os;
241
      print "Setting keys for operating system\n" if $verbose > 2;
279
      print "Setting keys for operating system\n" if $verbose > 2;
242
      foreach my $key ( keys %{$$operatingSystems{ $os }} ) {
280
      foreach my $key ( keys %{$$operatingSystems{ $os }} ) {
243
         $$install{$key} = $operatingSystems{ $os }{$key};
281
         $$install{$key} = $operatingSystems{ $os }{$key};
244
      } # if it is a known OS
282
      } # if it is a known OS
Line 405... Line 443...
405
   
443
   
406
   # seed configuration, if needed
444
   # seed configuration, if needed
407
   if ( $$install{'build config'} ) {
445
   if ( $$install{'build config'} ) {
408
      my $config;
446
      my $config;
409
      my @fileList;
447
      my @fileList;
410
      my $seedFile = $$install{'configuration'}{'configuration seed file'};
-
 
411
      my $confFile = $$install{'configuration'}{'configuration file'};
-
 
412
 
448
 
-
 
449
      # the order is important here as, if multiple files exist, latter ones can
-
 
450
      # overwrite values in the previous. We do a push so the first value pushed
-
 
451
      # is processed last, ie has higher priority.
-
 
452
      push @fileList, $install->{'configuration'}->{'old configuration file'};
-
 
453
      push @fileList, $install->{'configuration'}->{'configuration file'};
-
 
454
 
-
 
455
      my $seedFile = $install->{'configuration'}->{'configuration seed file'};
413
      if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
456
      if ( -e $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
414
         push @fileList, $seedFile;
457
         push @fileList, $seedFile;
415
      } # if preload seed file
458
      } # if preload seed file
416
 
459
 
417
      if (  -f $confFile  ) {
-
 
418
         push @fileList, $confFile;
-
 
419
      }
-
 
420
      $config = &makeConfig( @fileList );
460
      $config = &makeConfig( @fileList );
421
      # if ScriptDirs and moduleDirs not populated, do so from our configuration
461
      # if ScriptDirs and moduleDirs not populated, do so from our configuration
422
      if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
462
      if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
423
#         my @temp = ( $$install{'files'}{'scripts'}{'target'} );
463
#         my @temp = ( $$install{'files'}{'scripts'}{'target'} );
424
#         $$config{'scriptDirs'} = \@temp;
464
#         $$config{'scriptDirs'} = \@temp;
Line 467... Line 507...
467
                  
507
                  
468
if ( $help ) { &help() ; exit; }
508
if ( $help ) { &help() ; exit; }
469
if ( $version ) { print "$0 version $VERSION\n"; exit; }
509
if ( $version ) { print "$0 version $VERSION\n"; exit; }
470
&setDryRun( $dryRun ); # tell the library whether this is a dry run or not
510
&setDryRun( $dryRun ); # tell the library whether this is a dry run or not
471
 
511
 
472
# figure out if we know our operating system
512
# figure out if we know our operating system and set up special stuff for it
473
$os = &getOS( \%install, \%operatingSystems, $os );
513
$os = &setUpOperatingSystemSpecific( \%install, \%operatingSystems, $os );
474
 
514
 
475
&validateLibraries( \%libraries, $os );
515
&validateLibraries( \%libraries, $os );
-
 
516
use YAML::Tiny;
476
 
517
 
477
$installType = &getInstallActions( \%install );
518
$installType = &getInstallActions( \%install );
478
 
519
 
479
# based on the defaults, flesh out the install hash
520
# based on the defaults, flesh out the install hash
480
$status = &populateSourceDir( \%install, $sourceDir );
521
$status = &populateSourceDir( \%install, $sourceDir );
Line 483... Line 524...
483
$status = &getVersions( \%install );
524
$status = &getVersions( \%install );
484
 
525
 
485
&showWork( \%install );
526
&showWork( \%install );
486
die unless &yesno( "Ready to run? Select No to abort." );
527
die unless &yesno( "Ready to run? Select No to abort." );
487
 
528
 
-
 
529
#my $config = &makeConfig( $install{'configuration'}{'configuration seed file'}, $install{'configuration'}{'configuration file'}, $install{'configuration'}{'old configuration file'} );
-
 
530
#print Dumper( $config );
-
 
531
#die;
-
 
532
 
-
 
533
 
488
$status = &doInstall( \%install );
534
$status = &doInstall( \%install );
489
 
535
 
490
$status = &postInstall( \%install );
536
$status = &postInstall( \%install );
491
 
537
 
492
# create uninstaller script
538
# create uninstaller script
493
# find the last non-space string in the crontab value. This is the target of the link
539
# find the last non-space string in the crontab value. This is the target of the link
494
$install{'crontab'} =~ m/([^ ]+)$/;
540
$install{'crontab'} =~ m/([^ ]+)$/;
495
my $uninstall = "#! /usr/bin/env sh\n\n# Uninstall syinfo\nrm -fR $install{'bindir'} $install{'confdir'} $1\n";
541
my $uninstall = "#! /usr/bin/env sh\n\n# Uninstall syinfo\nrm -fR $install{'bindir'} $1\n";
496
my $outFileName = $install{'bindir'} . '/uninstall';
542
my $outFileName = $install{'bindir'} . '/uninstall';
497
open UNINSTALL, ">$outFileName" or die "could not write to $outFileName: $!\n";
543
open UNINSTALL, ">$outFileName" or die "could not write to $outFileName: $!\n";
498
print UNINSTALL $uninstall;
544
print UNINSTALL $uninstall;
499
close UNINSTALL;
545
close UNINSTALL;
500
qx ( chmod 700 $outFileName );
546
qx ( chmod 700 $outFileName );