l30013671 / rpms / kernel

Forked from rpms/kernel 2 years ago
Clone
f2c60e
#! /usr/bin/perl
f2c60e
f2c60e
my @args=@ARGV;
f2c60e
my %configvalues;
f2c60e
my @configoptions;
f2c60e
my $configcounter = 0;
f2c60e
f2c60e
# optionally print out the architecture as the first line of our output
f2c60e
my $arch = $args[2];
f2c60e
if (defined $arch) {
f2c60e
	print "# $arch\n";
f2c60e
}
f2c60e
f2c60e
# first, read the override file
f2c60e
f2c60e
open (FILE,"$args[0]") || die "Could not open $args[0]";
f2c60e
while (<FILE>) {
f2c60e
	my $str = $_;
f2c60e
	my $configname;
f2c60e
f2c60e
	if (/\# ([\w]+) is not set/) {
f2c60e
		$configname = $1;
f2c60e
	} elsif (/([\w]+)=/) {
f2c60e
		$configname = $1;
f2c60e
	}
f2c60e
f2c60e
	if (defined($configname) && !exists($configvalues{$configname})) {
f2c60e
		$configvalues{$configname} = $str;
f2c60e
		$configoptions[$configcounter] = $configname;
f2c60e
		$configcounter ++;
f2c60e
	}
f2c60e
};
f2c60e
f2c60e
# now, read and output the entire configfile, except for the overridden
f2c60e
# parts... for those the new value is printed.
f2c60e
f2c60e
open (FILE2,"$args[1]") || die "Could not open $args[1]";
f2c60e
while (<FILE2>) {
f2c60e
	my $configname;
f2c60e
f2c60e
	if (/\# ([\w]+) is not set/) {
f2c60e
		$configname = $1;
f2c60e
	} elsif (/([\w]+)=/) {
f2c60e
		$configname  = $1;
f2c60e
	}
f2c60e
f2c60e
	if (defined($configname) && exists($configvalues{$configname})) {
f2c60e
		print "$configvalues{$configname}";
f2c60e
		delete($configvalues{$configname});
f2c60e
	} else {
f2c60e
		print "$_";
f2c60e
	}
f2c60e
}
f2c60e
f2c60e
# now print the new values from the overridden configfile
f2c60e
my $counter = 0;
f2c60e
f2c60e
while ($counter < $configcounter) {
f2c60e
	my $configname = $configoptions[$counter];
f2c60e
	if (exists($configvalues{$configname})) {
f2c60e
		print "$configvalues{$configname}";
f2c60e
	}
f2c60e
	$counter++;
f2c60e
}
f2c60e
f2c60e
1;