Subversion Repositories camp_sysinfo_client_3

Rev

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

Rev 40 Rev 42
Line 1... Line 1...
1
#! /usr/bin/env perl
1
#! /usr/bin/env perl
2
 
2
 
-
 
3
 
3
use strict;
4
use strict;
4
use warnings;
5
use warnings;
5
 
6
 
-
 
7
# install.pl
-
 
8
#
-
 
9
# installer for perl script, in this case, sysinfo
-
 
10
#
-
 
11
# Revision history
-
 
12
#
-
 
13
# Version 1.1.7 20161010 RWR
-
 
14
# Added ability to validate required libraries are installed
-
 
15
#
-
 
16
 
6
our $VERSION = '1.1.5';
17
our $VERSION = '1.1.6';
7
 
18
 
8
# find our location and use it for searching for libraries
19
# find our location and use it for searching for libraries
9
BEGIN {
20
BEGIN {
10
   use FindBin;
21
   use FindBin;
11
   use File::Spec;
22
   use File::Spec;
Line 136... Line 147...
136
                     'confdir' => '/etc/camp/sysinfo-client',
147
                     'confdir' => '/etc/camp/sysinfo-client',
137
                     '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',
138
                     'modules' => '((ipfire)|(unix))',
149
                     'modules' => '((ipfire)|(unix))',
139
                  }
150
                  }
140
                  );
151
                  );
-
 
152
 
-
 
153
# 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
-
 
155
# 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
-
 
157
#      apt-get -y install perl-modules
-
 
158
#      apt-get -y install libwww-perl
-
 
159
# instead of
-
 
160
#      apt-get -y install libwww-perl perl-modules
-
 
161
# flexibility vs efficiency in this case.
-
 
162
my %libraries = ( 
-
 
163
                  'File::Basename' => { 'debian' => 'apt-get -y install perl-modules' },
-
 
164
                  'Exporter' => { 'debian' => 'apt-get -y install perl-base' },
-
 
165
                  'LWP' => { 'debian' => 'apt-get -y install libwww-perl' },
-
 
166
                );
-
 
167
 
-
 
168
# validates the libraries needed exist
-
 
169
# 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
-
 
171
# offering to install them if possible.
-
 
172
sub validateLibraries {
-
 
173
   my ( $libraries, $os ) = @_;
-
 
174
   my @command;
-
 
175
   my @missingLibs;
-
 
176
   foreach my $lib ( keys %$libraries ) {
-
 
177
      eval( "use $lib;" );
-
 
178
      if ( $@ ) {
-
 
179
         push @command,$$libraries{$lib}{$os} if $$libraries{$lib}{$os};
-
 
180
         push @missingLibs, $lib;
-
 
181
      }
-
 
182
   }
-
 
183
   if ( @missingLibs ) { # we have missing libraries
-
 
184
      if ( @command ) {
-
 
185
         &runCommand( join( "\n", @command ) )
-
 
186
            if &yesno(
-
 
187
                        'Following libraries need to be installed: ' . 
-
 
188
                        join( ' ', @missingLibs ) . "\n" .
-
 
189
                        "I can install them with the following command(s)\n" . 
-
 
190
                        join( "\n", @command ) . "\nDo you want me to do this?\n"
-
 
191
                     );
-
 
192
      } else {
-
 
193
         die unless &yesno( 'Following libraries need to be installed: ' . 
-
 
194
                            join( ' ', @missingLibs ) . 
-
 
195
                            "\nand I don't know how to do this. Abort?" );
-
 
196
      }
-
 
197
   } # if
-
 
198
} # validateLibraries
141
                  
199
                  
142
 
200
 
143
# attempt to locate the operating system.
201
# attempt to locate the operating system.
144
# if found, will set some defaults for it.
202
# if found, will set some defaults for it.
145
sub getOS {
203
sub getOS {
Line 155... Line 213...
155
      } # foreach
213
      } # foreach
156
   }
214
   }
157
   if ( $os ) {
215
   if ( $os ) {
158
      $$install{'os'} = $os;
216
      $$install{'os'} = $os;
159
      print "Setting keys for operating system\n" if $verbose > 2;
217
      print "Setting keys for operating system\n" if $verbose > 2;
160
      foreach my $key ( keys $$operatingSystems{ $os } ) {
218
      foreach my $key ( keys %{$$operatingSystems{ $os }} ) {
161
         $$install{$key} = $operatingSystems{ $os }{$key};
219
         $$install{$key} = $operatingSystems{ $os }{$key};
162
      } # if it is a known OS
220
      } # if it is a known OS
163
   } # if
221
   } # if
164
   return $os;
222
   return $os;
165
} # getOperatingSystem
223
} # getOperatingSystem
Line 399... Line 457...
399
&setDryRun( $dryRun ); # tell the library whether this is a dry run or not
457
&setDryRun( $dryRun ); # tell the library whether this is a dry run or not
400
 
458
 
401
# figure out if we know our operating system
459
# figure out if we know our operating system
402
$os = &getOS( \%install, \%operatingSystems, $os );
460
$os = &getOS( \%install, \%operatingSystems, $os );
403
 
461
 
-
 
462
&validateLibraries( \%libraries, $os );
-
 
463
 
-
 
464
die;
-
 
465
 
404
$installType = &getInstallActions( \%install );
466
$installType = &getInstallActions( \%install );
405
 
467
 
406
# based on the defaults, flesh out the install hash
468
# based on the defaults, flesh out the install hash
407
$status = &populateSourceDir( \%install, $sourceDir );
469
$status = &populateSourceDir( \%install, $sourceDir );
408
 
470