]>
Commit | Line | Data |
---|---|---|
70f6b6a6 | 1 | #!/bin/sh |
dd7e9d0e ER |
2 | # updates php-pear .spec with Requires/Conflicts lines. |
3 | # the items are added randomly to the preamble, but once added their order is left intact. | |
4 | # it is still better than nothing. if somebody wishes to add sorting in this | |
5 | # script. i'd be just glad :) | |
6 | # | |
269cad96 | 7 | # needs 'pear' for 'pear make-rpm-spec' command, ./builder for fetching sources. |
6f7ba2b5 | 8 | # You should have all PEAR packages installed to get best results (needed for epoch autodetection) |
4fcb2e28 ER |
9 | # So far there are 3 packages with epoch > 0: |
10 | # $ grep ^Epoch:.* php-pear-*.spec | grep -v 'Epoch:.*0' | |
11 | # php-pear-MDB2.spec:Epoch: 1 | |
12 | # php-pear-MDB.spec:Epoch: 1 | |
13 | # php-pear-PEAR.spec:Epoch: 1 | |
dd7e9d0e | 14 | # |
269cad96 ER |
15 | # To create completely new PEAR package spec, follow something like this: |
16 | # $ pear download RDF-alpha | |
17 | # File RDF-0.1.0alpha1.tgz downloaded | |
18 | # $ pear make-rpm-spec RDF-0.1.0alpha1.tgz | |
19 | # Wrote RPM spec file php-pear-RDF.spec | |
20 | # $ | |
21 | # | |
22 | # TODO: adjust similiarily noautoreqdeps | |
23 | # BUGS: the beta portions in version deps could be wrong (php-4.3.0b1 and alike) | |
c4bf44d2 | 24 | # see php-pear-DBA_Relational.spec |
62e972e1 | 25 | # Something strange: Requires: php-common < 4:3:5.1 |
dd7e9d0e | 26 | # |
62e972e1 ER |
27 | # NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE. |
28 | # | |
29 | # Send blames and beer\b\b\b\bideas to glen@pld-linux.org | |
dd7e9d0e | 30 | |
70f6b6a6 ER |
31 | set -e |
32 | spec="$1" | |
dd7e9d0e ER |
33 | if [ -z "$spec" ]; then |
34 | echo >&2 "Usage: $0 SPECFILE" | |
35 | exit 0 | |
36 | fi | |
37 | if [ ! -f "$spec" ]; then | |
38 | echo >&2 "$spec doesn't exist?" | |
39 | exit 1 | |
40 | fi | |
c4bf44d2 | 41 | |
15cbfeac ER |
42 | if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then |
43 | echo >&2 "Please install php-pear-PEAR_Command_Packaging" | |
44 | exit 1 | |
ea573965 | 45 | fi |
15cbfeac | 46 | echo "Processing $spec" |
ea573965 | 47 | |
390d2e8f ER |
48 | getsource() { |
49 | local spec="$1" | |
50 | local NR="$2" | |
51 | rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}" | |
52 | } | |
53 | ||
54 | tarball=$(getsource $spec 0) | |
cb64a2ce ER |
55 | if [ -z "$tarball" ]; then |
56 | echo >&2 "Spec is missing Source0!" | |
57 | exit 1 | |
58 | fi | |
70f6b6a6 | 59 | |
c5ad552d ER |
60 | if [ ! -f $tarball ]; then |
61 | ./builder -g "$spec" | |
62 | fi | |
63 | ||
4188dbdf | 64 | stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
e1b244a6 | 65 | template=pearize.spec |
4188dbdf ER |
66 | cat > $stmp <<'EOF' |
67 | @extra_headers@ | |
5e551ed7 ER |
68 | License: @release_license@ |
69 | State: @release_state@ | |
4188dbdf | 70 | EOF |
e1b244a6 | 71 | pear make-rpm-spec --spec-template=$stmp --output=$template $tarball |
0c79d776 ER |
72 | rm -f $stmp |
73 | ||
5e241fea ER |
74 | mv $template .$template~ |
75 | template=.$template~ | |
19133cbd | 76 | |
dd7e9d0e ER |
77 | # take as argument dependency in form NAME EQUALITY VERSION |
78 | # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero. | |
79 | add_epoch() { | |
80 | local dep="$@" | |
81 | local pkg="$1" | |
a36710cb ER |
82 | local ver="$3" |
83 | ||
84 | # already have epoch | |
85 | if [[ "$ver" = *:* ]]; then | |
86 | echo "$dep" | |
87 | return | |
88 | fi | |
89 | ||
dd7e9d0e ER |
90 | query=$(rpm -q --qf '%{epoch}\n' $pkg || :) |
91 | epoch=$(echo "$query" | grep -v 'installed' || :) | |
92 | if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then | |
63dd75f0 | 93 | echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:," |
dd7e9d0e ER |
94 | else |
95 | echo "$dep" | |
96 | fi | |
19133cbd ER |
97 | } |
98 | ||
5e551ed7 ER |
99 | preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
100 | # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things. | |
101 | sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble | |
102 | ||
dd7e9d0e ER |
103 | # create backup |
104 | bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" ) | |
19133cbd | 105 | |
5e551ed7 | 106 | # parse requires |
0b6459e9 ER |
107 | requires=$(grep '^BuildRequires:' $template || :) |
108 | if [ -n "$requires" ]; then | |
109 | echo "$requires" | while read tag dep; do | |
110 | dep=$(add_epoch $dep) | |
111 | if ! grep -q "^BuildRequires:.*$dep" $preamble; then | |
112 | sed -i -e "/^BuildRoot/iBuildRequires:\t$dep" $spec | |
113 | fi | |
114 | done | |
115 | fi | |
116 | ||
5e551ed7 | 117 | requires=$(grep '^Requires:' $template || :) |
dd7e9d0e ER |
118 | if [ -n "$requires" ]; then |
119 | echo "$requires" | while read tag dep; do | |
120 | dep=$(add_epoch $dep) | |
121 | if ! grep -q "^Requires:.*$dep" $preamble; then | |
0b53f90a | 122 | dep=$(echo "$dep" | sed -e 's,php-pear-PEAR\b,php-pear-PEAR-core,') |
dd7e9d0e ER |
123 | sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec |
124 | fi | |
125 | done | |
c9f81079 ER |
126 | fi |
127 | ||
5e551ed7 ER |
128 | # parse conflicts |
129 | conflicts=$(grep '^Conflicts:' $template || :) | |
dd7e9d0e | 130 | if [ -n "$conflicts" ]; then |
df07ff19 | 131 | echo "$conflicts" | while read tag dep; do |
dd7e9d0e ER |
132 | dep=$(add_epoch $dep) |
133 | if ! grep -q "^Conflicts:.*$req" $preamble; then | |
134 | sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec | |
135 | fi | |
136 | done | |
05779902 ER |
137 | fi |
138 | ||
cb4369bd | 139 | # parse optional deps |
0b6459e9 | 140 | optional=$(grep '^Suggests:' $template || :) |
cb4369bd ER |
141 | if [ -n "$optional" ]; then |
142 | echo "$optional" | while read tag dep; do | |
6fbd10e2 ER |
143 | dep=$(add_epoch $dep) |
144 | if ! grep -q "^Suggests:.*$dep" $preamble; then | |
145 | sed -i -e "/^BuildRoot/iSuggests:\t$dep" $spec | |
146 | fi | |
147 | ||
cb4369bd | 148 | for req in $dep; do |
83cb1608 ER |
149 | case "$req" in |
150 | php-pear-*) | |
151 | # convert pear package name to file pattern | |
d340622b | 152 | req=$(echo "$req" | sed -e 's,^php-pear-,pear(,;y,_,/,;s,$,.*),') |
83cb1608 ER |
153 | ;; |
154 | *) | |
155 | # process only php-pear-* packages | |
156 | continue | |
157 | ;; | |
158 | esac | |
159 | ||
bae3c76f | 160 | m=$(grep "^%define.*_noautoreq" $spec || :) |
cb4369bd | 161 | if [ -z "$m" ]; then |
bae3c76f ER |
162 | sed -i -e "/^BuildRoot:/{ |
163 | a | |
164 | a# exclude optional dependencies | |
165 | a%define\ \ _noautoreq\ $req | |
166 | } | |
167 | " $spec | |
168 | else | |
169 | m=$(echo "$m" | grep -o "$req" || :) | |
170 | if [ -z "$m" ]; then | |
171 | sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec | |
172 | fi | |
cb4369bd ER |
173 | fi |
174 | done | |
175 | done | |
176 | fi | |
e1b244a6 ER |
177 | |
178 | optional=$(grep '^Optional-ext:' $template || :) | |
179 | if [ -n "$optional" ]; then | |
180 | tmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") | |
181 | echo "$optional" | while read tag ext; do | |
182 | grep -q "PHP extension .$ext" && continue | |
183 | cat > $tmp <<-EOF | |
184 | echo '%{name} can optionally use PHP extension "$ext"' >> optional-packages.txt | |
185 | EOF | |
186 | sed -i -e " | |
187 | /%pear_package_setup/ { | |
188 | r $tmp | |
189 | } | |
190 | " $spec | |
191 | done | |
192 | rm -f .ext.tmp | |
193 | fi | |
194 | ||
887577bd | 195 | has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :) |
b299cb78 | 196 | if [ "$has_opt" -gt 0 ]; then |
5e4ba850 ER |
197 | if ! grep -q 'rpmbuild(macros)' $spec; then |
198 | sed -i -e ' | |
199 | /rpm-php-pearprov/{ | |
200 | aBuildRequires: rpmbuild(macros) >= 1.300 | |
201 | } | |
202 | ' $spec | |
203 | fi | |
204 | if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then | |
b299cb78 | 205 | sed -i -e ' |
20aec7a3 | 206 | /^%files$/{ |
5e4ba850 ER |
207 | i%post -p <lua> |
208 | i%pear_package_print_optionalpackages | |
b299cb78 ER |
209 | i |
210 | } | |
5e4ba850 ER |
211 | /rpmbuild(macros)/{ |
212 | s/>=.*/>= 1.571/ | |
213 | } | |
07dbc9c8 ER |
214 | ' $spec |
215 | fi | |
216 | if ! grep -q '%doc.*optional-packages.txt' $spec; then | |
217 | sed -i -e ' | |
b299cb78 ER |
218 | /^%doc install.log/{ |
219 | s/$/ optional-packages.txt/ | |
220 | } | |
221 | ' $spec | |
222 | fi | |
223 | fi | |
cb4369bd | 224 | |
5e551ed7 ER |
225 | # parse state |
226 | state=$(awk '/^State:/{print $2}' $template) | |
227 | sed -i -e "/^%define.*_status/{ | |
228 | /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/ | |
229 | }" $spec | |
230 | ||
4fcb2e28 ER |
231 | # parse license |
232 | #license=$(awk '/^License:/{print $2}' $template) | |
233 | #sed -i -e "s/^License:.*/License:\t$license/" $spec | |
234 | ||
dd7e9d0e | 235 | rm -f $preamble |
4d240bd1 | 236 | |
dd7e9d0e ER |
237 | diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
238 | if ! diff -u $bak $spec > $diff; then | |
239 | vim -o $spec $diff | |
240 | rm -f $diff | |
241 | else | |
242 | echo "$spec: No diffs" | |
4d240bd1 | 243 | fi |