Subversion Repositories camp_sysinfo_client_3

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
42 rodolico 6
# install.pl
7
#
8
# installer for perl script, in this case, sysinfo
9
#
10
# Revision history
11
#
12
# Version 1.1.7 20161010 RWR
13
# Added ability to validate required libraries are installed
14
#
50 rodolico 15
# version 1.2 20170327 RWR
16
# did some major modifications to correctly work on BSD systems also
94 rodolico 17
#
18
# version 2.0 20190330 RWR
19
# changed it so all configs are YAML
33 rodolico 20
 
94 rodolico 21
our $VERSION = '2.0';
42 rodolico 22
 
33 rodolico 23
# find our location and use it for searching for libraries
24
BEGIN {
25
   use FindBin;
26
   use File::Spec;
27
   use lib File::Spec->catdir($FindBin::Bin);
28
}
29
 
30
use sysinfoconf;
101 rodolico 31
use YAML::Tiny;
94 rodolico 32
use Data::Dumper;
33 rodolico 33
use File::Basename;
35 rodolico 34
use Getopt::Long;
35
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
33 rodolico 36
 
35 rodolico 37
# $verbose can have the following values
33 rodolico 38
# 0 - do everything
39
# 1 - Do everything except the install, display what would be done
40
# 2 - Be verbose to STDERR
41
# 3 - Be very verbose
35 rodolico 42
my $verbose = 0; # if test mode, simply show what would be done
43
my $dryRun = 0;
44
my $os;
45
my $help = 0;
46
my $version = 0;
33 rodolico 47
 
48
my $status; # exit status of the processes
49
my $sourceDir = File::Spec->catdir($FindBin::Bin);
34 rodolico 50
my $installType;
33 rodolico 51
 
120 rodolico 52
my @messages; # stores any messages we want to show up at the end
53
my @feedback; # store feedback when we execute command line actions
57 rodolico 54
 
33 rodolico 55
my %install = (  'bindir' => '/opt/camp/sysinfo-client',
56
                 'confdir' => '/etc/camp/sysinfo-client',
34 rodolico 57
                 'application name' => 'sysinfo client',
50 rodolico 58
                 'default group' => 'root',
59
                 'default owner' => 'root',
60
                 'default permission' => '0700',
35 rodolico 61
                 'configuration' => {
62
                          'configurator' => '<bindir>/configure.pl',
94 rodolico 63
                          'configuration file' => '<confdir>/sysinfo-client.yaml',
64
                          'configuration seed file' => 'sysinfo-client.seed.yaml',
65
                          'old configuration file' => '<confdir>/sysinfo-client.conf',
35 rodolico 66
                          'permission' => '700',
50 rodolico 67
                          'owner'      => '<default owner>',
35 rodolico 68
                          'target'     => '<confdir>'
69
                            },
33 rodolico 70
                 'files' => {
71
                           'configure.pl' => { 
72
                                 'type' => 'file',
73
                                 'permission' => '700', 
50 rodolico 74
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 75
                                 'target' =>  '<bindir>'
76
                              },
77
                           'sysinfo-client' => { 
78
                                 'type' => 'file',
79
                                 'permission' => '700',
50 rodolico 80
                                 'owner' => '<default owner>:<default group>',
33 rodolico 81
                                 'target' =>  '<bindir>'
82
                              },
83
                           'sysinfoconf.pm' => {
84
                                 'type' => 'file',
85
                                 'permission' => '600',
50 rodolico 86
                                 'owner' => '<default owner>:<default group>',
33 rodolico 87
                                 'target' =>  '<bindir>'
88
                              },
89
                           'notes' => { 
90
                                 'type' => 'file',
91
                                 'permission' => '600', 
50 rodolico 92
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 93
                                 'target' =>  '<bindir>'
94
                              },
94 rodolico 95
                           'sysinfo-client.conf.template.yaml' => { 
33 rodolico 96
                                 'type' => 'file',
97
                                 'permission' => '600', 
50 rodolico 98
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 99
                                 'target' =>  '<bindir>' 
100
                              },
101
                           'getSendEmail.pl' => { 
102
                                 'type' => 'file',
103
                                 'permission' => '700', 
50 rodolico 104
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 105
                                 'target' =>  '<bindir>' 
106
                              },
107
                           'install.pl' => {
108
                                 'type' => 'file',
109
                                 'permission' => '700', 
50 rodolico 110
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 111
                                 'target' =>  '<bindir>' 
112
                              },
94 rodolico 113
                           'sysinfo-client.seed.example.yaml' => { 
33 rodolico 114
                                 'type' => 'file',
115
                                 'permission' => '600', 
50 rodolico 116
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 117
                                 'target' =>  '<bindir>' 
118
                              },
119
                           'VERSION' => { 
120
                                 'type' => 'file',
121
                                 'permission' => '600', 
50 rodolico 122
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 123
                                 'target' =>  '<bindir>' 
124
                              },
125
                              'modules' => {
126
                                 'type' => 'directory',
127
                                 'permission' => '700', 
50 rodolico 128
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 129
                                 'target' =>  '<bindir>',
130
                                 'action' => 'chmod 700 *'
131
                              },
132
                              'scripts' => {
133
                                 'type' => 'directory',
134
                                 'permission' => '700', 
50 rodolico 135
                                 'owner' => '<default owner>:<default group>', 
33 rodolico 136
                                 'target' =>  '<bindir>',
137
                                 'action' => 'chmod 700 *'
138
                              },
139
                     }
140
                  );
