Add kernel-2.6.32-358.118.1.openstack version
[packages/centos6/kernel.git] / merge.pl
1 #! /usr/bin/perl
2
3 my @args=@ARGV;
4 my %configvalues;
5 my @configoptions;
6 my $configcounter = 0;
7
8 # optionally print out the architecture as the first line of our output
9 my $arch = $args[2];
10 if (defined $arch) {
11         print "# $arch\n";
12 }
13
14 # first, read the override file
15
16 open (FILE,"$args[0]") || die "Could not open $args[0]";
17 while (<FILE>) {
18         my $str = $_;
19         my $configname;
20
21         if (/\# ([\w]+) is not set/) {
22                 $configname = $1;
23         } elsif (/([\w]+)=/) {
24                 $configname = $1;
25         }
26
27         if (defined($configname) && !exists($configvalues{$configname})) {
28                 $configvalues{$configname} = $str;
29                 $configoptions[$configcounter] = $configname;
30                 $configcounter ++;
31         }
32 };
33
34 # now, read and output the entire configfile, except for the overridden
35 # parts... for those the new value is printed.
36
37 open (FILE2,"$args[1]") || die "Could not open $args[1]";
38 while (<FILE2>) {
39         my $configname;
40
41         if (/\# ([\w]+) is not set/) {
42                 $configname = $1;
43         } elsif (/([\w]+)=/) {
44                 $configname  = $1;
45         }
46
47         if (defined($configname) && exists($configvalues{$configname})) {
48                 print "$configvalues{$configname}";
49                 delete($configvalues{$configname});
50         } else {
51                 print "$_";
52         }
53 }
54
55 # now print the new values from the overridden configfile
56 my $counter = 0;
57
58 while ($counter < $configcounter) {
59         my $configname = $configoptions[$counter];
60         if (exists($configvalues{$configname})) {
61                 print "$configvalues{$configname}";
62         }
63         $counter++;
64 }
65
66 1;