]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - pearize.sh
- fix epoch adding
[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 # you should have all pear packages installed to get best results
10 #
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
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
19 set -e
20 spec="$1"
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
29 echo "Processing $spec"
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-,,')
35
36 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
37 cat > $stmp <<'EOF'
38 @extra_headers@
39 Optional: @optional@
40 License: @release_license@
41 State: @release_state@
42 EOF
43 pear makerpm --spec-template=$stmp $tarball
44 rm -f $stmp
45
46 template=$(rpm -q --qf "%{name}-%{version}$rc$pre$beta.spec\n" --specfile "$spec" | head -n 1)
47 mv $template .$template~
48 template=.$template~
49
50 # take as argument dependency in form NAME EQUALITY VERSION
51 # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
52 add_epoch() {
53         local dep="$@"
54         local pkg="$1"
55         local ver="$3"
56
57         # already have epoch
58         if [[ "$ver" = *:* ]]; then
59                 echo "$dep"
60                 return
61         fi
62
63         query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
64         epoch=$(echo "$query" | grep -v 'installed' || :)
65         if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
66                 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
67         else
68                 echo "$dep"
69         fi
70 }
71
72 preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
73 # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
74 sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
75
76 # create backup
77 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
78
79 # parse requires
80 requires=$(grep '^Requires:' $template || :)
81 if [ -n "$requires" ]; then
82         echo "$requires" | while read tag dep; do
83                 dep=$(add_epoch $dep)
84                 if ! grep -q "^Requires:.*$dep" $preamble; then
85                         sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
86                 fi
87         done
88 fi
89
90 # parse conflicts
91 conflicts=$(grep '^Conflicts:' $template || :)
92 if [ -n "$conflicts" ]; then
93         echo "$conflicts" | while read tag dep; do
94                 dep=$(add_epoch $dep)
95                 if ! grep -q "^Conflicts:.*$req" $preamble; then
96                         sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
97                 fi
98         done
99 fi
100
101 # parse state
102 state=$(awk '/^State:/{print $2}' $template)
103 sed -i -e "/^%define.*_status/{
104         /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/
105 }" $spec
106
107 rm -f $preamble
108
109 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
110 if ! diff -u $bak $spec > $diff; then
111         vim -o $spec $diff
112         rm -f $diff
113 else
114         echo "$spec: No diffs"
115 fi
116 #exit 1
This page took 0.106761 seconds and 4 git commands to generate.