141
 
142
# hash to set up os specific rules                  
143
my %operatingSystems = (
144
                  'debian' => {
76 rodolico 145
                     'regex'  => '(debian|mx|devuan)',
33 rodolico 146
                     'bindir' => '/opt/camp/sysinfo-client',
147
                     'confdir' => '/etc/camp/sysinfo-client',
35 rodolico 148
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/cron.daily/sysinfo-client',
57 rodolico 149
                     'modules' => '((linux)|(dpkg)|(unix)|(all))',
33 rodolico 150
                  },
151
                  'ipfire' => {
60 rodolico 152
                     'regex'  => 'ipfire',
33 rodolico 153
                     'bindir' => '/opt/camp/sysinfo-client',
154
                     'confdir' => '/etc/camp/sysinfo-client',
50 rodolico 155
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/fcron.daily/sysinfo-client.fcron',
57 rodolico 156
                     'modules' => '((ipfire)|(unix)|(all))',
43 rodolico 157
                  },
158
                  'freebsd' => {
60 rodolico 159
                     'regex' => 'freebsd',
43 rodolico 160
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
161
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
50 rodolico 162
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
57 rodolico 163
                     'modules' => '((bsd)|(unix)|(all))',
50 rodolico 164
                    'default group' => 'wheel',
165
                    'default owner' => 'root',
43 rodolico 166
                  },
94 rodolico 167
                  'opnsense' => {
168
                     'fileexists' => '/conf/config.xml',
169
                     'bindir' => '/usr/local/opt/camp/sysinfo-client',
170
                     'confdir' => '/usr/local/etc/camp/sysinfo-client',
171
                     'crontab' => 'ln -s <bindir>/sysinfo-client /etc/periodic/daily/sysinfo-client',
172
                     'modules' => '((bsd)|(unix)|(all))',
173
                    'default group' => 'wheel',
174
                    'default owner' => 'root',
99 rodolico 175
                    'files' => {
176
                              'YAML' => { 
177
                                    'type' => 'directory',
178
                                    'permission' => '777', 
179
                                    'owner' => '<default owner>:<default group>', 
180
                                    'target' =>  '<bindir>'
181
                                 },
182
                              'Tiny.pm' => { 
183
                                    'type' => 'file',
184
                                    'permission' => '444',
185
                                    'owner' => '<default owner>:<default group>',
186
                                    'target' =>  '<bindir>/YAML'
187
                                 },
120 rodolico 188
                              'actions_sysinfo.conf' => {
189
                                    'type' => 'file',
190
                                    'permission' => '755',
191
                                    'owner' => '<default owner>:<default group>',
192
                                    'target' => '/usr/local/opnsense/service/conf/actions.d',
193
                                    'post action' => 'service configd restart',
194
                                    'message' => 'No automatic run can be done. Please log in through the webui and enable the sysinfo cron job'
195
                                 },
99 rodolico 196
                              },
94 rodolico 197
                 },
43 rodolico 198
 
199
                );
