-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig_merge
More file actions
executable file
·118 lines (90 loc) · 1.75 KB
/
config_merge
File metadata and controls
executable file
·118 lines (90 loc) · 1.75 KB
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
#!/usr/bin/perl
## hyphop ##
#= kernel config merge replace values
our %o;
our $in;
our $out;
our $REPLACE;
for (@ARGV) {
if (/(\w+)=(y|n|m|$)/i) {
my $n = uc $1;
my $v = lc $2 || 'n';
$n = "CONFIG_$n" unless $n =~ /^CONFIG_/;
# warn "[i] $n = $v";
$o{$n} = $v;
}
elsif (/^\-r/) {
$REPLACE = 1;
warn "[i] replace mode\n";
#replace
# ;
}
else {
if ( -f $_ && !defined $in ) {
$in = $_;
}
else {
$out = $_;
}
}
}
unless ( keys %o ) {
warn "[e] undef any config values\n";
exit 1;
}
warn "[i] in $in > $out\n";
open IN, "$in";
if ( defined $out || $REPLACE ) {
our $T = "/tmp/$$.tmp";
open T, ">$T";
}
else {
open T, ">&STDOUT";
}
while (<IN>) {
if ( /(# )?(CONFIG_\w+)(\s|=(y|m))/ && $o{$2} ) {
my $a = $4 || 'n';
if ( $a ne $o{$2} ) {
warn "[i] replace - $2=$a <= $o{$2}\n";
if ( $o{$2} eq 'n' ) {
print T "# $2 is not set\n";
}
else {
print T "$2=$o{$2}\n";
}
##
$O{$2} = delete $o{$2}
}
else {
print T "$_";
warn "[i] same: $2=$o{$2}\n";
delete $o{$2};
}
}
else {
print T "$_";
}
}
print T "\n# add\n\n" if keys %o;
for ( sort keys %o ) {
warn "[i] add $_=$o{$_}\n";
if ( $o{$_} eq 'n' ) {
print T "# $_ is not set\n";
}
else {
print T "$_=$o{$_}\n";
}
$O{$_} = delete $o{$_};
}
close T;
close IN;
if ( $REPLACE ) {
if ( keys %O ) {
warn "[i] $T => $in\n";
`mv "$T" "$in"`;
} else {
warn "[i] not changes for $in\n";
}
} else {
}
unlink $T;