Subversion Repositories camp_sysinfo_client_3

Rev

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

Rev 35 Rev 37
Line 1... Line 1...
1
#! /usr/bin/env perl
1
#! /usr/bin/env perl
2
 
2
 
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
 
5
 
6
our $VERSION = '1.1.3';
6
our $VERSION = '1.1.4';
7
 
7
 
8
# find our location and use it for searching for libraries
8
# find our location and use it for searching for libraries
9
BEGIN {
9
BEGIN {
10
   use FindBin;
10
   use FindBin;
11
   use File::Spec;
11
   use File::Spec;
Line 86... Line 86...
86
                                 'type' => 'file',
86
                                 'type' => 'file',
87
                                 'permission' => '600', 
87
                                 'permission' => '600', 
88
                                 'owner' => 'root:root', 
88
                                 'owner' => 'root:root', 
89
                                 'target' =>  '<bindir>' 
89
                                 'target' =>  '<bindir>' 
90
                              },
90
                              },
91
                           'uninstall.pl' => { 
-
 
92
                                 'type' => 'file',
-
 
93
                                 'permission' => '700', 
-
 
94
                                 'owner' => 'root:root', 
-
 
95
                                 'target' =>  '<bindir>' 
-
 
96
                              },
-
 
97
                           'getSendEmail.pl' => { 
91
                           'getSendEmail.pl' => { 
98
                                 'type' => 'file',
92
                                 'type' => 'file',
99
                                 'permission' => '700', 
93
                                 'permission' => '700', 
100
                                 'owner' => 'root:root', 
94
                                 'owner' => 'root:root', 
101
                                 'target' =>  '<bindir>' 
95
                                 'target' =>  '<bindir>' 
102
                              },
96
                              },
103
                           'upgrade.pl' => { 
-
 
104
                                 'type' => 'file',
-
 
105
                                 'permission' => '700', 
-
 
106
                                 'owner' => 'root:root', 
-
 
107
                                 'target' =>  '<bindir>' 
-
 
108
                              },
-
 
109
                           'install.pl' => {
97
                           'install.pl' => {
110
                                 'type' => 'file',
98
                                 'type' => 'file',
111
                                 'permission' => '700', 
99
                                 'permission' => '700', 
112
                                 'owner' => 'root:root', 
100
                                 'owner' => 'root:root', 
113
                                 'target' =>  '<bindir>' 
101
                                 'target' =>  '<bindir>' 
Line 151... Line 139...
151
my %operatingSystems = (
139
my %operatingSystems = (
152
                  'debian' => {
140
                  'debian' => {
153
                     'bindir' => '/opt/camp/sysinfo-client',
141
                     'bindir' => '/opt/camp/sysinfo-client',
154
                     'confdir' => '/etc/camp/sysinfo-client',
142
                     'confdir' => '/etc/camp/sysinfo-client',
155
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/cron.daily/sysinfo-client',
143
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/cron.daily/sysinfo-client',
156
                     'modules' => '/^((dpkg)|(unix)|(ipmi))/',
144
                     'modules' => '((dpkg)|(unix)|(ipmi)|(xen))',
157
                  },
145
                  },
158
                  'ipfire' => {
146
                  'ipfire' => {
159
                     'bindir' => '/opt/camp/sysinfo-client',
147
                     'bindir' => '/opt/camp/sysinfo-client',
160
                     'confdir' => '/etc/camp/sysinfo-client',
148
                     'confdir' => '/etc/camp/sysinfo-client',
161
                     'crontab' => 'ln -s <bindir>sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
149
                     'crontab' => 'ln -s <bindir>sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
162
                     'modules' => '/^((ipfire)|(unix))/',
150
                     'modules' => '((ipfire)|(unix))',
163
                  }
151
                  }
164
                  );
152
                  );
165
                  
153
                  
166
 
154
 
167
# attempt to locate the operating system.
155
# attempt to locate the operating system.
Line 186... Line 174...
186
      } # if it is a known OS
174
      } # if it is a known OS
187
   } # if
175
   } # if
188
   return $os;
176
   return $os;
