101 |
rodolico |
1 |
#! /usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
our $VERSION = '1.0';
|
|
|
4 |
|
|
|
5 |
use strict;
|
|
|
6 |
use warnings;
|
|
|
7 |
|
|
|
8 |
use FindBin;
|
|
|
9 |
use File::Spec;
|
|
|
10 |
use lib File::Spec->catdir($FindBin::Bin);
|
|
|
11 |
|
|
|
12 |
my $sourceDir = File::Spec->catdir($FindBin::Bin);
|
|
|
13 |
chdir $sourceDir;
|
|
|
14 |
|
|
|
15 |
my $verbose = 0;
|
|
|
16 |
|
|
|
17 |
# prompt the user for a response, then allow them to enter it
|
|
|
18 |
# the first response is considered the default and is printed
|
|
|
19 |
# in all caps if more than one exists
|
|
|
20 |
# first answer is used if they simply press the Enter
|
|
|
21 |
# key. The response is returned all lower case if more than one
|
|
|
22 |
# exists.
|
|
|
23 |
# it is assumed
|
|
|
24 |
sub getAnswer {
|
|
|
25 |
my ( $prompt, @answers ) = @_;
|
|
|
26 |
$answers[0] = '' unless defined( $answers[0] );
|
|
|
27 |
my $default = $answers[0];
|
|
|
28 |
my $onlyOneAnswer = scalar( @answers ) == 1;
|
|
|
29 |
print $prompt . '[ ';
|
|
|
30 |
$answers[0] = uc $answers[0] unless $onlyOneAnswer;
|
|
|
31 |
print join( ' | ', @answers ) . ' ]: ';
|
|
|
32 |
my $thisAnswer = <>;
|
|
|
33 |
chomp $thisAnswer;
|
|
|
34 |
$thisAnswer = $default unless $thisAnswer;
|
|
|
35 |
return $thisAnswer;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
sub yesno {
|
|
|
40 |
my ( $prompt, $default ) = @_;
|
|
|
41 |
$default = 'yes' unless $default;
|
|
|
42 |
my $answer = &getAnswer( $prompt, $default eq 'yes' ? ('yes','no' ) : ('no', 'yes') );
|
|
|
43 |
return lc( substr( $answer, 0, 1 ) ) eq 'y';
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
# hash to set up os specific rules
|
|
|
48 |
my %operatingSystems = (
|
|
|
49 |
'debian' => {
|
|
|
50 |
'regex' => '(debian|mx|devuan)',
|
|
|
51 |
'install' => 'apt-get -y install libyaml-tiny-perl',
|
|
|
52 |
},
|
|
|
53 |
'ipfire' => {
|
|
|
54 |
'regex' => 'ipfire',
|
122 |
rodolico |
55 |
'install' => 'gunzip Tiny.pm.gz ; mkdir YAML ; cp Tiny.pm YAML',
|
101 |
rodolico |
56 |
},
|
|
|
57 |
'freebsd' => {
|
|
|
58 |
'regex' => 'freebsd',
|
102 |
rodolico |
59 |
'install' => 'echo y | pkg install p5-YAML-Tiny',
|
101 |
rodolico |
60 |
},
|
|
|
61 |
'opnsense' => {
|
|
|
62 |
'fileexists' => '/conf/config.xml',
|
122 |
rodolico |
63 |
'install' => 'gunzip Tiny.pm.gz ; mkdir YAML ; cp Tiny.pm YAML',
|
101 |
rodolico |
64 |
},
|
|
|
65 |
|
|
|
66 |
);
|
|
|
67 |
|
|
|
68 |
|
106 |
rodolico |
69 |
my $os = `./determineOS`;
|
101 |
rodolico |
70 |
|
|
|
71 |
die "Could not determine operating system, manual installation required\n" unless $os;
|
|
|
72 |
|
|
|
73 |
eval( 'use YAML::Tiny' );
|
|
|
74 |
if ( $@ ) { # we need to install YAML::Tiny
|
|
|
75 |
if ( &yesno( "You need YAML::Tiny but it is not installed\nI can install it with the command\n$operatingSystems{$os}{install}\nOk" ) ) {
|
|
|
76 |
print "Please wait while I do the installation\nIt will take a minute\n";
|
|
|
77 |
`$operatingSystems{$os}{'install'}`;
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
118 |
rodolico |
81 |
#print "perl install-sysinfo-client.pl --os=$os\n";
|
|
|
82 |
exec "perl install-sysinfo-client.pl --os=$os";
|