]>
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 ER |
59 | stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
60 | cat > $stmp <<'EOF' | |
61 | @extra_headers@ | |
62 | Optional: @optional@ | |
d5150240 ER |
63 | @optional-pkg@ |
64 | @optional-ext@ | |
5e551ed7 ER |
65 | License: @release_license@ |
66 | State: @release_state@ | |
4188dbdf | 67 | EOF |
cb64a2ce | 68 | pear make-rpm-spec --spec-template=$stmp --output=pearize.spec $tarball |
95c0e2f7 | 69 | template=pearize.spec |
0c79d776 ER |
70 | rm -f $stmp |
71 | ||
5e241fea ER |
72 | mv $template .$template~ |
73 | template=.$template~ | |
19133cbd | 74 | |
dd7e9d0e ER |
75 | # take as argument dependency in form NAME EQUALITY VERSION |
76 | # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero. | |
77 | add_epoch() { | |
78 | local dep="$@" | |
79 | local pkg="$1" | |
a52e6b27 | 80 | local qual="$2" |
a36710cb ER |
81 | local ver="$3" |
82 | ||
a52e6b27 ER |
83 | if [ "$pkg" == "php-pear-PEAR" ]; then |
84 | pkg="php-pear-PEAR-core" | |
85 | fi | |
86 | ||
87 | case "$pkg" in | |
88 | php-pear-PEAR-core) | |
89 | ver=$(echo "$ver" | sed -e 's,1.4.0b1,1.4.0-0.b1,') | |
90 | ;; | |
91 | esac | |
92 | ||
93 | dep="$pkg $qual $ver" | |
94 | ||
a36710cb ER |
95 | # already have epoch |
96 | if [[ "$ver" = *:* ]]; then | |
97 | echo "$dep" | |
98 | return | |
99 | fi | |
100 | ||
dd7e9d0e ER |
101 | query=$(rpm -q --qf '%{epoch}\n' $pkg || :) |
102 | epoch=$(echo "$query" | grep -v 'installed' || :) | |
103 | if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then | |
63dd75f0 | 104 | echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:," |
dd7e9d0e ER |
105 | else |
106 | echo "$dep" | |
107 | fi | |
19133cbd ER |
108 | } |
109 | ||
5e551ed7 ER |
110 | preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
111 | # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things. | |
112 | sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble | |
113 | ||
dd7e9d0e ER |
114 | # create backup |
115 | bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" ) | |
19133cbd | 116 | |
5e551ed7 ER |
117 | # parse requires |
118 | requires=$(grep '^Requires:' $template || :) | |
dd7e9d0e ER |
119 | if [ -n "$requires" ]; then |
120 | echo "$requires" | while read tag dep; do | |
121 | dep=$(add_epoch $dep) | |
122 | if ! grep -q "^Requires:.*$dep" $preamble; then | |
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 ER |
139 | # parse optional deps |
140 | optional=$(grep '^Optional:' $template || :) | |
141 | if [ -n "$optional" ]; then | |
142 | echo "$optional" | while read tag dep; do | |
143 | for req in $dep; do | |
a673f50f ER |
144 | # strip single quotes that default template includes in @optional@ expand |
145 | # TODO: remove in php-pear-PEAR_Command_Packaging package | |
146 | req=${req#\'} req=${req%\'} | |
bae3c76f | 147 | m=$(grep "^%define.*_noautoreq" $spec || :) |
cb4369bd | 148 | if [ -z "$m" ]; then |
bae3c76f ER |
149 | sed -i -e "/^BuildRoot:/{ |
150 | a | |
151 | a# exclude optional dependencies | |
152 | a%define\ \ _noautoreq\ $req | |
153 | } | |
154 | " $spec | |
155 | else | |
156 | m=$(echo "$m" | grep -o "$req" || :) | |
157 | if [ -z "$m" ]; then | |
158 | sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec | |
159 | fi | |
cb4369bd ER |
160 | fi |
161 | done | |
162 | done | |
163 | fi | |
887577bd | 164 | has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :) |
b299cb78 | 165 | if [ "$has_opt" -gt 0 ]; then |
5e4ba850 ER |
166 | if ! grep -q 'rpmbuild(macros)' $spec; then |
167 | sed -i -e ' | |
168 | /rpm-php-pearprov/{ | |
169 | aBuildRequires: rpmbuild(macros) >= 1.300 | |
170 | } | |
171 | ' $spec | |
172 | fi | |
173 | if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then | |
b299cb78 | 174 | sed -i -e ' |
20aec7a3 | 175 | /^%files$/{ |
5e4ba850 ER |
176 | i%post -p <lua> |
177 | i%pear_package_print_optionalpackages | |
b299cb78 ER |
178 | i |
179 | } | |
5e4ba850 ER |
180 | /rpmbuild(macros)/{ |
181 | s/>=.*/>= 1.571/ | |
182 | } | |
07dbc9c8 ER |
183 | ' $spec |
184 | fi | |
185 | if ! grep -q '%doc.*optional-packages.txt' $spec; then | |
186 | sed -i -e ' | |
b299cb78 ER |
187 | /^%doc install.log/{ |
188 | s/$/ optional-packages.txt/ | |
189 | } | |
190 | ' $spec | |
191 | fi | |
192 | fi | |
cb4369bd | 193 | |
5e551ed7 ER |
194 | # parse state |
195 | state=$(awk '/^State:/{print $2}' $template) | |
196 | sed -i -e "/^%define.*_status/{ | |
197 | /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/ | |
198 | }" $spec | |
199 | ||
dd7e9d0e | 200 | rm -f $preamble |
4d240bd1 | 201 | |
dd7e9d0e ER |
202 | diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
203 | if ! diff -u $bak $spec > $diff; then | |
204 | vim -o $spec $diff | |
205 | rm -f $diff | |
206 | else | |
207 | echo "$spec: No diffs" | |
4d240bd1 | 208 | fi |
c4bf44d2 | 209 | #exit 1 |