]>
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 ER |
8 | # requires tarball to exist in ../SOURCES. |
9 | # | |
dd7e9d0e ER |
10 | # bugs: will not find tarball for packages with 'beta' and 'alpha' in version. |
11 | # | |
12 | # todo: adjust similiarily noautoreqdeps | |
13 | # | |
14 | # note: old version pf this script which was used to convert to new package format is in CVS branch MIGRATE | |
15 | # send blames and beer\b\b\b\bideas to glen@pld-linux.org | |
16 | ||
70f6b6a6 ER |
17 | set -e |
18 | spec="$1" | |
dd7e9d0e ER |
19 | if [ -z "$spec" ]; then |
20 | echo >&2 "Usage: $0 SPECFILE" | |
21 | exit 0 | |
22 | fi | |
23 | if [ ! -f "$spec" ]; then | |
24 | echo >&2 "$spec doesn't exist?" | |
25 | exit 1 | |
26 | fi | |
ae02a056 | 27 | echo "Processing $spec" |
461a16ad | 28 | tarball=$(rpm -q --qf '../SOURCES/%{name}-%{version}.tgz\n' --specfile "$spec" | head -n 1 | sed -e 's,php-pear-,,') |
2bf93f18 | 29 | template=$(rpm -q --qf '%{name}-%{version}.spec\n' --specfile "$spec" | head -n 1) |
70f6b6a6 | 30 | |
dd7e9d0e | 31 | pear makerpm --spec-template=template.spec $tarball |
5f89133e | 32 | ls -l $spec $template |
19133cbd | 33 | |
dd7e9d0e ER |
34 | requires=$(grep '^Requires:' $template || :) |
35 | conflicts=$(grep '^Conflicts:' $template || :) | |
36 | preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") | |
37 | # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things. | |
38 | sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble | |
39 | ||
40 | # take as argument dependency in form NAME EQUALITY VERSION | |
41 | # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero. | |
42 | add_epoch() { | |
43 | local dep="$@" | |
44 | local pkg="$1" | |
45 | query=$(rpm -q --qf '%{epoch}\n' $pkg || :) | |
46 | epoch=$(echo "$query" | grep -v 'installed' || :) | |
47 | if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then | |
48 | echo "$dep" | sed -e "s, [<>=] ,&$epoch:," | |
49 | else | |
50 | echo "$dep" | |
51 | fi | |
19133cbd ER |
52 | } |
53 | ||
dd7e9d0e ER |
54 | # create backup |
55 | bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" ) | |
19133cbd | 56 | |
dd7e9d0e ER |
57 | if [ -n "$requires" ]; then |
58 | echo "$requires" | while read tag dep; do | |
59 | dep=$(add_epoch $dep) | |
60 | if ! grep -q "^Requires:.*$dep" $preamble; then | |
61 | sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec | |
62 | fi | |
63 | done | |
c9f81079 ER |
64 | fi |
65 | ||
dd7e9d0e ER |
66 | if [ -n "$conflicts" ]; then |
67 | echo "$conflicts" | while read tag reqc; do | |
68 | dep=$(add_epoch $dep) | |
69 | if ! grep -q "^Conflicts:.*$req" $preamble; then | |
70 | sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec | |
71 | fi | |
72 | done | |
05779902 ER |
73 | fi |
74 | ||
dd7e9d0e | 75 | rm -f $preamble |
4d240bd1 | 76 | |
dd7e9d0e ER |
77 | set -e |
78 | diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX") | |
79 | if ! diff -u $bak $spec > $diff; then | |
80 | vim -o $spec $diff | |
81 | rm -f $diff | |
82 | else | |
83 | echo "$spec: No diffs" | |
4d240bd1 | 84 | fi |