Rev 221 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#! /usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
# used as a small file to download and install sysinfo client
# perl install_sysinfo_client.pl \
# --dryRun \
# --repo=http://svn.dailydata.net/svn/camp_sysinfo_client_3/tags/stable \
# --target ~/test \
# --seed=http://example.com/private/sysinfo-client.seed.yaml
# define the version number
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
use version;
our $VERSION = version->declare("v1.001.002");
my %operatingSystems = (
'linux' => '/opt/camp/sysinfo-client',
'freebsd' => '/usr/local/opt/camp/sysinfo-client'
);
# location of the installer library so we can set stuff up correctly
my $libraryFile = 'installer/installer_config.pl';
my $configurationTool = 'installer/install --quiet';
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
my $repository = 'http://svn.dailydata.net/svn/camp_sysinfo_client_3/tags/stable';
my $svn = '';
my $dryRun = 0;
my $os;
my $help = 0;
my $version = 0;
my $targetDir;
my $seedFileURL;
# simple display if --help is passed
sub help {
my $oses = join( ', ', keys %operatingSystems );
use File::Basename;
print basename($0) . " $VERSION\n";
print <<END
$0 [options]
Options:
--os - osname, one of [$oses]
--dryrun - do not actually do anything, just tell you what I'd do
--version - display version and exit
--svn - path to svn command
--repo - full URL of subversion repository
--target - Target directory for installation
--seed - URL to download a seed file for new installs
END
}
################################################################
# Main Code #
################################################################
# handle any command line parameters that may have been passed in
GetOptions (
"os|o=s" => \$os, # pass in the operating system
"dryrun|n" => \$dryRun, # do NOT actually do anything
'help|h' => \$help,
'version|v' => \$version,
'svn|s=s' => \$svn,
'repo|r=s' => \$repository,
'target|t=s' => \$targetDir,
'seed=s' => \$seedFileURL
) or die "Error parsing command line\n";
if ( $help ) { &help() ; exit; }
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
unless ( $svn ) {
$svn = `which svn`;
chomp $svn;
}
die "Could not locate svn command\n" unless $svn;
die "This installer requires subversion, and it is not found on this system\n" unless `$svn --version --quiet`;
$os = $^O unless $os;
$targetDir = $operatingSystems{$os} unless $targetDir;
die "Can not determine targetDirectory for operating system $os, aborting\n" unless $targetDir;
# the directory exists and is not an svn repo, so move it
if ( -e $targetDir && system( "svn info $targetDir >/dev/null 2>&1" ) ) {
print "$targetDir exists and is not an svn URL; moving to $targetDir.backup\n";
`mv $targetDir $targetDir.backup` unless $dryRun;
}
if ( -d $targetDir ) { # target is a directory, and an svn repo
print "Performing an update on $targetDir\n";
`svn update $targetDir` unless $dryRun;
} else { # doesn't exist, so create and do a checkout
print "Creating target directory $targetDir\n";
`mkdir -p $targetDir` unless -d $targetDir || $dryRun; # verify the target directory exists
print "Installing into $targetDir using $svn checkout $repository to $targetDir\n";
`$svn checkout $repository $targetDir` unless $dryRun;
}
if ( $seedFileURL && ! $dryRun ) {
my $seedFileName = $targetDir . '/installer/sysinfo-client.seed.yaml';
print "Downloading seed file from $seedFileURL to $seedFileName\n";
`wget --quiet --output-document=$seedFileName $seedFileURL`;
die "Error downloading $seedFileURL into $seedFileName\n" if $?;
$configurationTool .= " --seed $seedFileName";
}
$libraryFile = "$targetDir/$libraryFile";
if ( -f $libraryFile ) {
# load the definitions from installer_config.pl
do $libraryFile;
print "Success loading library file\n";
} else {
die "Could not load library file from $libraryFile\nAborting installation\n";
}
print "Now running $targetDir/$configurationTool\n";
exec( "$targetDir/$configurationTool" ) unless $dryRun;
#https://metacpan.org/pod/Hash%3a%3aMerge
1;