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