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 makerpm' command, ./builder for fetching sources.
8 # You should have all PEAR packages installed to get best results (needed for epoch autodetection)
10 # todo: adjust similiarily noautoreqdeps
11 # bugs: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
12 # see php-pear-DBA_Relational.spec
13 # Something strange: Requires: php-common < 4:3:5.1
15 # NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE.
17 # Send blames and beer
\b\b\b\bideas to glen@pld-linux.org
21 if [ -z "$spec" ]; then
22 echo >&2 "Usage: $0 SPECFILE"
25 if [ ! -f "$spec" ]; then
26 echo >&2 "$spec doesn't exist?"
29 echo "Processing $spec"
34 rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}"
37 tarball=$(getsource $spec 0)
38 if [ -z "$tarball" ]; then
39 echo >&2 "Spec is missing Source0!"
43 if [ ! -f $tarball ]; then
47 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
53 License: @release_license@
54 State: @release_state@
56 pear make-rpm-spec --spec-template=$stmp --output=pearize.spec $tarball
60 mv $template .$template~
63 # take as argument dependency in form NAME EQUALITY VERSION
64 # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
71 if [[ "$ver" = *:* ]]; then
76 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
77 epoch=$(echo "$query" | grep -v 'installed' || :)
78 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
79 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
85 preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
86 # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
87 sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
90 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
93 requires=$(grep '^Requires:' $template || :)
94 if [ -n "$requires" ]; then
95 echo "$requires" | while read tag dep; do
97 if ! grep -q "^Requires:.*$dep" $preamble; then
98 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
104 conflicts=$(grep '^Conflicts:' $template || :)
105 if [ -n "$conflicts" ]; then
106 echo "$conflicts" | while read tag dep; do
107 dep=$(add_epoch $dep)
108 if ! grep -q "^Conflicts:.*$req" $preamble; then
109 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
114 # parse optional deps
115 optional=$(grep '^Optional:' $template || :)
116 if [ -n "$optional" ]; then
117 echo "$optional" | while read tag dep; do
119 m=$(grep "^%define.*_noautoreq" $spec || :)
121 sed -i -e "/^BuildRoot:/{
123 a# exclude optional dependencies
124 a%define\ \ _noautoreq\ $req
128 m=$(echo "$m" | grep -o "$req" || :)
130 sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
136 has_opt=$(egrep -c '^Optional-(pkg|ext):' $template || :)
137 if [ "$has_opt" -gt 0 ]; then
138 if ! grep -q '%{_docdir}/.*/optional-packages.txt' $spec; then
142 iif [ -f %{_docdir}/%{name}-%{version}/optional-packages.txt ]; then
143 i\ cat %{_docdir}/%{name}-%{version}/optional-packages.txt
149 if ! grep -q '%doc.*optional-packages.txt' $spec; then
152 s/$/ optional-packages.txt/
159 state=$(awk '/^State:/{print $2}' $template)
160 sed -i -e "/^%define.*_status/{
161 /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/
166 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
167 if ! diff -u $bak $spec > $diff; then
171 echo "$spec: No diffs"