Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
   );
208 rodolico 24
 
25
# location of the installer library so we can set stuff up correctly
26
my $libraryFile = 'installer/installer_config.pl';
203 rodolico 27
 
206 rodolico 28
my $configurationTool = 'installer/install --quiet --inplace';
204 rodolico 29
 
203 rodolico 30
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
31
my $repository = 'http://svn.dailydata.net/svn/camp_sysinfo_client_3/tags/stable';
32
my $svn = '';
33
my $dryRun = 0;
34
my $os;
35
my $help = 0;
36
my $version = 0;
37
my $targetDir;
38
my $seedFileURL;
39
 
40
 
41
# simple display if --help is passed
42
sub help {
43
   my $oses = join( ', ', keys %operatingSystems );
44
   use File::Basename;
45
   print basename($0) . " $VERSION\n";
46
   print <<END
47
$0 [options]
48
Options:
49
   --os      - osname, one of [$oses]
50
   --dryrun  - do not actually do anything, just tell you what I'd do
51
   --version - display version and exit
52
   --svn     - path to svn command
53
   --repo    - full URL of subversion repository
54
   --target  - Target directory for installation
55
   --seed    - URL to download a seed file for new installs
56
END
57
}
58
 
59
 
60
################################################################
61
#               Main Code                                      #
62
################################################################
63
 
64
# handle any command line parameters that may have been passed in
65
 
66
GetOptions (
67
            "os|o=s"      => \$os,      # pass in the operating system
68
            "dryrun|n"    => \$dryRun,  # do NOT actually do anything
69
            'help|h'      => \$help,
70
            'version|v'   => \$version,
71
            'svn|s=s'     => \$svn,
72
            'repo|r=s'    => \$repository,
73
            'target|t=s'  => \$targetDir,
74
            'seed=s'      => \$seedFileURL
75
            ) or die "Error parsing command line\n";
76
 
77
if ( $help ) { &help() ; exit; }
78
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
79
unless ( $svn ) {
80
   $svn = `which svn`;
81
   chomp $svn;
82
   }
83
die "Could not locate svn command\n" unless $svn;
204 rodolico 84
die "This installer requires subversion, and it is not found on this system\n" unless `$svn --version --quiet`;
203 rodolico 85
 
86
$os = `uname` unless $os;
87
$os = lc $os;
88
chomp $os;
89
 
90
$targetDir = $operatingSystems{$os} unless $targetDir;
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
}
208 rodolico 106
if ( $seedFileURL && ! $dryRun ) {
107
   my $seedFileName = $targetDir . '/installer/sysinfo-client.seed.yaml';
108
   print "Downloading seed file from $seedFileURL to $seedFileName\n";
109
   `wget --quiet --output-document=$seedFileName $seedFileURL`;
110
   die "Error downloading $seedFileURL into $seedFileName\n" if $?;
203 rodolico 111
}
112
 
208 rodolico 113
$libraryFile = "$targetDir/$libraryFile";
114
 
115
if ( -f $libraryFile ) {
116
   # load the definitions from installer_config.pl
117
   do $libraryFile;
118
   print "Success loading library file\n";
119
} else {
120
   die "Could not load library file from $libraryFile\nAborting installation\n";
121
}
122
 
206 rodolico 123
print "Starting up $configurationTool\n";
204 rodolico 124
 
206 rodolico 125
 
126
print "Now run $targetDir/$configurationTool\n";
207 rodolico 127
#exec( "$targetDir/$configurationTool" ) unless $dryRun;
204 rodolico 128
#https://metacpan.org/pod/Hash%3a%3aMerge
129
 
130
#check for all the necessary libraries and install
131
#set cron job
132
#merge seedFile with any existing configuration file and save
133
#message to user to run configure.pl
134
 
203 rodolico 135
1;