Subversion Repositories camp_sysinfo_client_3

Rev

Rev 229 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
223 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
6
# find our location and use it for searching for libraries
7
BEGIN {
8
   use FindBin;
9
   use File::Spec;
10
   # use libraries from the directory this script is in
11
   use lib File::Spec->catdir($FindBin::Bin);
12
   # and its parent
13
   use lib File::Spec->catdir( $FindBin::Bin . '/../' );
14
   eval( 'use YAML::Tiny' );
15
}
16
 
17
use Cwd qw(abs_path);
18
use sysinfosetup;
19
 
20
my $scriptDir = abs_path(File::Spec->catdir($FindBin::Bin) );
21
 
22
use Digest::MD5 qw(md5_hex);
23
use File::Copy;
24
 
25
# define the version number
26
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
27
use version;
28
our $VERSION = version->declare("v0.001.001");
29
 
30
 
31
use Data::Dumper;
32
use File::Basename;
33
use Getopt::Long;
34
 
35
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
36
our $dryRun;
37
our $DEBUG;
38
my $os;
39
my $help = 0;
40
my $version = 0;
41
my $quiet = 0;
42
my $seedFileName = '';
43
 
44
# simple display if --help is passed
45
sub help {
46
   use File::Basename;
47
   print basename($0) . " $VERSION\n";
48
   print <<END
49
$0 [options]
50
Options:
51
   --os|-o      - lower case name of operating system (debian, freebsd, etc...)
52
   --dryrun|-n  - do not actually do anything, just tell you what I'd do
53
   --version|-v - display version and exit
54
   --quiet|-q   - Do not ask questions, just do stuff
55
   --help|-g    - Show this screen
56
   --seed|-s    - URL/Path to seed file for config
57
   --debug      - Show extra information (--nodebug is default)
58
END
59
}
60
 
61
 
236 rodolico 62
# returns 0 on success, so call with
63
# if ( my $return = &doCommand $command ) {
64
#    failure code
65
# } else {
66
#    success code
67
# }
68
# 
69
sub doCommand {
70
   my $command = shift;
71
   system $command;
72
   if ($? == -1) { # Could not even find the file?? Or not executable
73
       return -1;
74
   }
75
   elsif ($? & 127) { # major failure with, possibly, code dump
76
       return $? & 127;
77
   } else { # we had some kind of failure, just return the failure code
78
       return $? >> 8;
79
   }
80
   return 0;
81
}
82
 
223 rodolico 83
################################################################
84
#               Main Code                                      #
85
################################################################
86
 
87
# handle any command line parameters that may have been passed in
88
 
89
GetOptions (
90
            "os|o=s"      => \$os,      # pass in the operating system
91
            "dryrun|n"    => \$dryRun,  # do NOT actually do anything
92
            "seed|s=s"    => \$seedFileName,
93
            'help|h'      => \$help,
94
            'version|v'   => \$version,
95
            'quiet|q'     => \$quiet,
96
            'debug!'      => \$DEBUG
97
            ) or die "Error parsing command line\n";
98
 
99
if ( $help ) { &help() ; exit; }
100
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
101
 
102
my $returnValue = 0;
103
 
104
# first, find operating system
105
my $command = $scriptDir . '/determineOS';
106
$os = `$command` unless $os;
107
&logIt( "Detected operating system is [$os]" );
108
 
109
die "Could not detect operation system\n" unless $os;
110
# now, verify we have all the libraries we need and install them if necessary
111
$command = $scriptDir . '/validateDependencies'
112
            . " -o $os" 
113
            . ( $quiet ? ' -q' : '' ) 
114
            . ( $DEBUG ? ' --debug' : '')
115
            . ( $dryRun ? ' -n' : '' );
116
&logIt( "Running command $command" );
236 rodolico 117
if ( doCommand( $command ) ) {
118
   die "I had an error executing $command\n";
119
}
223 rodolico 120
&logIt( "\tReturn value is $returnValue" );
121
 
225 rodolico 122
$command = $scriptDir . '/checkFiles'
123
            . " -o $os" 
124
            . ( $quiet ? ' -q' : '' ) 
125
            . ( $DEBUG ? ' --debug' : '')
126
            . ( $dryRun ? ' -n' : '')
127
            . ( $seedFileName ? " -s $seedFileName " : '' );
128
&logIt( "Running command $command" );
236 rodolico 129
if ( doCommand( $command ) ) {
130
   die "I had an error executing $command\n";
131
}
225 rodolico 132
&logIt( "\tReturn value is $returnValue" );
133
 
229 rodolico 134
# check permissions
135
$command = $scriptDir . '/permissions';
136
&logIt( "Running command $command" );
236 rodolico 137
if ( doCommand( $command ) ) {
138
   die "I had an error executing $command\n";
139
}
225 rodolico 140
 
229 rodolico 141
# run configure
223 rodolico 142
$command = $scriptDir . "/../configure"
143
            . ( $quiet ? ' -q' : '' ) 
144
            . ( $DEBUG ? ' --debug' : '')
229 rodolico 145
            . ( $dryRun ? ' -n' : '' );
223 rodolico 146
&logIt( "Running command $command" );
236 rodolico 147
if ( doCommand( $command ) ) {
148
   die "I had an error executing $command\n";
149
}
223 rodolico 150
&logIt( "\tReturn value is $returnValue" );