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

$NOCpulse::Object::config = NOCpulse::Config->new('/etc/rc.d/np.d/SysV.ini');
$SysVStep::LibMode=1;
my $regdir = SysVStep->ConfigValue('registry');
my $stepName;
my @stepNames;
opendir(DIR,$regdir);
while ($stepName = readdir(DIR)) {
	if ($stepName !~ /^\./) {
		push(@stepNames,$stepName);
	}
}
closedir(DIR);
foreach $stepName (@stepNames) {
	eval "require($stepName)";
	if ($@) {
		print "$@\n";
		exit;
	}
	$stepName->newInitialized()->registerForInstall;
}
# At this point the final list of what needs to be installed
# is in the registry (and in memory) so we go through it again...
opendir(DIR,$regdir);
while ($stepName = readdir(DIR)) {
	if ($stepName !~ /^\./) {
		print "Installing $stepName\n";
		$stepName->newInitialized()->installSysVLinks;
	}
}
closedir(DIR);