42 rodolico 200
 
81 rodolico 201
my %configuration;
202
 
42 rodolico 203
# list of libraries used by the system. We will offer to install them if
204
# we know how. NOTE: I have chosen to put the full installation command
205
# for each library. This allows us to use the package selector OR a different
206
# piece of code on a per-library basis, but results in something like
207
#      apt-get -y install perl-modules
208
#      apt-get -y install libwww-perl
209
# instead of
210
#      apt-get -y install libwww-perl perl-modules
211
# flexibility vs efficiency in this case.
212
my %libraries = ( 
213
                  'File::Basename' => { 'debian' => 'apt-get -y install perl-modules' },
214
                  'Exporter' => { 'debian' => 'apt-get -y install perl-base' },
50 rodolico 215
                  'LWP' => { 
216
                             'debian' => 'apt-get -y install libwww-perl',
55 rodolico 217
                             'freebsd' => 'pkg install -y p5-libwww'
50 rodolico 218
                           },
42 rodolico 219
                );
220
 
43 rodolico 221
# utilities md5sum
222
# freebsd isomd5sum
223
 
42 rodolico 224
# validates the libraries needed exist
225
# simply eval's each library. If it doesn't exist, creates a list of
226
# commands to be executed to install it, and displays missing libraries
227
# offering to install them if possible.
228
sub validateLibraries {
229
   my ( $libraries, $os ) = @_;
230
   my @command;
231
   my @missingLibs;
232
   foreach my $lib ( keys %$libraries ) {
98 rodolico 233
      print "Checking on libarary $lib\n";
42 rodolico 234
      eval( "use $lib;" );
235
      if ( $@ ) {
98 rodolico 236
         print "\tNot found, adding\n";
42 rodolico 237
         push @command,$$libraries{$lib}{$os} if $$libraries{$lib}{$os};
238
         push @missingLibs, $lib;
239
      }
240
   }
241
   if ( @missingLibs ) { # we have missing libraries
242
      if ( @command ) {
243
         &runCommand( join( "\n", @command ) )
244
            if &yesno(
245
                        'Following libraries need to be installed: ' . 
246
                        join( ' ', @missingLibs ) . "\n" .
247
                        "I can install them with the following command(s)\n" . 
248
                        join( "\n", @command ) . "\nDo you want me to do this?\n"
249
                     );
250
      } else {
251
         die unless &yesno( 'Following libraries need to be installed: ' . 
252
                            join( ' ', @missingLibs ) . 
253
                            "\nand I don't know how to do this. Abort?" );
254
      }
255
   } # if
256
} # validateLibraries
33 rodolico 257
 
94 rodolico 258
 
114 rodolico 259
 
260
 
33 rodolico 261
# attempt to locate the operating system.
262
# if found, will set some defaults for it.
94 rodolico 263
sub setUpOperatingSystemSpecific {
35 rodolico 264
   my ( $install, $operatingSystems, $os ) = @_;
107 rodolico 265
   print "They passed $os in as the \$os\n" if $verbose > 2;
35 rodolico 266
   if ( $os ) {
94 rodolico 267
      # We found the OS, set up some defaults
35 rodolico 268
      $$install{'os'} = $os;
269
      print "Setting keys for operating system\n" if $verbose > 2;
114 rodolico 270
      # merge operatingSystems into install
115 rodolico 271
      foreach my $key ( keys %{$operatingSystems->{ $os }} ) {
272
         if ( $key eq 'files' ) {
273
            $install->{'files'} = { %{$install->{'files'}}, %{$operatingSystems->{$os}->{'files'}} }
274
         } else {
275
            $install->{$key} = $operatingSystems->{ $os }->{$key};
276
         }
277
      } # if it is a known OS
35 rodolico 278
   } # if
279
   return $os;
33 rodolico 280
} # getOperatingSystem
281
 
