#! /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) ); my $binDir = abs_path("$scriptDir/../"); 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 = ''; our %operatingSystems; # simple display if --help is passed sub help { use File::Basename; print basename($0) . " $VERSION\n"; print < \$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; } # find OS if they did not tell us what it was $os = `$scriptDir/determineOS` unless $os; print "Installing Conf and Cron for $os\n" unless $quiet; my $returnValue = 0; my $command; # load the definitions from installer_config.pl do "$scriptDir/installer_config.pl"; our %libraries; our %install; our %binaries; if ( $seedFileName =~ m~^(((http)|(ftp))s?://).+$~ ) { # the seed file is a URL $command = "wget -O /tmp/seedfile --no-check-certificate $seedFileName"; print "Downloading from $seedFileName\n\t$command\n" unless $quiet; `$command` unless $dryRun; $seedFileName = '/tmp/seedfile'; } # Check for configuration file my $configDir = $operatingSystems{ $os }{'confdir'}; unless ( -d $configDir ) { $command = "mkdir -p $configDir"; print "Creating $configDir\n\t$command\n" unless $quiet; `$command` unless $dryRun; } my $configFile = $operatingSystems{'configuration file'}; $configFile =~ s//$configDir/; unless ( -f $configFile ) { $seedFileName = "$scriptDir/sysinfo-client.conf.template.yaml" unless $seedFileName; $command = "cp $seedFileName $configFile"; print "Creating $configFile\n\t$command\n" unless $quiet; `cp $seedFileName $configFile` unless $dryRun; } # check for cron file(s) if ( defined( $operatingSystems{$os}{'crontab'} ) ) { my $command = $operatingSystems{$os}{'crontab'}; $command =~ s//$binDir/; $command =~ s//$scriptDir/g; print "Setting up cron\n\t$command\n" unless $quiet; `$command` unless $dryRun; }