189
} # getOperatingSystem
177
} # getOperatingSystem
190
 
178
 
-
 
179
 
191
# get some input from the user and decide how to install/upgrade/remove/whatever
180
# get some input from the user and decide how to install/upgrade/remove/whatever
192
sub getInstallActions {
181
sub getInstallActions {
193
   my $install = shift;
182
   my $install = shift;
194
   if ( ! &yesno( "This looks like a $$install{'os'} machine, correct?" ) ) {
183
   if ( ! &yesno( "This looks like a $$install{'os'} machine, correct?" ) ) {
195
      die "User Aborted\n" if &yesno( "If we continue, I will set this up like a $$install{'os'} system. Abort?" );
184
      die "User Aborted\n" if &yesno( "If we continue, I will set this up like a $$install{'os'} system. Abort?" );
Line 254... Line 243...
254
         if ( opendir( my $dh, "$sourceDir/$dir" ) ) {
243
         if ( opendir( my $dh, "$sourceDir/$dir" ) ) {
255
            my @files = map{ $dir . '/' . $_ } grep { ! /^\./ && -f "$sourceDir/$dir/$_" } readdir( $dh );
244
            my @files = map{ $dir . '/' . $_ } grep { ! /^\./ && -f "$sourceDir/$dir/$_" } readdir( $dh );
256
            print "\tFound files " . join( ' ', @files ) . "\n" if $verbose > 2;
245
            print "\tFound files " . join( ' ', @files ) . "\n" if $verbose > 2;
257
            foreach my $file ( @files ) {
246
            foreach my $file ( @files ) {
258
               $$allFiles{ $file }{'type'} = 'file';
247
               $$allFiles{ $file }{'type'} = 'file';
-
 
248
               if ( $dir eq 'modules' ) {
-
 
249
                  $$allFiles{ $file }{'permission'} = ( $file =~ m/$$install{'modules'}/ ) ? '0700' : '0600';
-
 
250
               } else {
259
               $$allFiles{ $file }{'permission'} = $$allFiles{ $dir }{'permission'};
251
                  $$allFiles{ $file }{'permission'} = $$allFiles{ $dir }{'permission'};
-
 
252
               }
260
               $$allFiles{ $file }{'owner'} = $$allFiles{ $dir }{'owner'};
253
               $$allFiles{ $file }{'owner'} = $$allFiles{ $dir }{'owner'};
261
               $$allFiles{ $file }{'target'} = $$allFiles{ $dir }{'target'};
254
               $$allFiles{ $file }{'target'} = $$allFiles{ $dir }{'target'};
262
            } # foreach
255
            } # foreach
263
            closedir $dh;
256
            closedir $dh;
264
         } # if opendir
257
         } # if opendir
265
      } # if it is a directory
258
      } # if it is a directory
266
   } # foreach
259
   } # foreach
267
 
-
 
268
   # find all files, and set the source directory, and add the filename to
260
   # find all files, and set the source directory, and add the filename to
269
   # the target
261
   # the target
270
   foreach my $file ( keys %$allFiles ) {
262
   foreach my $file ( keys %$allFiles ) {
271
      $$allFiles{$file}{'source'} = "$sourceDir/$file";
263
      $$allFiles{$file}{'source'} = "$sourceDir/$file";
272
      $$allFiles{$file}{'target'} .= "/$file";
264
      $$allFiles{$file}{'target'} .= "/$file";
Line 328... Line 320...
328
   return 1;
320
   return 1;
329
}
321
}
330
 
322
 