37 rodolico 282
 
34 rodolico 283
# get some input from the user and decide how to install/upgrade/remove/whatever
284
sub getInstallActions {
285
   my $install = shift;
286
   if ( ! &yesno( "This looks like a $$install{'os'} machine, correct?" ) ) {
287
      die "User Aborted\n" if &yesno( "If we continue, I will set this up like a $$install{'os'} system. Abort?" );
288
   }
289
   if ( -d $$install{'confdir'} ) {
290
      $$install{'action'} = &getAnswer( "It looks like $$install{'application name'} is already installed, what do you want to do?", 
291
                            ( "upgrade","remove", "overwrite" )
292
                          );
293
   } else {
294
      if ( &yesno( "This looks like a fresh install, correct?" ) ) {
295
         $$install{'action'} = 'install';
296
         $$install{'preseed config'} = &yesno( "Preseed the configuration file?" );
297
      } else {
298
         die "Can not continue at this time: Do not understand your system\n";
299
      }
300
   }
301
   $$install{'build config'} = &yesno( "Edit config file when done?" );
302
   $$install{'setup cron'} = &yesno( "Set up for automatic running via crontab?" );
303
}
33 rodolico 304
 
34 rodolico 305
sub showWork { 
306
   my $install = shift;
91 rodolico 307
   print Dump( \%install );
34 rodolico 308
}
35 rodolico 309
 
310
 
311
sub doPlaceholderSubstitution {
312
   my ($hash, $placeholder) = @_;
313
   return if ref $hash ne 'HASH';
314
   foreach my $key ( keys %$hash ) {
315
      if ( ref( $$hash{$key} ) ) {
316
         &doPlaceholderSubstitution( $$hash{$key}, $placeholder );
317
      } else {
318
         foreach my $place ( keys %$placeholder ) {
319
            $$hash{$key} =~ s/$place/$$placeholder{$place}/;
320
         } # foreach
321
      } # if..else
322
   } # foreach
323
   return;
324
}
34 rodolico 325
 
