aboutsummaryrefslogtreecommitdiff
blob: 435e936071daae20188da54c492c835c30eb3256 (plain)
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
BEGIN { RS="\n"; FS=""; OFS=""; ORS=""; state="0"; }
{
if(state == "0")
{
	if (match($0, /^title=/) || match($0, /^title */))
	{
		state = "1";
		ORIG = ORIG $0 "\n";
		next;
	} else {
		if(match($0, /^[[:space:]]*#/))
			ORIG = ORIG $0 "\n";
		extraA = extraA $0 "\n";
	}
}

if(state == "1")
{
	if(match($0, /^[[:space:]]*kernel /))
	{
		ORIG = ORIG $0 "\n";
		i = 0;
		have_k = "1";
		my_kernel = $0;
		sub(/kernel-[[:alnum:][:punct:]]+/, "kernel-" KNAME "-" ARCH "-" KV, my_kernel);
	} else {
		if(match($0, /^[[:space:]]*initrd /))
		{
			ORIG = ORIG $0 "\n";
			i = 0;
			extraC = extraC commentLookahead;

			have_i = "1";
			my_initrd = "\n" $0;
			sub(/initr(d|amfs)-[[:alnum:][:punct:]]+/, "init" TYPE "-" KNAME "-" ARCH "-" KV, my_initrd);
		} else {
			if($0 == "\n")
				next;
			ORIG = ORIG $0 "\n";
			if(match($0, /^[[:space:]]*#/))
			{
				i = 1;
				if(commentLookahead)
					commentLookahead = commentLookahead "\n" $0;
				else
					commentLookahead = $0;
				next;
			}

			if(!(match($0, /^title=/) || match($0, /^title */) ))
			{	
				i = 0;
				commentLookahead = "";

				if(have_k != "1")
					extraB = extraB commentLookahead $0 "\n";
				else
				{
					if(have_i != "1")
						extraC = extraC commentLookahead $0 "\n";
					else
						extraD = extraD commentLookahead $0 "\n";
				}
			}
		}
	}
	if(have_k == "1" && ((match($0, /^title=/) || match($0, /^title */)) || NR == LIMIT))
	{
		state = "2";
		print extraA "title=Gentoo Linux (" KV ")\n";
		print extraB my_kernel;
		if(extraC)
			print "\n" extraC;
		print my_initrd extraD "\n";
		if(i == 0)
			print commentLookahead;
		print ORIG;
		next;
	}
}

if(state == "2")
	print $0 "\n";
}