203 |
rodolico |
1 |
#! /usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
use strict;
|
|
|
4 |
use warnings;
|
|
|
5 |
use Getopt::Long;
|
|
|
6 |
|
|
|
7 |
# used as a small file to download and install sysinfo client
|
|
|
8 |
|
|
|
9 |
# perl install_sysinfo_client.pl \
|
|
|
10 |
# --dryRun \
|
204 |
rodolico |
11 |
# --repo=http://svn.dailydata.net/svn/camp_sysinfo_client_3/tags/stable \
|
203 |
rodolico |
12 |
# --target ~/test \
|
204 |
rodolico |
13 |
# --seed=http://example.com/private/sysinfo-client.seed.yaml
|
203 |
rodolico |
14 |
|
|
|
15 |
# define the version number
|
|
|
16 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
|
|
17 |
use version;
|
|
|
18 |
our $VERSION = version->declare("v1.001.001");
|
|
|
19 |
|
|
|
20 |
my %operatingSystems = (
|
|
|
21 |
'linux' => '/opt/camp/sysinfo-client', # '/opt/camp/sysinfo-client',
|
|
|
22 |
'bsd' => '/usr/local/opt/camp/sysinfo-client'
|
|
|
23 |
);
|
|
|
24 |
|
206 |
rodolico |
25 |
my $configurationTool = 'installer/install --quiet --inplace';
|
204 |
rodolico |
26 |
|
203 |
rodolico |
27 |
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
|
|
|
28 |
my $repository = 'http://svn.dailydata.net/svn/camp_sysinfo_client_3/tags/stable';
|
|
|
29 |
my $svn = '';
|
|
|
30 |
my $dryRun = 0;
|
|
|
31 |
my $os;
|
|
|
32 |
my $help = 0;
|
|
|
33 |
my $version = 0;
|
|
|
34 |
my $targetDir;
|
|
|
35 |
my $seedFileURL;
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
# simple display if --help is passed
|
|
|
39 |
sub help {
|
|
|
40 |
my $oses = join( ', ', keys %operatingSystems );
|
|
|
41 |
use File::Basename;
|
|
|
42 |
print basename($0) . " $VERSION\n";
|
|
|
43 |
print <<END
|
|
|
44 |
$0 [options]
|
|
|
45 |
Options:
|
|
|
46 |
--os - osname, one of [$oses]
|
|
|
47 |
--dryrun - do not actually do anything, just tell you what I'd do
|
|
|
48 |
--version - display version and exit
|
|
|
49 |
--svn - path to svn command
|
|
|
50 |
--repo - full URL of subversion repository
|
|
|
51 |
--target - Target directory for installation
|
|
|
52 |
--seed - URL to download a seed file for new installs
|
|
|
53 |
END
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
################################################################
|
|
|
58 |
# Main Code #
|
|
|
59 |
################################################################
|
|
|
60 |
|
|
|
61 |
# handle any command line parameters that may have been passed in
|
|
|
62 |
|
|
|
63 |
GetOptions (
|
|
|
64 |
"os|o=s" => \$os, # pass in the operating system
|
|
|
65 |
"dryrun|n" => \$dryRun, # do NOT actually do anything
|
|
|
66 |
'help|h' => \$help,
|
|
|
67 |
'version|v' => \$version,
|
|
|
68 |
'svn|s=s' => \$svn,
|
|
|
69 |
'repo|r=s' => \$repository,
|
|
|
70 |
'target|t=s' => \$targetDir,
|
|
|
71 |
'seed=s' => \$seedFileURL
|
|
|
72 |
) or die "Error parsing command line\n";
|
|
|
73 |
|
|
|
74 |
if ( $help ) { &help() ; exit; }
|
|
|
75 |
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
|
|
|
76 |
unless ( $svn ) {
|
|
|
77 |
$svn = `which svn`;
|
|
|
78 |
chomp $svn;
|
|
|
79 |
}
|
|
|
80 |
die "Could not locate svn command\n" unless $svn;
|
204 |
rodolico |
81 |
die "This installer requires subversion, and it is not found on this system\n" unless `$svn --version --quiet`;
|
203 |
rodolico |
82 |
|
|
|
83 |
$os = `uname` unless $os;
|
|
|
84 |
$os = lc $os;
|
|
|
85 |
chomp $os;
|
|
|
86 |
|
|
|
87 |
$targetDir = $operatingSystems{$os} unless $targetDir;
|
|
|
88 |
|
204 |
rodolico |
89 |
# the directory exists and is not an svn repo, so move it
|
|
|
90 |
if ( -e $targetDir && system( "svn info $targetDir >/dev/null 2>&1" ) ) {
|
|
|
91 |
print "$targetDir exists and is not an svn URL; moving to $targetDir.backup\n";
|
|
|
92 |
`mv $targetDir $targetDir.backup` unless $dryRun;
|
|
|
93 |
}
|
|
|
94 |
if ( -d $targetDir ) { # target is a directory, and an svn repo
|
|
|
95 |
print "Performing an update on $targetDir\n";
|
|
|
96 |
`svn update $targetDir` unless $dryRun;
|
206 |
rodolico |
97 |
} else { # doesn't exist, so create and do a checkout
|
204 |
rodolico |
98 |
print "Creating target directory $targetDir\n";
|
206 |
rodolico |
99 |
`mkdir -p $targetDir` unless -d $targetDir || $dryRun; # verify the target directory exists
|
204 |
rodolico |
100 |
print "Installing into $targetDir using $svn checkout $repository\n";
|
|
|
101 |
`$svn checkout $repository $targetDir` unless $dryRun;
|
|
|
102 |
}
|
|
|
103 |
if ( $seedFileURL ) {
|
|
|
104 |
print "Downloading seed file from $seedFileURL\n";
|
|
|
105 |
unless ( $dryRun ) {
|
|
|
106 |
my $seedFileName = $targetDir . '/installer/sysinfo-client.seed.yaml';
|
|
|
107 |
`wget --quiet --output-document=$seedFileName $seedFileURL`;
|
|
|
108 |
die "Error downloading $seedFileURL into $seedFileName\n" if $?;
|
203 |
rodolico |
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
206 |
rodolico |
112 |
print "Starting up $configurationTool\n";
|
204 |
rodolico |
113 |
|
206 |
rodolico |
114 |
|
|
|
115 |
print "Now run $targetDir/$configurationTool\n";
|
|
|
116 |
exec( "$targetDir/$configurationTool" ) unless $dryRun;
|
204 |
rodolico |
117 |
#https://metacpan.org/pod/Hash%3a%3aMerge
|
|
|
118 |
|
|
|
119 |
#check for all the necessary libraries and install
|
|
|
120 |
#set cron job
|
|
|
121 |
#merge seedFile with any existing configuration file and save
|
|
|
122 |
#message to user to run configure.pl
|
|
|
123 |
|
203 |
rodolico |
124 |
1;
|