326
# This will go through and first, see if anything is a directory, in
327
# which case, we'll create new entries for all files in there.
328
# then, it will do keyword substitution of <bindir> and <confdir>
329
# to populate the target.
330
# When this is done, each file should have a source and target that is
331
# a fully qualified path and filename
33 rodolico 332
sub populateSourceDir {
333
   my ( $install, $sourceDir ) = @_;
35 rodolico 334
   my %placeHolders = 
335
      ( 
336
        '<bindir>' => $$install{'bindir'},
50 rodolico 337
        '<confdir>' => $$install{'confdir'},
338
        '<default owner>' => $$install{'default owner'},
339
        '<default group>' => $$install{'default group'},
340
        '<default permission>' => $$install{'default permission'}
35 rodolico 341
      );
33 rodolico 342
 
343
   my $allFiles = $$install{'files'};
344
 
35 rodolico 345
   # find all directory entries and load files in that directory into $$install{'files'}
33 rodolico 346
   foreach my $dir ( keys %$allFiles ) {
347
      if ( defined( $$allFiles{$dir}{'type'} ) && $$allFiles{$dir}{'type'} eq 'directory' ) {
35 rodolico 348
         print "Found directory $dir\n" if $verbose > 2;
33 rodolico 349
         if ( opendir( my $dh, "$sourceDir/$dir" ) ) {
350
            my @files = map{ $dir . '/' . $_ } grep { ! /^\./ && -f "$sourceDir/$dir/$_" } readdir( $dh );
35 rodolico 351
            print "\tFound files " . join( ' ', @files ) . "\n" if $verbose > 2;
33 rodolico 352
            foreach my $file ( @files ) {
353
               $$allFiles{ $file }{'type'} = 'file';
37 rodolico 354
               if ( $dir eq 'modules' ) {
355
                  $$allFiles{ $file }{'permission'} = ( $file =~ m/$$install{'modules'}/ ) ? '0700' : '0600';
356
               } else {
357
                  $$allFiles{ $file }{'permission'} = $$allFiles{ $dir }{'permission'};
358
               }
33 rodolico 359
               $$allFiles{ $file }{'owner'} = $$allFiles{ $dir }{'owner'};
360
               $$allFiles{ $file }{'target'} = $$allFiles{ $dir }{'target'};
361
            } # foreach
362
            closedir $dh;
363
         } # if opendir
364
      } # if it is a directory
365
   } # foreach
35 rodolico 366
   # find all files, and set the source directory, and add the filename to
367
   # the target
33 rodolico 368
   foreach my $file ( keys %$allFiles ) {
369
      $$allFiles{$file}{'source'} = "$sourceDir/$file";
370
      $$allFiles{$file}{'target'} .= "/$file";
371
   } # foreach
35 rodolico 372
 
373
   # finally, do place holder substitution. This recursively replaces all keys
374
   # in  %placeHolders with the values.
375
   &doPlaceholderSubstitution( $install, \%placeHolders );
376
 
91 rodolico 377
   print Dump( $install ) if $verbose > 2;
35 rodolico 378
 
33 rodolico 379
   return 1;
380
} # populateSourceDir
381
 
34 rodolico 382
# there is a file named VERSIONS. We get the values out of the install
383
# directory and (if it exists) the target so we can decide what needs
384
# to be updated.
33 rodolico 385
sub getVersions {
386
   my $install = shift;
387
   my $currentVersionFile = $$install{'files'}{'VERSION'}{'target'};
388
   my $newVersionFile = $$install{'files'}{'VERSION'}{'source'};
389
   if ( open FILE,"<$currentVersionFile" ) {
390
      while ( my $line = <FILE> ) {
391
         chomp $line;
392
         my ( $filename, $version, $checksum ) = split( "\t", $line );
393
         $$install{'files'}{$filename}{'installed version'} = $version ? $version : '';
394
      }
395
      close FILE;
396
   }
397
   if ( open FILE,"<$newVersionFile" ) {
398
      while ( my $line = <FILE> ) {
399
         chomp $line;
400
         my ( $filename, $version, $checksum ) = split( "\t", $line );
401
         $$install{'files'}{$filename}{'new version'} = $version ? $version : '';
402
      }
403
      close FILE;
404
   }
40 rodolico 405
   foreach my $file ( keys %{$$install{'files'}} ) {
406
      $$install{'files'}{$file}{'installed version'} = -2 unless defined $$install{'files'}{$file}{'installed version'};
407
      $$install{'files'}{$file}{'new version'} = -1 unless defined $$install{'files'}{$file}{'new version'};
408
   }
33 rodolico 409
   return 1;
410
} # getVersions
411
 
