]>
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 | |
4d58f3eb ER |
31 | PROGRAM=${0##*/} |
32 | APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d") | |
33 | ||
70f6b6a6 ER |
34 | set -e |
35 | spec="$1" | |
dd7e9d0e ER |
36 | if [ -z "$spec" ]; then |
37 | echo >&2 "Usage: $0 SPECFILE" | |
38 | exit 0 | |
39 | fi | |
40 | if [ ! -f "$spec" ]; then | |
41 | echo >&2 "$spec doesn't exist?" | |
42 | exit 1 | |
43 | fi | |
c4bf44d2 | 44 | |
15cbfeac ER |
45 | if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then |
46 | echo >&2 "Please install php-pear-PEAR_Command_Packaging" | |
47 | exit 1 | |
ea573965 | 48 | fi |
15cbfeac | 49 | echo "Processing $spec" |
ea573965 | 50 | |
390d2e8f ER |
51 | getsource() { |
52 | local spec="$1" | |
53 | local NR="$2" | |
54 | rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}" | |
55 | } | |
56 | ||
57 | tarball=$(getsource $spec 0) | |
cb64a2ce ER |
58 | if [ -z "$tarball" ]; then |
59 | echo >&2 "Spec is missing Source0!" | |
60 | exit 1 | |
61 | fi | |
70f6b6a6 | 62 | |
c5ad552d | 63 | if [ ! -f $tarball ]; then |
4d58f3eb | 64 | $APPDIR/builder -g "$spec" |
c5ad552d ER |
65 | fi |
66 | ||
4188dbdf | 67 | stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
e1b244a6 | 68 | template=pearize.spec |
4188dbdf ER |
69 | cat > $stmp <<'EOF' |
70 | @extra_headers@ | |
5e551ed7 ER |
71 | License: @release_license@ |
72 | State: @release_state@ | |
4188dbdf | 73 | EOF |
e1b244a6 | 74 | pear make-rpm-spec --spec-template=$stmp --output=$template $tarball |
0c79d776 ER |
75 | rm -f $stmp |
76 | ||
5e241fea ER |
77 | mv $template .$template~ |
78 | template=.$template~ | |
19133cbd | 79 | |
dd7e9d0e ER |
80 | # take as argument dependency in form NAME EQUALITY VERSION |
81 | # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero. | |
82 | add_epoch() { | |
83 | local dep="$@" | |
84 | local pkg="$1" | |
a36710cb ER |
85 | local ver="$3" |
86 | ||
87 | # already have epoch | |
88 | if [[ "$ver" = *:* ]]; then | |
89 | echo "$dep" | |
90 | return | |
91 | fi | |
92 | ||
dd7e9d0e ER |
93 | query=$(rpm -q --qf '%{epoch}\n' $pkg || :) |
94 | epoch=$(echo "$query" | grep -v 'installed' || :) | |
95 | if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then | |
63dd75f0 | 96 | echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:," |
dd7e9d0e ER |
97 | else |
98 | echo "$dep" | |
99 | fi | |
19133cbd ER |
100 | } |
101 | ||
5e551ed7 ER |
102 | preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
103 | # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things. | |
104 | sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble | |
105 | ||
dd7e9d0e ER |
106 | # create backup |
107 | bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" ) | |
19133cbd | 108 | |
4743a56e ER |
109 | # ensure rpm-build-macros is present |
110 | if ! grep -q "^BuildRequires:.*rpmbuild(macros)" $preamble; then | |
111 | sed -i -e "/^BuildRequires:.*rpm-php-pearprov/aBuildRequires:\trpmbuild(macros) >= 1.300" $spec | |
112 | fi | |
5e551ed7 | 113 | # parse requires |
0b6459e9 ER |
114 | requires=$(grep '^BuildRequires:' $template || :) |
115 | if [ -n "$requires" ]; then | |
116 | echo "$requires" | while read tag dep; do | |
117 | dep=$(add_epoch $dep) | |
118 | if ! grep -q "^BuildRequires:.*$dep" $preamble; then | |
119 | sed -i -e "/^BuildRoot/iBuildRequires:\t$dep" $spec | |
120 | fi | |
121 | done | |
122 | fi | |
123 | ||
5e551ed7 | 124 | requires=$(grep '^Requires:' $template || :) |
dd7e9d0e ER |
125 | if [ -n "$requires" ]; then |
126 | echo "$requires" | while read tag dep; do | |
127 | dep=$(add_epoch $dep) | |
128 | if ! grep -q "^Requires:.*$dep" $preamble; then | |
0b53f90a | 129 | dep=$(echo "$dep" | sed -e 's,php-pear-PEAR\b,php-pear-PEAR-core,') |
dd7e9d0e ER |
130 | sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec |
131 | fi | |
132 | done | |
c9f81079 ER |
133 | fi |
134 | ||
5e551ed7 ER |
135 | # parse conflicts |
136 | conflicts=$(grep '^Conflicts:' $template || :) | |
dd7e9d0e | 137 | if [ -n "$conflicts" ]; then |
df07ff19 | 138 | echo "$conflicts" | while read tag dep; do |
dd7e9d0e ER |
139 | dep=$(add_epoch $dep) |
140 | if ! grep -q "^Conflicts:.*$req" $preamble; then | |
141 | sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec | |
142 | fi | |
143 | done | |
05779902 ER |
144 | fi |
145 | ||
cb4369bd | 146 | # parse optional deps |
0b6459e9 | 147 | optional=$(grep '^Suggests:' $template || :) |
cb4369bd ER |
148 | if [ -n "$optional" ]; then |
149 | echo "$optional" | while read tag dep; do | |
6fbd10e2 ER |
150 | dep=$(add_epoch $dep) |
151 | if ! grep -q "^Suggests:.*$dep" $preamble; then | |
152 | sed -i -e "/^BuildRoot/iSuggests:\t$dep" $spec | |
153 | fi | |
154 | ||
cb4369bd | 155 | for req in $dep; do |
83cb1608 ER |
156 | case "$req" in |
157 | php-pear-*) | |
158 | # convert pear package name to file pattern | |
d340622b | 159 | req=$(echo "$req" | sed -e 's,^php-pear-,pear(,;y,_,/,;s,$,.*),') |
83cb1608 ER |
160 | ;; |
161 | *) | |
162 | # process only php-pear-* packages | |
163 | continue | |
164 | ;; | |
165 | esac | |
166 | ||
bae3c76f | 167 | m=$(grep "^%define.*_noautoreq" $spec || :) |
cb4369bd | 168 | if [ -z "$m" ]; then |
bae3c76f ER |
169 | sed -i -e "/^BuildRoot:/{ |
170 | a | |
171 | a# exclude optional dependencies | |
172 | a%define\ \ _noautoreq\ $req | |
173 | } | |
174 | " $spec | |
175 | else | |
176 | m=$(echo "$m" | grep -o "$req" || :) | |
177 | if [ -z "$m" ]; then | |
178 | sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec | |
179 | fi | |
cb4369bd ER |
180 | fi |
181 | done | |
182 | done | |
183 | fi | |
e1b244a6 ER |
184 | |
185 | optional=$(grep '^Optional-ext:' $template || :) | |
186 | if [ -n "$optional" ]; then | |
187 | tmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") | |
188 | echo "$optional" | while read tag ext; do | |
189 | grep -q "PHP extension .$ext" && continue | |
190 | cat > $tmp <<-EOF | |
191 | echo '%{name} can optionally use PHP extension "$ext"' >> optional-packages.txt | |
192 | EOF | |
193 | sed -i -e " | |
194 | /%pear_package_setup/ { | |
195 | r $tmp | |
196 | } | |
197 | " $spec | |
198 | done | |
199 | rm -f .ext.tmp | |
200 | fi | |
201 | ||
887577bd | 202 | has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :) |
b299cb78 | 203 | if [ "$has_opt" -gt 0 ]; then |
5e4ba850 ER |
204 | if ! grep -q 'rpmbuild(macros)' $spec; then |
205 | sed -i -e ' | |
206 | /rpm-php-pearprov/{ | |
207 | aBuildRequires: rpmbuild(macros) >= 1.300 | |
208 | } | |
209 | ' $spec | |
210 | fi | |
211 | if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then | |
b299cb78 | 212 | sed -i -e ' |
20aec7a3 | 213 | /^%files$/{ |
5e4ba850 ER |
214 | i%post -p <lua> |
215 | i%pear_package_print_optionalpackages | |
b299cb78 ER |
216 | i |
217 | } | |
5e4ba850 ER |
218 | /rpmbuild(macros)/{ |
219 | s/>=.*/>= 1.571/ | |
220 | } | |
07dbc9c8 ER |
221 | ' $spec |
222 | fi | |
223 | if ! grep -q '%doc.*optional-packages.txt' $spec; then | |
224 | sed -i -e ' | |
b299cb78 ER |
225 | /^%doc install.log/{ |
226 | s/$/ optional-packages.txt/ | |
227 | } | |
228 | ' $spec | |
229 | fi | |
230 | fi | |
cb4369bd | 231 | |
5e551ed7 ER |
232 | # parse state |
233 | state=$(awk '/^State:/{print $2}' $template) | |
c419af1a ER |
234 | sed -i -e "/^%define.*_\?status/{ |
235 | s/%define[[:space:]]*_status.*/%define\t\t_status\t\t$state/ | |
236 | s/%define[[:space:]]*status.*/%define\t\tstatus\t\t$state/ | |
5e551ed7 ER |
237 | }" $spec |
238 | ||
4fcb2e28 ER |
239 | # parse license |
240 | #license=$(awk '/^License:/{print $2}' $template) | |
241 | #sed -i -e "s/^License:.*/License:\t$license/" $spec | |
242 | ||
dd7e9d0e | 243 | rm -f $preamble |
4d240bd1 | 244 | |
dd7e9d0e ER |
245 | diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
246 | if ! diff -u $bak $spec > $diff; then | |
247 | vim -o $spec $diff | |
248 | rm -f $diff | |
249 | else | |
250 | echo "$spec: No diffs" | |
4d240bd1 | 251 | fi |