#! /usr/bin/perl $name = $0; $name =~ s/.*\///o; @level = ("0", "1", "2", "3", "4", "5", "6"); @leveldir = ( "/etc/rc0.d", "/etc/rc1.d", "/etc/rc2.d", "/etc/rc3.d", "/etc/rc4.d", "/etc/rc5.d", "/etc/rc6.d" ); $rc = 0; parse_args(); $ignore = ". .. README skeleton single halt boot reboot"; opendir (INIT, "/etc/init.d") || die "Can't read /etc/init.d: $?"; while (defined($file = readdir(INIT))) { if ($ignore !~ /$file/) { $conf{$file} = ""; $max = length($file) if (length($file) > $max); } } closedir (INIT); opendir (BOOT, "/etc/rc.boot") || die "Can't read /etc/rc.boot: $!"; while (defined($file = readdir(BOOT))) { if ($ignore !~ /$file/) { $bootfiles .= "$file "; } } chop $bootfiles; for ($i = 0; $i <= $#level; $i++) { opendir(RC, $leveldir[$i]) || die "Can't read $leveldir[$i]: $?"; while(defined($file = readdir(RC))) { if ($ignore !~ /$file/) { $stripped = $file; $stripped =~ s/^[SK](\d+)//og; $file =~ /^([SK]\d+)/o; $priority[$i]{$stripped} = $1; if ($1 =~ /^S/o) { $runlvl{$stripped} .= $level[$i]; } else { $offlvl{$stripped} .= $level[$i]; } } } closedir(RC); } if ($activeflag && !defined($conf{$activeflag})) { print STDERR "No such flag: $activeflag\nUse '$name -f' to create.\n\n"; exit(254); } foreach $prog (keys(%conf)) { for ($i = 0; $i <= $#level; $i++) { $priority[$i]{$prog} = "-" if (!defined($priority[$i]{$prog})); } if (defined($runlvl{$prog})) { if ($verbose) { $conf{$prog} = $runlvl{$prog}; $offlvl{$prog} = "-" if (!defined($offlvl{$prog})); } else { $conf{$prog} = "On"; } } else { if ($verbose) { $conf{$prog} = $offlvl{$prog} = "-" ; } else { $conf{$prog} = "Off"; } } } if (!defined($activeflag)) { if ($verbose) { print " Flag" . pad($max) . "rl0 rl1 rl2 rl3 rl4 rl5 rl6\n"; print " ====" . pad($max) . "=== === === === === === ===\n\n"; } else { print " Flag" . pad($max) . "State (when multiuser)\n"; print " ====" . pad($max) . "======================\n\n"; } } $check = !defined($activeflag) || $showstate || $verbose; while (($flag, $state) = each (%conf)) { if (!defined($activeflag) || $activeflag eq $flag) { if ($check) { print " $flag" . pad($max + 4 - length($flag)); if (!$verbose) { print $state; } else { foreach $i (0, 1, 2, 3, 4, 5, 6) { print $priority[$i]{$flag} . pad(4 - length($priority[$i]{$flag})); } } } $rc = 1 if (defined($runlvl{$flag})); print "\n" if ($check); } } print "\n" if ($check); if (!defined($activeflag)) { print "Active at boot time: $bootfiles\n\n"; $rc = 0; } exit($rc); sub pad { my $len = shift; my $i; my $out = ""; for ($i = 0; $i < $len; $i++) { $out .= " "; } $out; } sub parse_args { my $len, $cur; my $i, $args; $args = $#ARGV; if (lc($ARGV[$args]) eq "on") { syntax() if ($args == 0 || $ARGV[$args - 1] =~ /\-/o); $args -= 2; $activeflag = $on = $ARGV[$args - 1]; } elsif (lc($ARGV[$args]) eq "off") { syntax() if ($args == 0 || $ARGV[$args - 1] =~ /\-/o); $args -= 2; $activeflag = $off = $ARGV[$args - 1]; } elsif ($ARGV[$#ARGV] !~ /\-/o) { $activeflag = $ARGV[$#ARGV]; $args --; } $#ARGV = $args; foreach $arg (@ARGV) { syntax() if ($arg != /\-/); $i = 1; $len = length($arg); while ($i < $len) { $cur = substr($arg, $i, 1); if ($cur eq "v") { $verbose = 1; $i++; } else { syntax(); } } } syntax if ($force && !defined($activeflag)); } sub syntax { print "\n$name 1.0 - check init runlevel configuration\n\n"; print "Distributed under the STPL - see LICENCE file for details\n"; print "Syntax: $name [-v] [flag] View state (-v = verbose)\n"; print "\nIf flag is specified, returns 1 if flag is on when multiuser,\n"; print " 0 otherwise\n"; print "\n"; exit(255); }