]>
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 | # | |
7 | # needs pear makerpm command. | |
70f6b6a6 | 8 | # requires tarball to exist in ../SOURCES. |
c4bf44d2 | 9 | # you should have all pear packages installed to get best results |
dd7e9d0e ER |
10 | # |
11 | # todo: adjust similiarily noautoreqdeps | |
c4bf44d2 ER |
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 | |
dd7e9d0e ER |
15 | # |
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 | |
18 | ||
70f6b6a6 ER |
19 | set -e |
20 | spec="$1" | |
dd7e9d0e ER |
21 | if [ -z "$spec" ]; then |
22 | echo >&2 "Usage: $0 SPECFILE" | |
23 | exit 0 | |
24 | fi | |
25 | if [ ! -f "$spec" ]; then | |
26 | echo >&2 "$spec doesn't exist?" | |
27 | exit 1 | |
28 | fi | |
ae02a056 | 29 | echo "Processing $spec" |
c4bf44d2 ER |
30 | |
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-,,') | |
70f6b6a6 | 35 | |
4188dbdf ER |
36 | stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
37 | cat > $stmp <<'EOF' | |
38 | @extra_headers@ | |
39 | Optional: @optional@ | |
40 | EOF | |
5e241fea | 41 | template=$(rpm -q --qf "%{name}-%{version}$rc$pre$beta.spec\n" --specfile "$spec" | head -n 1) |
4188dbdf | 42 | |
5e241fea ER |
43 | pear makerpm --spec-template=$stmp $tarball |
44 | mv $template .$template~ | |
45 | template=.$template~ | |
19133cbd | 46 | |
dd7e9d0e ER |
47 | requires=$(grep '^Requires:' $template || :) |
48 | conflicts=$(grep '^Conflicts:' $template || :) | |
49 | preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") | |
50 | # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things. | |
51 | sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble | |
52 | ||
53 | # take as argument dependency in form NAME EQUALITY VERSION | |
54 | # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero. | |
55 | add_epoch() { | |
56 | local dep="$@" | |
57 | local pkg="$1" | |
a36710cb ER |
58 | local ver="$3" |
59 | ||
60 | # already have epoch | |
61 | if [[ "$ver" = *:* ]]; then | |
62 | echo "$dep" | |
63 | return | |
64 | fi | |
65 | ||
dd7e9d0e ER |
66 | query=$(rpm -q --qf '%{epoch}\n' $pkg || :) |
67 | epoch=$(echo "$query" | grep -v 'installed' || :) | |
68 | if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then | |
69 | echo "$dep" | sed -e "s, [<>=] ,&$epoch:," | |
70 | else | |
71 | echo "$dep" | |
72 | fi | |
19133cbd ER |
73 | } |
74 | ||
dd7e9d0e ER |
75 | # create backup |
76 | bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" ) | |
19133cbd | 77 | |
dd7e9d0e ER |
78 | if [ -n "$requires" ]; then |
79 | echo "$requires" | while read tag dep; do | |
80 | dep=$(add_epoch $dep) | |
81 | if ! grep -q "^Requires:.*$dep" $preamble; then | |
82 | sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec | |
83 | fi | |
84 | done | |
c9f81079 ER |
85 | fi |
86 | ||
dd7e9d0e ER |
87 | if [ -n "$conflicts" ]; then |
88 | echo "$conflicts" | while read tag reqc; do | |
89 | dep=$(add_epoch $dep) | |
90 | if ! grep -q "^Conflicts:.*$req" $preamble; then | |
91 | sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec | |
92 | fi | |
93 | done | |
05779902 ER |
94 | fi |
95 | ||
dd7e9d0e | 96 | rm -f $preamble |
4d240bd1 | 97 | |
dd7e9d0e ER |
98 | diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") |
99 | if ! diff -u $bak $spec > $diff; then | |
100 | vim -o $spec $diff | |
101 | rm -f $diff | |
102 | else | |
103 | echo "$spec: No diffs" | |
4d240bd1 | 104 | fi |
4188dbdf | 105 | rm -f $stmp |
c4bf44d2 | 106 | #exit 1 |