hitmoon / rpms / kernel

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