331
sub postInstall {
323
sub postInstall {
332
   my $install = shift;
324
   my $install = shift;
-
 
325
 
333
   # set up crontab, if necessary
326
   # set up crontab, if necessary
-
 
327
   &runCommand( $$install{'crontab'} ) if defined ( $$install{'crontab'} );
-
 
328
   
334
   # run configurator, if needed
329
   # seed configuration, if needed
-
 
330
   if ( $$install{'build config'} ) {
335
   my %config;
331
      my %config;
336
   my $seedFile = $install{'configuration'}{'configuration seed file'};
332
      my $seedFile = $$install{'configuration'}{'configuration seed file'};
337
   my $confFile = $install{'configuration'}{'configuration file'};
333
      my $confFile = $$install{'configuration'}{'configuration file'};
338
   my $content;
334
      my $content;
339
   if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
-
 
-
 
335
 
340
      my $clientName;
336
      my $clientName;
341
      my $serialNumber;
337
      my $serialNumber;
342
      my $hostname;
338
      my $hostname;
343
      my @moduleDirs;
339
      my @moduleDirs;
344
      my @scriptDirs;
340
      my @scriptDirs;
345
      my $transports = {};
341
      my $transports = {};
-
 
342
 
346
         
343
      
-
 
344
      if ( -f $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
347
      print "Loading seed file $seedFile\n";
345
         print "Loading seed file $seedFile\n";
348
      open SEED, "<$seedFile" or die "Could not open $seedFile: $!\n";
346
         open SEED, "<$seedFile" or die "Could not open $seedFile: $!\n";
349
      $content = join( '', <SEED> );
347
         $content = join( '', <SEED> );
350
      close SEED;
348
         close SEED;
351
      # now, eval the information we just read.
349
         # now, eval the information we just read.
352
      # NOTE: we must turn off strict while doing this, and we die if something breaks.
350
         # NOTE: we must turn off strict while doing this, and we die if something breaks.
353
      no strict "vars"; eval( $content ); use strict "vars"; die "Error during eval: $@\n" if $@;
351
         no strict "vars"; eval( $content ); use strict "vars"; die "Error during eval: $@\n" if $@;
-
 
352
      } # if preload seed file
354
 
353
 
355
      if (  -f $confFile  ) {
354
      if (  -f $confFile  ) {
356
         print "Loading configuration file $confFile\n";
355
         print "Loading configuration file $confFile\n";
357
         open SEED, "<$confFile" or die "Could not open $confFile: $!\n";
356
         open SEED, "<$confFile" or die "Could not open $confFile: $!\n";
358
         $content = join( '', <SEED> );
357
         $content = join( '', <SEED> );
Line 368... Line 367...
368
      $config{'scriptDirs'} = [ @scriptDirs ];
367
      $config{'scriptDirs'} = [ @scriptDirs ];
369
      $config{'transports'} = $transports;
368
      $config{'transports'} = $transports;
370
 
369
 
371
      $content = &showConf( \%config );
370
      $content = &showConf( \%config );
372
      print $content;
371
      print $content;
373
      print &writeConfig( $install{'configuration'}{'configuration file'} , $content ) . "\n"
372
      print &writeConfig( $$install{'configuration'}{'configuration file'} , $content ) . "\n"
374
         if ( &yesno( "Write the above configuration to $install{'configuration'}{'configuration file'}?" ) );
373
         if ( &yesno( "Write the above configuration to $$install{'configuration'}{'configuration file'}?" ) );
375
   }
374
   } # if we are building/merging configuration
376
   
375
   
377
   if ( ( -x $install{'configuration'}{'configurator'} ) && $install{'build config'} ) {
-
 
378
      exec( $install{'configuration'}{'configurator'} );
-
 
379
   }
-
 
380
}
376
}
381
 
377
 
382
sub help {
378
sub help {
383
   my $oses = join( ' ', keys %operatingSystems );
379
   my $oses = join( ' ', keys %operatingSystems );
384
   print <<END
380
   print <<END
Line 426... Line 422...
426
 
422
 
427
$status = &doInstall( \%install );
423
$status = &doInstall( \%install );
428
 
424
 
429
$status = &postInstall( \%install );
425
$status = &postInstall( \%install );
430
 
426
 
-
 
427
if ( ( -x $install{'configuration'}{'configurator'} ) && $install{'build config'} ) {
-
 
428
   exec( $install{'configuration'}{'configurator'} );
-
 
429
} else {
-
 
430
   print "Done, you should check the files in $install{'bindir'} and $install{'confdir'} before running\n";
-
 
431
   print "If you need help configuring, the helper app at\n$install{'configuration'}{'configurator'}\ncan be used.\n";
-
 
432
}
-
 
433
 
431
1;   
434
1;