]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - pearize.sh
- stage2: this script will not adjust Requires/Conflicts lines of packages
[packages/rpm-build-tools.git] / pearize.sh
1 #!/bin/sh
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.
8 # requires tarball to exist in ../SOURCES.
9 #
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
17 set -e
18 spec="$1"
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
27 echo "Processing $spec"
28 tarball=$(rpm -q --qf '../SOURCES/%{name}-%{version}.tgz\n' --specfile "$spec" | head -n 1 | sed -e 's,php-pear-,,')
29 template=$(rpm -q --qf '%{name}-%{version}.spec\n' --specfile "$spec" | head -n 1)
30
31 pear makerpm --spec-template=template.spec $tarball
32 ls -l $spec $template
33
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
52 }
53
54 # create backup
55 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
56
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
64 fi
65
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
73 fi
74
75 rm -f $preamble
76
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"
84 fi
This page took 0.033655 seconds and 4 git commands to generate.