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 makerpm command.
8 # requires tarball to exist in ../SOURCES.
9 # you should have all pear packages installed to get best results
11 # todo: adjust similiarily noautoreqdeps
12 # bugs: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
13 # see php-pear-DBA_Relational.spec
14 # SOmething strange: Requires: php-common < 4:3:5.1
16 # note: old version pf 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"
31 rc=$(awk '/^%define.*_rc/{print $NF}' $spec)
32 pre=$(awk '/^%define.*_pre/{print $NF}' $spec)
33 beta=$(awk '/^%define.*_beta/{print $NF}' $spec)
34 tarball=$(rpm -q --qf "../SOURCES/%{name}-%{version}$rc$pre$beta.tgz\n" --specfile "$spec" | head -n 1 | sed -e 's,php-pear-,,')
36 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
42 License: @release_license@
43 State: @release_state@
45 pear makerpm --spec-template=$stmp $tarball
48 template=$(rpm -q --qf "%{name}-%{version}$rc$pre$beta.spec\n" --specfile "$spec" | head -n 1)
49 mv $template .$template~
52 # take as argument dependency in form NAME EQUALITY VERSION
53 # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
60 if [[ "$ver" = *:* ]]; then
65 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
66 epoch=$(echo "$query" | grep -v 'installed' || :)
67 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
68 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
74 preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
75 # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
76 sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
79 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
82 requires=$(grep '^Requires:' $template || :)
83 if [ -n "$requires" ]; then
84 echo "$requires" | while read tag dep; do
86 if ! grep -q "^Requires:.*$dep" $preamble; then
87 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
93 conflicts=$(grep '^Conflicts:' $template || :)
94 if [ -n "$conflicts" ]; then
95 echo "$conflicts" | while read tag dep; do
97 if ! grep -q "^Conflicts:.*$req" $preamble; then
98 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
103 # parse optional deps
104 optional=$(grep '^Optional:' $template || :)
105 if [ -n "$optional" ]; then
106 echo "$optional" | while read tag dep; do
108 m=$(grep "^%define.*_noautoreq" $spec | fgrep -o "$req" || :)
110 sed -i -e "/^%define.*_noautoreq/s/$/ $req/" $spec
117 state=$(awk '/^State:/{print $2}' $template)
118 sed -i -e "/^%define.*_status/{
119 /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/
124 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
125 if ! diff -u $bak $spec > $diff; then
129 echo "$spec: No diffs"