forked from NagiosEnterprises/nrpe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subst.in
executable file
·61 lines (50 loc) · 1.67 KB
/
subst.in
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
#!/usr/bin/perl -w
# This script finishes the job started by config.status by replacing the variables
# of the form ${...} which were inserted into the file(s) by config.status.
# Read all files with a single read statement
$/ = undef;
# List of variables to replace
my %configvars = (
"prefix" => { "value" => '@prefix@'},
"exec_prefix" => { "value" => '@exec_prefix@'},
);
sub replace_var {
my $filep = shift;
my $cvp = shift;
my $varname = shift;
return if( $cvp->{ $varname}->{ "replaced"});
if( defined( $cvp->{ $varname}->{ "dependency"})) {
if( !$cvp->{ $cvp->{ $varname}->{ "dependency"}}->{ "replaced"}) {
# If a dependency exists and it is not already replaced, replace it
replace_var( $filep, $cvp, $cvp->{ $varname}->{ "dependency"});
}
}
my $replacement = $cvp->{ $varname}->{ "value"};
$$filep =~ s/\${$varname}/$replacement/g;
$cvp->{ $varname}->{ "replaced"} = 1;
}
# Figure out the dependencies.
foreach my $cv ( keys %configvars ) {
if( $configvars{ $cv}->{ "value"} =~ /\${([^}]+)}/) {
my $dependency = $1;
if( exists( $configvars{ $dependency})) {
$configvars{ $dependency}->{ "dependency"} = $cv;
}
$configvars{ $cv}->{ "replaced"} = 0;
}
}
# Process each file
while ($f = shift @ARGV) {
# Read in the file
open( FILE, $f) || die "Unable to open $f for reading";
my $file = <FILE>;
close( FILE) || die "Unable to close $f after reading";
# Replace each of the variables we know about
foreach $cv ( keys %configvars ) {
replace_var( \$file, \%configvars, $cv);
}
# Write out the replacements
open( FILE, ">$f") || die "Unable to open $f for writing";
print FILE $file;
close( FILE) || die "Unable to close $f after writing";
}