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