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;
|
211 |
rodolico |
18 |
our $VERSION = version->declare("v1.001.002");
|
203 |
rodolico |
19 |
|
|
|
20 |
my %operatingSystems = (
|
211 |
rodolico |
21 |
'linux' => '/opt/camp/sysinfo-client',
|
|
|
22 |
'freebsd' => '/usr/local/opt/camp/sysinfo-client'
|
203 |
rodolico |
23 |
);
|
208 |
rodolico |
24 |
|
211 |
rodolico |
25 |
|
208 |
rodolico |
26 |
# location of the installer library so we can set stuff up correctly
|
|
|
27 |
my $libraryFile = 'installer/installer_config.pl';
|
203 |
rodolico |
28 |
|
214 |
rodolico |
29 |
my $configurationTool = 'installer/install --quiet';
|
204 |
rodolico |
30 |
|
203 |
rodolico |
31 |
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
|
|
|
32 |
my $repository = 'http://svn.dailydata.net/svn/camp_sysinfo_client_3/tags/stable';
|
|
|
33 |
my $svn = '';
|
|
|
34 |
my $dryRun = 0;
|
|
|
35 |
my $os;
|
|
|
36 |
my $help = 0;
|
|
|
37 |
my $version = 0;
|
|
|
38 |
my $targetDir;
|
|
|
39 |
my $seedFileURL;
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
# simple display if --help is passed
|
|
|
43 |
sub help {
|
|
|
44 |
my $oses = join( ', ', keys %operatingSystems );
|
|
|
45 |
use File::Basename;
|
|
|
46 |
print basename($0) . " $VERSION\n";
|
|
|
47 |
print <<END
|
|
|
48 |
$0 [options]
|
|
|
49 |
Options:
|
|
|
50 |
--os - osname, one of [$oses]
|
|
|
51 |
--dryrun - do not actually do anything, just tell you what I'd do
|
|
|
52 |
--version - display version and exit
|
|
|
53 |
--svn - path to svn command
|
|
|
54 |
--repo - full URL of subversion repository
|
|
|
55 |
--target - Target directory for installation
|
|
|
56 |
--seed - URL to download a seed file for new installs
|
|
|
57 |
END
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
################################################################
|
|
|
62 |
# Main Code #
|
|
|
63 |
################################################################
|
|
|
64 |
|
|
|
65 |
# handle any command line parameters that may have been passed in
|
|
|
66 |
|
|
|
67 |
GetOptions (
|
|
|
68 |
"os|o=s" => \$os, # pass in the operating system
|
|
|
69 |
"dryrun|n" => \$dryRun, # do NOT actually do anything
|
|
|
70 |
'help|h' => \$help,
|
|
|
71 |
'version|v' => \$version,
|
|
|
72 |
'svn|s=s' => \$svn,
|
|
|
73 |
'repo|r=s' => \$repository,
|
|
|
74 |
'target|t=s' => \$targetDir,
|
|
|
75 |
'seed=s' => \$seedFileURL
|
|
|
76 |
) or die "Error parsing command line\n";
|
|
|
77 |
|
|
|
78 |
if ( $help ) { &help() ; exit; }
|
|
|
79 |
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
|
|
|
80 |
unless ( $svn ) {
|
|
|
81 |
$svn = `which svn`;
|
|
|
82 |
chomp $svn;
|
|
|
83 |
}
|
|
|
84 |
die "Could not locate svn command\n" unless $svn;
|
204 |
rodolico |
85 |
die "This installer requires subversion, and it is not found on this system\n" unless `$svn --version --quiet`;
|
203 |
rodolico |
86 |
|
211 |
rodolico |
87 |
$os = $^O unless $os;
|
203 |
rodolico |
88 |
|
|
|
89 |
$targetDir = $operatingSystems{$os} unless $targetDir;
|
211 |
rodolico |
90 |
die "Can not determine targetDirectory for operating system $os, aborting\n" unless $targetDir;
|
203 |
rodolico |
91 |
|
204 |
rodolico |
92 |
# the directory exists and is not an svn repo, so move it
|
|
|
93 |
if ( -e $targetDir && system( "svn info $targetDir >/dev/null 2>&1" ) ) {
|
|
|
94 |
print "$targetDir exists and is not an svn URL; moving to $targetDir.backup\n";
|
|
|
95 |
`mv $targetDir $targetDir.backup` unless $dryRun;
|
|
|
96 |
}
|
|
|
97 |
if ( -d $targetDir ) { # target is a directory, and an svn repo
|
|
|
98 |
print "Performing an update on $targetDir\n";
|
|
|
99 |
`svn update $targetDir` unless $dryRun;
|
206 |
rodolico |
100 |
} else { # doesn't exist, so create and do a checkout
|
204 |
rodolico |
101 |
print "Creating target directory $targetDir\n";
|
206 |
rodolico |
102 |
`mkdir -p $targetDir` unless -d $targetDir || $dryRun; # verify the target directory exists
|
208 |
rodolico |
103 |
print "Installing into $targetDir using $svn checkout $repository to $targetDir\n";
|
204 |
rodolico |
104 |
`$svn checkout $repository $targetDir` unless $dryRun;
|
|
|
105 |
}
|
214 |
rodolico |
106 |
|
208 |
rodolico |
107 |
if ( $seedFileURL && ! $dryRun ) {
|
221 |
rodolico |
108 |
my $seedFileName = $targetDir . '/installer/sysinfo-client.seed.yaml';
|
208 |
rodolico |
109 |
print "Downloading seed file from $seedFileURL to $seedFileName\n";
|
|
|
110 |
`wget --quiet --output-document=$seedFileName $seedFileURL`;
|
|
|
111 |
die "Error downloading $seedFileURL into $seedFileName\n" if $?;
|
221 |
rodolico |
112 |
$configurationTool .= " --seed $seedFileName";
|
203 |
rodolico |
113 |
}
|
|
|
114 |
|
208 |
rodolico |
115 |
$libraryFile = "$targetDir/$libraryFile";
|
|
|
116 |
|
|
|
117 |
if ( -f $libraryFile ) {
|
|
|
118 |
# load the definitions from installer_config.pl
|
|
|
119 |
do $libraryFile;
|
|
|
120 |
print "Success loading library file\n";
|
|
|
121 |
} else {
|
|
|
122 |
die "Could not load library file from $libraryFile\nAborting installation\n";
|
|
|
123 |
}
|
|
|
124 |
|
211 |
rodolico |
125 |
print "Now running $targetDir/$configurationTool\n";
|
|
|
126 |
exec( "$targetDir/$configurationTool" ) unless $dryRun;
|
204 |
rodolico |
127 |
#https://metacpan.org/pod/Hash%3a%3aMerge
|
|
|
128 |
|
203 |
rodolico |
129 |
1;
|