34 rodolico 412
# this actually does the installation, except for the configuration
33 rodolico 413
sub doInstall {
414
   my $install = shift;
415
   my $fileList = $$install{'files'};
416
 
50 rodolico 417
   &checkDirectoryExists( $$install{'bindir'} . '/', $$install{'default permission'}, "$$install{'default owner'}:$$install{'default group'}" );
33 rodolico 418
   foreach my $file ( keys %$fileList ) {
419
      next unless ( $$fileList{$file}{'type'} && $$fileList{$file}{'type'} eq 'file' );
40 rodolico 420
      next if $$install{'action'} eq 'upgrade' && ! defined( $$fileList{$file}{'installed version'} )
421
              ||
422
              ( $$fileList{$file}{'new version'} eq $$fileList{$file}{'installed version'} );
50 rodolico 423
      &checkDirectoryExists( $$fileList{$file}{'target'}, $$install{'default permission'}, "$$install{'default owner'}:$$install{'default group'}" );
33 rodolico 424
      &runCommand( 
425
            "cp $$fileList{$file}{'source'} $$fileList{$file}{'target'}",
426
            "chmod $$fileList{$file}{'permission'} $$fileList{$file}{'target'}",
427
            "chown  $$fileList{$file}{'owner'} $$fileList{$file}{'target'}"
428
            );
120 rodolico 429
            # if there is a post action, run it and store any return in @feedback
430
            push @feedback, `$fileList->{$file}->{'post action'}` if defined $fileList->{$file}->{'post action'};
431
            # if there is a message to be passed, store it in @messages
432
            push @messages, $fileList->{$file}->{'meesage'} if defined $fileList->{$file}->{'message'};
33 rodolico 433
   } # foreach file
434
   return 1;
435
}
436
 
35 rodolico 437
sub postInstall {
438
   my $install = shift;
37 rodolico 439
 
35 rodolico 440
   # set up crontab, if necessary
37 rodolico 441
   &runCommand( $$install{'crontab'} ) if defined ( $$install{'crontab'} );
442
 
443
   # seed configuration, if needed
444
   if ( $$install{'build config'} ) {
43 rodolico 445
      my $config;
446
      my @fileList;
37 rodolico 447
 
94 rodolico 448
      # the order is important here as, if multiple files exist, latter ones can
449
      # overwrite values in the previous. We do a push so the first value pushed
450
      # is processed last, ie has higher priority.
451
      push @fileList, $install->{'configuration'}->{'old configuration file'};
452
      push @fileList, $install->{'configuration'}->{'configuration file'};
453
 
454
      my $seedFile = $install->{'configuration'}->{'configuration seed file'};
455
      if ( -e $seedFile  && &yesno( 'Add installation seed file? ' ) ) {
43 rodolico 456
         push @fileList, $seedFile;
37 rodolico 457
      } # if preload seed file
458
 
92 rodolico 459
      $config = &makeConfig( @fileList );
54 rodolico 460
      # if ScriptDirs and moduleDirs not populated, do so from our configuration
88 rodolico 461
      if ( ! $$config{'scriptDirs'} || ! scalar @{ $$config{'scriptDirs'} }  ) {
90 rodolico 462
#         my @temp = ( $$install{'files'}{'scripts'}{'target'} );
463
#         $$config{'scriptDirs'} = \@temp;
464
         $config->{'scriptDirs'} = [ $install->{'files'}->{'scripts'}->{'target'} ];
465
 
54 rodolico 466
      }
88 rodolico 467
      if ( ! $$config{'moduleDirs'} || ! @{ $$config{'moduleDirs'} }  ) {
90 rodolico 468
         $config->{'moduleDirs'} = [ $install->{'files'}->{'modules'}->{'target'} ];
469
#         $$config{'moduleDirs'} = [ $$install{'files'}{'modules'}{'target'} ];
54 rodolico 470
      }
471
#      print Dumper ($config ) ; die;
43 rodolico 472
      my $content = &showConf( $config );
35 rodolico 473
      print $content;
37 rodolico 474
      print &writeConfig( $$install{'configuration'}{'configuration file'} , $content ) . "\n"
475
         if ( &yesno( "Write the above configuration to $$install{'configuration'}{'configuration file'}?" ) );
476
   } # if we are building/merging configuration
120 rodolico 477
   if ( @feedback ) {
478
      print "We got some messages while doing the install, please review below\n" . join( "\n", @feedback ) . "\n";
479
   }
480
   if ( @messages ) {
481
      print "\n\nFollowing are some important messages for your installation\n" . join( "\n", @messages ) . "\n";
482
   }
35 rodolico 483
}
34 rodolico 484
 
