chengshan / rpms / kernel

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