Subversion Repositories camp_sysinfo_client_3

Rev

Rev 244 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
224 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
6
# find our location and use it for searching for libraries
7
BEGIN {
8
   use FindBin;
9
   use File::Spec;
10
   # use libraries from the directory this script is in
11
   use lib File::Spec->catdir($FindBin::Bin);
12
   # and its parent
13
   use lib File::Spec->catdir( $FindBin::Bin . '/../' );
14
   eval( 'use YAML::Tiny' );
15
}
16
 
17
use Cwd qw(abs_path);
18
use sysinfosetup;
19
 
20
my $scriptDir = abs_path(File::Spec->catdir($FindBin::Bin) );
225 rodolico 21
my $binDir = abs_path("$scriptDir/../");
224 rodolico 22
use Digest::MD5 qw(md5_hex);
23
use File::Copy;
24
 
25
# define the version number
26
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
27
use version;
28
our $VERSION = version->declare("v0.001.001");
29
 
30
 
31
use Data::Dumper;
32
use File::Basename;
33
use Getopt::Long;
34
 
35
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
36
our $dryRun;
37
our $DEBUG;
38
my $os;
39
my $help = 0;
40
my $version = 0;
41
my $quiet = 0;
42
my $seedFileName = '';
43
 
44
our %operatingSystems;
45
 
46
# simple display if --help is passed
47
sub help {
48
   use File::Basename;
49
   print basename($0) . " $VERSION\n";
50
   print <<END
51
$0 [options]
52
Options:
53
   --os|-o      - lower case name of operating system (debian, freebsd, etc...)
54
   --dryrun|-n  - do not actually do anything, just tell you what I'd do
55
   --version|-v - display version and exit
56
   --quiet|-q   - Do not ask questions, just do stuff
57
   --help|-g    - Show this screen
58
   --seed|-s    - URL/Path to seed file for config
59
   --debug      - Show extra information (--nodebug is default)
60
END
61
}
62
 
63
 
64
################################################################
65
#               Main Code                                      #
66
################################################################
67
 
68
# handle any command line parameters that may have been passed in
69
 
70
GetOptions (
71
            "os|o=s"      => \$os,      # pass in the operating system
72
            "dryrun|n"    => \$dryRun,  # do NOT actually do anything
73
            "seed|s=s"    => \$seedFileName,
74
            'help|h'      => \$help,
75
            'version|v'   => \$version,
76
            'quiet|q'     => \$quiet,
77
            'debug!'      => \$DEBUG
78
            ) or die "Error parsing command line\n";
79
 
80
if ( $help ) { &help() ; exit; }
81
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
82
 
225 rodolico 83
# find OS if they did not tell us what it was
84
$os = `$scriptDir/determineOS` unless $os;
85
print "Installing Conf and Cron for $os\n" unless $quiet;
86
 
224 rodolico 87
my $returnValue = 0;
225 rodolico 88
my $command;
224 rodolico 89
 
90
# load the definitions from installer_config.pl
91
do "$scriptDir/installer_config.pl";
92
 
93
our %libraries;
94
our %install;
95
our %binaries;
96
 
225 rodolico 97
if ( $seedFileName =~ m'^((http)|(ftp))s?://' ) { # the seed file is a URL
98
   $command = "wget -O /tmp/seedfile --no-check-certificate $seedFileName";
99
   print "Downloading from $seedFileName\n\t$command\n" unless $quiet;
100
   `$command` unless $dryRun;
101
   $seedFileName = '/tmp/seedfile';
102
}
103
 
224 rodolico 104
# Check for configuration file
105
my $configDir = $operatingSystems{ $os }{'confdir'};
106
unless ( -d $configDir ) {
225 rodolico 107
   $command = "mkdir -p $configDir";
108
   print "Creating $configDir\n\t$command\n" unless $quiet;
109
   `$command` unless $dryRun;
224 rodolico 110
}
111
 
112
my $configFile = $operatingSystems{'configuration file'};
113
$configFile =~ s/<confdir>/$configDir/;
114
unless ( -f $configFile ) {
115
   $seedFileName = "$scriptDir/sysinfo-client.conf.template.yaml" unless $seedFileName;
225 rodolico 116
   $command = "cp $seedFileName $configFile";
117
   print "Creating $configFile\n\t$command\n" unless $quiet;
224 rodolico 118
   `cp $seedFileName $configFile` unless $dryRun;
119
}
120
 
121
# check for cron file(s)
225 rodolico 122
if ( defined( $operatingSystems{$os}{'crontab'} ) ) {
123
   my $command = $operatingSystems{$os}{'crontab'};
124
   $command =~ s/<bindir>/$binDir/;
125
   $command =~ s/<scriptdir>/$scriptDir/g;
126
   print "Setting up cron\n\t$command\n" unless $quiet;
127
   `$command` unless $dryRun;
128
}