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)
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
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
22 # TODO: adjust similiarily noautoreqdeps
23 # BUGS: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
24 # see php-pear-DBA_Relational.spec
25 # Something strange: Requires: php-common < 4:3:5.1
27 # NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE.
29 # Send blames and beer
\b\b\b\bideas to glen@pld-linux.org
33 if [ -z "$spec" ]; then
34 echo >&2 "Usage: $0 SPECFILE"
37 if [ ! -f "$spec" ]; then
38 echo >&2 "$spec doesn't exist?"
42 if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then
43 echo >&2 "Please install php-pear-PEAR_Command_Packaging"
46 echo "Processing $spec"
51 rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}"
54 tarball=$(getsource $spec 0)
55 if [ -z "$tarball" ]; then
56 echo >&2 "Spec is missing Source0!"
60 if [ ! -f $tarball ]; then
64 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
68 License: @release_license@
69 State: @release_state@
71 pear make-rpm-spec --spec-template=$stmp --output=$template $tarball
74 mv $template .$template~
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.
85 if [[ "$ver" = *:* ]]; then
90 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
91 epoch=$(echo "$query" | grep -v 'installed' || :)
92 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
93 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
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
104 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
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
117 requires=$(grep '^Requires:' $template || :)
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
122 dep=$(echo "$dep" | sed -e 's,php-pear-PEAR\b,php-pear-PEAR-core,')
123 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
129 conflicts=$(grep '^Conflicts:' $template || :)
130 if [ -n "$conflicts" ]; then
131 echo "$conflicts" | while read tag dep; do
132 dep=$(add_epoch $dep)
133 if ! grep -q "^Conflicts:.*$req" $preamble; then
134 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
139 # parse optional deps
140 optional=$(grep '^Suggests:' $template || :)
141 if [ -n "$optional" ]; then
142 echo "$optional" | while read tag dep; do
143 dep=$(add_epoch $dep)
144 if ! grep -q "^Suggests:.*$dep" $preamble; then
145 sed -i -e "/^BuildRoot/iSuggests:\t$dep" $spec
151 # convert pear package name to file pattern
152 req=$(echo "$req" | sed -e 's,^php-pear-,pear(,;y,_,/,;s,$,.*),')
155 # process only php-pear-* packages
160 m=$(grep "^%define.*_noautoreq" $spec || :)
162 sed -i -e "/^BuildRoot:/{
164 a# exclude optional dependencies
165 a%define\ \ _noautoreq\ $req
169 m=$(echo "$m" | grep -o "$req" || :)
171 sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
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
184 echo '%{name} can optionally use PHP extension "$ext"' >> optional-packages.txt
187 /%pear_package_setup/ {
195 has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :)
196 if [ "$has_opt" -gt 0 ]; then
197 if ! grep -q 'rpmbuild(macros)' $spec; then
200 aBuildRequires: rpmbuild(macros) >= 1.300
204 if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then
208 i%pear_package_print_optionalpackages
216 if ! grep -q '%doc.*optional-packages.txt' $spec; then
219 s/$/ optional-packages.txt/
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/
232 #license=$(awk '/^License:/{print $2}' $template)
233 #sed -i -e "s/^License:.*/License:\t$license/" $spec
237 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
238 if ! diff -u $bak $spec > $diff; then
242 echo "$spec: No diffs"