Subversion Repositories camp_sysinfo_client_3

Rev

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 \
11
#      --repo=http://svn.dailydata.net/svn/camp_sysinfo_client_3/trunk \
12
#      --target ~/test \
13
#      --seed=http://phantom.dailydata.net/uploadFiles299q/sysinfo-client.seed.yaml
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
 
25
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
26
my $repository = 'http://svn.dailydata.net/svn/camp_sysinfo_client_3/tags/stable';
27
my $svn = '';
28
my $dryRun = 0;
29
my $os;
30
my $help = 0;
31
my $version = 0;
32
my $targetDir;
33
my $seedFileURL;
34
 
35
 
36
# simple display if --help is passed
37
sub help {
38
   my $oses = join( ', ', keys %operatingSystems );
39
   use File::Basename;
40
   print basename($0) . " $VERSION\n";
41
   print <<END
42
$0 [options]
43
Options:
44
   --os      - osname, one of [$oses]
45
   --dryrun  - do not actually do anything, just tell you what I'd do
46
   --version - display version and exit
47
   --svn     - path to svn command
48
   --repo    - full URL of subversion repository
49
   --target  - Target directory for installation
50
   --seed    - URL to download a seed file for new installs
51
END
52
}
53
 
54
 
55
################################################################
56
#               Main Code                                      #
57
################################################################
58
 
59
# handle any command line parameters that may have been passed in
60
 
61
GetOptions (
62
            "os|o=s"      => \$os,      # pass in the operating system
63
            "dryrun|n"    => \$dryRun,  # do NOT actually do anything
64
            'help|h'      => \$help,
65
            'version|v'   => \$version,
66
            'svn|s=s'     => \$svn,
67
            'repo|r=s'    => \$repository,
68
            'target|t=s'  => \$targetDir,
69
            'seed=s'      => \$seedFileURL
70
            ) or die "Error parsing command line\n";
71
 
72
if ( $help ) { &help() ; exit; }
73
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
74
unless ( $svn ) {
75
   $svn = `which svn`;
76
   chomp $svn;
77
   }
78
die "Could not locate svn command\n" unless $svn;
79
die "This installer requires subvsion, and it is not found on this system\n" unless `$svn --version --quiet`;
80
 
81
$os = `uname` unless $os;
82
$os = lc $os;
83
chomp $os;
84
 
85
$targetDir = $operatingSystems{$os} unless $targetDir;
86
 
87
# if the target directory is NOT an svn repository, we want to 
88
# move it out of the way.
89
my $eraseOld = `svn info $target >/dev/null 2>&1` ? 0 : 1;
90
 
91
if ( $dryRun ) {
92
   print "Dry Run!!\nDownloading sysinfo\nfrom $repository\nusing $svn\ninto $targetDir\n";
93
   print "Using seed file from $seedFileURL\n" if $seedFileURL;
94
} else {
95
   `mkdir -p $targetDir`; # verify the target directory exists
96
   `$svn co $repository $targetDir`;
97
   if ( $seedFileURL ) {
98
      my $seedFileName = $targetDir . '/sysinfo-client.seed.yaml';
99
      `wget --output-document=$seedFileName $seedFileURL`;
100
   }
101
}
102
 
103
1;