35 rodolico 485
sub help {
486
   my $oses = join( ' ', keys %operatingSystems );
487
   print <<END
488
$0 --verbose=x --os="osname" --dryrun --help --version
34 rodolico 489
 
35 rodolico 490
--os      - osname is one of [$oses]
491
--dryrun  - do not actually do anything, just tell you what I'd do
492
--verbose - x is 0 (normal) to 3 (horrible)
493
END
494
}
34 rodolico 495
 
35 rodolico 496
 
497
 
498
##########################################
499
# Main Loop
500
##########################################
501
 
502
# handle any command line parameters that may have been passed in
503
 
504
GetOptions (
505
            "verbose|v=i" => \$verbose, # verbosity level, 0-9
506
            "os|o=s"      => \$os,      # pass in the operating system
507
            "dryrun|n"    => \$dryRun,  # do NOT actually do anything
508
            'help|h'      => \$help,
509
            'version|V'   => \$version
510
            ) or die "Error parsing command line\n";
511
 
512
if ( $help ) { &help() ; exit; }
513
if ( $version ) { print "$0 version $VERSION\n"; exit; }
514
&setDryRun( $dryRun ); # tell the library whether this is a dry run or not
515
 
107 rodolico 516
$os = `$sourceDir/determineOS` unless $os;
94 rodolico 517
# figure out if we know our operating system and set up special stuff for it
115 rodolico 518
 
94 rodolico 519
$os = &setUpOperatingSystemSpecific( \%install, \%operatingSystems, $os );
33 rodolico 520
 
115 rodolico 521
#$os = &setUpOperatingSystemSpecific( \%install, \%operatingSystems, 'freebsd' );
522
#print Dumper( \%install ); die;
523
 
42 rodolico 524
&validateLibraries( \%libraries, $os );
525
 
35 rodolico 526
$installType = &getInstallActions( \%install );
34 rodolico 527
 
33 rodolico 528
# based on the defaults, flesh out the install hash
529
$status = &populateSourceDir( \%install, $sourceDir );
530
 
35 rodolico 531
 
33 rodolico 532
$status = &getVersions( \%install );
533
 
35 rodolico 534
&showWork( \%install );
535
die unless &yesno( "Ready to run? Select No to abort." );
536
 
94 rodolico 537
#my $config = &makeConfig( $install{'configuration'}{'configuration seed file'}, $install{'configuration'}{'configuration file'}, $install{'configuration'}{'old configuration file'} );
538
#print Dumper( $config );
539
#die;
540
 
541
 
33 rodolico 542
$status = &doInstall( \%install );
543
 
35 rodolico 544
$status = &postInstall( \%install );
34 rodolico 545
 
57 rodolico 546
# create uninstaller script
547
# find the last non-space string in the crontab value. This is the target of the link
548
$install{'crontab'} =~ m/([^ ]+)$/;
94 rodolico 549
my $uninstall = "#! /usr/bin/env sh\n\n# Uninstall syinfo\nrm -fR $install{'bindir'} $1\n";
57 rodolico 550
my $outFileName = $install{'bindir'} . '/uninstall';
551
open UNINSTALL, ">$outFileName" or die "could not write to $outFileName: $!\n";
552
print UNINSTALL $uninstall;
553
close UNINSTALL;
554
qx ( chmod 700 $outFileName );
555
 
556
print "Uninstall script has been created at $outFileName\n";
557
 
37 rodolico 558
if ( ( -x $install{'configuration'}{'configurator'} ) && $install{'build config'} ) {
559
   exec( $install{'configuration'}{'configurator'} );
560
} else {
561
   print "Done, you should check the files in $install{'bindir'} and $install{'confdir'} before running\n";
562
   print "If you need help configuring, the helper app at\n$install{'configuration'}{'configurator'}\ncan be used.\n";
563
}
564
 
35 rodolico 565
1;   
40 rodolico 566
 
567
 
568
# clean will look for any file in bindir which is NOT in the list of available files and remove them
569
# if files already exist in install, preserve their permissions