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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/usr/bin/php
<?php
$ignorechangelog = false;
$remi = false;
$fedo = false;
// Parsing arg
for ($i=1 ; $i < $_SERVER['argc'] ; $i++) {
switch ($arg=$_SERVER['argv'][$i]) {
case '-n':
$ignorechangelog = true;
break;
default:
if ($arg[0] == '-') {
die("Unkown option $arg\n");
} else if ($fedo) {
die("Too much arguments\n");
} else if ($remi) {
$fedo = $arg;
} else {
$remi = $arg;
}
}
}
if (!$remi) {
die("
Usage getspec [ -n ] <remispec> [ <fedoraspec> ]
Otions:
-n : no new changelog entry
\n");
}
if (!$fedo) {
$fedo = basename($remi);
}
if (!file_exists($fedo) && strpos($fedo, '-dev')) {
$fedo = str_replace('-dev', '', $fedo);
}
printf("Reading remi's spec: %s\n", $remi);
$rem = file_get_contents($remi);
if (!$rem) {
die("Cannot read $remi\n");
}
$rem = explode("\n", $rem);
printf("Reading fedora's spec: %s\n", $fedo);
$fed = file_get_contents($fedo);
if (!$fed) {
die("Cannot read $fedo\n");
}
$fed = explode("\n", $fed);
printf("Merging\n");
$out = [];
$inchangelog = false;
$empty = 0;
$skip = 0;
foreach ($rem as $l) {
if ($l == '%changelog') {
$inchangelog = true;
}
if (preg_match('/^BuildRoot:/', $l) ||
preg_match('/^rm -rf( )*%{buildroot}$/', $l) ||
preg_match('/^%defattr/', $l) ||
preg_match('/^# remirepo spec/', $l) ||
preg_match('/%clean/', $l)) {
continue;
}
if (preg_match("/# remirepo:([0-9]+)/", $l, $reg)) {
$skip = $reg[1];
continue;
}
if ($skip) {
$skip--;
continue;
}
if ($l) {
$out[] = $l;
$empty = 0;
} else {
if ($empty < 2) {
$out[] = $l;
}
$empty++;
}
if ($inchangelog) {
if ($ignorechangelog) {
// After entering changelog
break;
}
if (!$l) {
// After 1st new Changelog entry
break;
}
}
}
$inchangelog = false;
foreach ($fed as $l) {
if ($l == '%changelog') {
$inchangelog = true;
continue;
}
if ($inchangelog) {
$out[] = $l;
}
}
printf("Saving $fedo\n");
file_put_contents($fedo, implode("\n", $out));
|