Rev 236 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#! /usr/bin/env perl
use strict;
use warnings;
# find our location and use it for searching for libraries
BEGIN {
use FindBin;
use File::Spec;
# use libraries from the directory this script is in
use lib File::Spec->catdir($FindBin::Bin);
# and its parent
use lib File::Spec->catdir( $FindBin::Bin . '/../' );
eval( 'use YAML::Tiny' );
}
use Cwd qw(abs_path);
use sysinfosetup;
my $scriptDir = abs_path(File::Spec->catdir($FindBin::Bin) );
use Digest::MD5 qw(md5_hex);
use File::Copy;
# define the version number
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
use version;
our $VERSION = version->declare("v0.001.001");
use Data::Dumper;
use File::Basename;
use Getopt::Long;
Getopt::Long::Configure ("bundling"); # allow -vd --os='debian'
our $dryRun;
our $DEBUG;
my $os;
my $help = 0;
my $version = 0;
my $quiet = 0;
my $seedFileName = '';
# simple display if --help is passed
sub help {
use File::Basename;
print basename($0) . " $VERSION\n";
print <<END
$0 [options]
Options:
--os|-o - lower case name of operating system (debian, freebsd, etc...)
--dryrun|-n - do not actually do anything, just tell you what I'd do
--version|-v - display version and exit
--quiet|-q - Do not ask questions, just do stuff
--help|-g - Show this screen
--seed|-s - URL/Path to seed file for config
--debug - Show extra information (--nodebug is default)
END
}
# returns 0 on success, so call with
# if ( my $return = &doCommand $command ) {
# failure code
# } else {
# success code
# }
#
sub doCommand {
my $command = shift;
system $command;
if ($? == -1) { # Could not even find the file?? Or not executable
return -1;
}
elsif ($? & 127) { # major failure with, possibly, code dump
return $? & 127;
} else { # we had some kind of failure, just return the failure code
return $? >> 8;
}
return 0;
}
################################################################
# 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
"seed|s=s" => \$seedFileName,
'help|h' => \$help,
'version|v' => \$version,
'quiet|q' => \$quiet,
'debug!' => \$DEBUG
) or die "Error parsing command line\n";
if ( $help ) { &help() ; exit; }
if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; }
my $returnValue = 0;
# first, find operating system
my $command = $scriptDir . '/determineOS';
$os = `$command` unless $os;
&logIt( "Detected operating system is [$os]" );
die "Could not detect operation system\n" unless $os;
# now, verify we have all the libraries we need and install them if necessary
$command = $scriptDir . '/validateDependencies'
. " -o $os"
. ( $quiet ? ' -q' : '' )
. ( $DEBUG ? ' --debug' : '')
. ( $dryRun ? ' -n' : '' );
&logIt( "Running command $command" );
if ( doCommand( $command ) ) {
die "I had an error executing $command\n";
}
&logIt( "\tReturn value is $returnValue" );
$command = $scriptDir . '/checkFiles'
. " -o $os"
. ( $quiet ? ' -q' : '' )
. ( $DEBUG ? ' --debug' : '')
. ( $dryRun ? ' -n' : '')
. ( $seedFileName ? " -s $seedFileName " : '' );
&logIt( "Running command $command" );
if ( doCommand( $command ) ) {
die "I had an error executing $command\n";
}
&logIt( "\tReturn value is $returnValue" );
# check permissions
$command = $scriptDir . '/permissions';
&logIt( "Running command $command" );
if ( doCommand( $command ) ) {
die "I had an error executing $command\n";
}
# run configure
$command = $scriptDir . "/../configure"
. ( $quiet ? ' -q' : '' )
. ( $DEBUG ? ' --debug' : '')
. ( $dryRun ? ' -n' : '' );
&logIt( "Running command $command" );
if ( doCommand( $command ) ) {
die "I had an error executing $command\n";
}
&logIt( "\tReturn value is $returnValue" );
Generated by GNU Enscript 1.6.5.90.