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