#! /usr/bin/env perl use warnings; use strict; # 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; use Getopt::Long; use File::Basename; our $DEBUG; our $dryRun; my $quiet = 0; my $help = 0; my $version = 0; my $os; my $VERSION = '1.0.2'; sub help { print basename($0) . " $VERSION\n"; print <catdir($FindBin::Bin) ); my $binDir = abs_path("$scriptDir/../"); # bin directory assumed to be above this one my $runPeriodicFlag = 'touch /tmp/sysinfo.firstrun'; # this is a flag that says to go ahead and run periodic scripts sub checkDirectory { my $directory = shift; print "In checkDirectory, looking in $directory\n" if $DEBUG; my @dirs; if ( -d $directory ) { # we found a modules directory opendir( my $dh, $directory ) || die "Could not read from $scriptDir/modules:$!\n"; @dirs = grep { -f "$directory/$_" } readdir($dh); closedir $dh; } #die "dirs is " . join("\n", @dirs ) . "\n"; while ( my $script = shift(@dirs) ) { next if $script =~ /\..+$/; # ignore anything with a period in it next if $script =~ /README/; # ignore readme print "Checking $directory/$script\n" if $DEBUG; if ( $dryRun ) { print "Dry-run: would probe $directory/$script\n" if ( $DEBUG || !$quiet ); next; } &runCommand( $runPeriodicFlag ); # ensure we will attempt to run all periodic scripts also &runCommand( "chmod 755 $directory/$script" ); my $output = `$directory/$script $directory`; my $mod = $output ? '700' : '600'; &runCommand( "chmod $mod $directory/$script" ); } } # setting permissions my %su = ( 'debian' => 'root:root', 'freebsd' => 'root:wheel', 'opnsense' => 'root:wheel' ); Getopt::Long::Configure ("bundling"); GetOptions ( "os|o=s" => \$os, "dryrun|n" => \$dryRun, 'quiet|q' => \$quiet, 'help|h' => \$help, 'version|v' => \$version, 'debug!' => \$DEBUG ) or die "Error parsing command line\n"; if ( $help ) { &help(); exit; } if ( $version ) { print basename($0) . " $VERSION\n"; exit; } $os = `$scriptDir/determineOS` unless $os; chomp $os if defined $os; die "Could not determine operating system\n" unless $os; my $owner = $su{$os} ? $su{$os} : 'root:root'; print "Setting ownership for $os as $owner\n" unless $quiet; &runCommand( "chown -fR $owner $binDir" ); &runCommand( "chmod 700 $binDir/sysinfo_client" ); &runCommand( "chmod 700 $binDir/configure" ); &checkDirectory( "$binDir/modules" );