#!/usr/bin/perl
use NOCpulse::Object;
use lib qw(/etc/rc.d/np.d);
use RootOnlyPlease;
use NOCpulse::Config;
use NOCpulse::Debug;
use SysVStep;

$NOCpulse::Object::config = NOCpulse::Config->new('/etc/rc.d/np.d/SysV.ini');
my $debug = NOCpulse::Debug->new; # default debug object
$debug->addstream(LEVEL=>1)->timestamps(1);
$debug->addstream(LEVEL=>1,
                FILE=>SysVStep->ConfigValue('logFileName'),
                APPEND=>1)->timestamps(1);

my $stepName = shift(@ARGV);
$stepName =~ s/(.*)\.pm/$1/g;

eval "require($stepName)";
if ($@) {
        $debug->dprint(1,"MODULE LOAD FAILED: $@\n");
        exit(1);
}
my $exitlevel;
eval {$exitlevel = $stepName->newInitialized()->run() };
if ($@) {
        $debug->dprint(1,"!!!!!!!!!! STEP $stepName EXECUTION FAILED: $@\n");
        exit(1);
}
exit($exitlevel);
