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 :)
7 # needs 'pear' for 'pear make-rpm-spec' command, ./builder for fetching sources.
8 # You should have all PEAR packages installed to get best results (needed for epoch autodetection)
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
17 # TODO: adjust similiarily noautoreqdeps
18 # BUGS: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
19 # see php-pear-DBA_Relational.spec
20 # Something strange: Requires: php-common < 4:3:5.1
22 # NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE.
24 # Send blames and beer
\b\b\b\bideas to glen@pld-linux.org
28 if [ -z "$spec" ]; then
29 echo >&2 "Usage: $0 SPECFILE"
32 if [ ! -f "$spec" ]; then
33 echo >&2 "$spec doesn't exist?"
37 if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then
38 echo >&2 "Please install php-pear-PEAR_Command_Packaging"
41 echo "Processing $spec"
46 rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}"
49 tarball=$(getsource $spec 0)
50 if [ -z "$tarball" ]; then
51 echo >&2 "Spec is missing Source0!"
55 if [ ! -f $tarball ]; then
59 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
63 License: @release_license@
64 State: @release_state@
66 pear make-rpm-spec --spec-template=$stmp --output=$template $tarball
69 mv $template .$template~
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.
80 if [ "$pkg" == "php-pear-PEAR" ]; then
81 pkg="php-pear-PEAR-core"
86 ver=$(echo "$ver" | sed -e 's,1.4.0b1,1.4.0-0.b1,')
93 if [[ "$ver" = *:* ]]; then
98 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
99 epoch=$(echo "$query" | grep -v 'installed' || :)
100 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
101 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
107 preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
108 # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
109 sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
112 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
115 requires=$(grep '^BuildRequires:' $template || :)
116 if [ -n "$requires" ]; then
117 echo "$requires" | while read tag dep; do
118 dep=$(add_epoch $dep)
119 if ! grep -q "^BuildRequires:.*$dep" $preamble; then
120 sed -i -e "/^BuildRoot/iBuildRequires:\t$dep" $spec
125 requires=$(grep '^Requires:' $template || :)
126 if [ -n "$requires" ]; then
127 echo "$requires" | while read tag dep; do
128 dep=$(add_epoch $dep)
129 if ! grep -q "^Requires:.*$dep" $preamble; then
130 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
136 conflicts=$(grep '^Conflicts:' $template || :)
137 if [ -n "$conflicts" ]; then
138 echo "$conflicts" | while read tag dep; do
139 dep=$(add_epoch $dep)
140 if ! grep -q "^Conflicts:.*$req" $preamble; then
141 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
146 # parse optional deps
147 optional=$(grep '^Suggests:' $template || :)
148 if [ -n "$optional" ]; then
149 echo "$optional" | while read tag dep; do
153 # convert pear package name to file pattern
154 req=$(echo "$req" | sed -e 's,^php-pear-,pear(,;y,-,/,;s,$,.*),')
157 # process only php-pear-* packages
162 m=$(grep "^%define.*_noautoreq" $spec || :)
164 sed -i -e "/^BuildRoot:/{
166 a# exclude optional dependencies
167 a%define\ \ _noautoreq\ $req
171 m=$(echo "$m" | grep -o "$req" || :)
173 sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
180 optional=$(grep '^Optional-ext:' $template || :)
181 if [ -n "$optional" ]; then
182 tmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
183 echo "$optional" | while read tag ext; do
184 grep -q "PHP extension .$ext" && continue
186 echo '%{name} can optionally use PHP extension "$ext"' >> optional-packages.txt
189 /%pear_package_setup/ {
197 has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :)
198 if [ "$has_opt" -gt 0 ]; then
199 if ! grep -q 'rpmbuild(macros)' $spec; then
202 aBuildRequires: rpmbuild(macros) >= 1.300
206 if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then
210 i%pear_package_print_optionalpackages
218 if ! grep -q '%doc.*optional-packages.txt' $spec; then
221 s/$/ optional-packages.txt/
228 state=$(awk '/^State:/{print $2}' $template)
229 sed -i -e "/^%define.*_status/{
230 /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/
235 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
236 if ! diff -u $bak $spec > $diff; then
240 echo "$spec: No diffs"