#! /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; our $DEBUG; $DEBUG = 1; my $scriptDir = abs_path(File::Spec->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"; 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"; &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' ); my $os = `./determineOS`; my $owner = $su{$os} ? $su{$os} : 'root:root'; &runCommand( "chown -fR $owner $binDir" ); &runCommand( "chmod 700 $binDir/sysinfo-client" ); &runCommand( "chmod 700 $binDir/configure" ); &checkDirectory( "$binDir/modules" );