/usr/share/metainit/utils/arrange-sysvinit is in metainit 0.0.5.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | #!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(sum);
my $prefix = "";
$prefix = $ENV{METAINIT_PREFIX} if $ENV{METAINIT_PREFIX};
my $metainit_path = "$prefix/etc/metainit";
my $etc = "$prefix/etc";
use MetaInit::Parse;
my @new_scripts = @ARGV;
my %facilities = (
'$local_fs' => 0,
'$network' => 0,
'$named' => 15,
'$portmap' => 18,
'$remote_fs' => 21,
'$syslog' => 10,
'$time' => 0,
);
# Read in all meta-init scripts
my @metainit_files = <$metainit_path/*.metainit>;
my %metainits;
for my $metainit_file (@metainit_files) {
my $data = MetaInit::Parse::parse({ filename => $metainit_file });
$metainits{$data->{Name}} = $data;
}
# Locate existing scripts
# We check for existing scripts only in /etc/rc2.d
my %startscripts;
for my $rc_file (<$etc/rc2.d/S??*>) {
my ($num, $name) = $rc_file =~ m!S(\d\d)([^/]+)!;
$startscripts{$name} = $num;
}
# Sort the scripts to existing and non-existing scripts
my @existing;
my @new;
for my $metainit (keys %metainits) {
if (exists $startscripts{$metainit}) {
push @existing, $metainit;
} else {
push @new, $metainit;
}
}
# Actually, we only want to treat the passed scripts as new
@new = @new_scripts;
# Check the dependencies for existing scripts
for my $existing (@existing) {
my @deps = @{$metainits{$existing}{"Required-Start"}};
for my $dep (@deps) {
if (exists $startscripts{$dep}) {
if ($startscripts{$dep} >= $startscripts{$existing}) {
warn "Late dependency $dep of $existing.\n"
}
} elsif (exists $facilities{$dep}) {
if ($facilities{$dep} >= $startscripts{$existing}) {
warn "Late facility $dep of $existing.\n"
}
} elsif (not exists $startscripts{$dep}){
# Nothing to do here
} else {
warn "Unkown dependency $dep of $existing.\n";
}
}
}
my @processed = ();
while (@new > 0) {
# Check Bounds
my %lower;
my %upper;
for my $existing (@existing) {
my @deps = @{$metainits{$existing}{"Required-Start"}};
for my $dep (@deps) {
if (exists $startscripts{$dep}){
$upper{$dep} = min($startscripts{$existing}, $upper{$dep})
}
}
}
for my $new (@new) {
my @deps = @{$metainits{$new}{"Required-Start"}};
for my $dep (@deps) {
if (not exists $startscripts{$dep}){
$lower{$new} = $startscripts{$dep};
$lower{$new} = max($startscripts{$dep}, $lower{$new})
}
}
}
# Put a new scripts at appropriate location
my $current = pop @new;
# Standard case:
if (($lower{$current}||0) > ($upper{$current}||99)) {
warn "Could not correctly fit in $current, please reorder manually.\n";
$startscripts{$current} = $lower{$current}||10 + 10;
push @processed, $current;
push @existing, $current;
} elsif (($lower{$current}||0 < 20) and not defined $upper{$current}) {
$startscripts{$current} = 20;
push @processed, $current;
push @existing, $current;
} else {
$startscripts{$current} = mid($lower{$current}, $upper{$current});
}
}
for my $done (@processed) {
printf "%s %02d\n", $done, $startscripts{$done}
}
sub max {
return $_[1] if (defined $_[1] and $_[0] < $_[1]);
return $_[0]
}
sub min {
return $_[1] if (defined $_[1] and $_[0] > $_[1]);
return $_[0]
}
sub mid {
return sum(@_) / scalar @_;
}
# vim: sw=4:ts=4:expandtab
|