-
Notifications
You must be signed in to change notification settings - Fork 1
/
vera-rcm
52 lines (40 loc) · 992 Bytes
/
vera-rcm
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
#! /usr/bin/perl
#
# Modify /etc/rc.d/rc.M and /etc/rc.d/rc.inet2 on the fly.
#
# Replace all instances of "/etc/rc.d/rc.SOMETHING start" with
# "vlad start system/rc.M/rc.SOMETHING", if this unit file exists.
use strict;
use warnings;
use IO::File;
my ($unitdir, $rc_m) = @ARGV;
my $fh = IO::File->new($rc_m, "r");
my $l;
sub repl {
my ($pfix, $word,$start) = @_;
my $unit = $word;
# ip_forward => ip-forward
$unit =~ s/_/-/g;
if ($unit =~ m{^/etc/rc.d/(.*)} &&
-f "$unitdir/system/rc.M/$1")
{
return "vlad start system/rc.M/$1";
}
return ($pfix // '') . "$word$start";
}
while (defined($l = <$fh>))
{
# /etc/rc.d/rc.inet2 in /etc/rc.d/rc.M will run me again.
$l =~ s{
^\s*/etc/rc\.d/rc\.inet2[ \t]*$
}[
"$0 $unitdir /etc/rc.d/rc.inet2 | /bin/bash"
]gex;
# And check if any other script has a unit.
$l =~ s{
(\b(sh|\.)\s+)?(/etc/rc\.d/rc\.\w+)(\s+start)
}[
repl($1,$3,$4)
]gex;
print $l;
}