]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame_incremental - pearize.sh
- avoid overwriting actual specfile
[packages/rpm-build-tools.git] / pearize.sh
... / ...
CommitLineData
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' for 'pear makerpm' command, ./builder for fetching sources.
8# You should have all PEAR packages installed to get best results.
9#
10# todo: adjust similiarily noautoreqdeps
11# bugs: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
12# see php-pear-DBA_Relational.spec
13# Something strange: Requires: php-common < 4:3:5.1
14#
15# NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE.
16#
17# Send blames and beer\b\b\b\bideas to glen@pld-linux.org
18
19set -e
20spec="$1"
21if [ -z "$spec" ]; then
22 echo >&2 "Usage: $0 SPECFILE"
23 exit 0
24fi
25if [ ! -f "$spec" ]; then
26 echo >&2 "$spec doesn't exist?"
27 exit 1
28fi
29echo "Processing $spec"
30
31getsource() {
32 local spec="$1"
33 local NR="$2"
34 rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}"
35}
36
37tarball=$(getsource $spec 0)
38
39if [ ! -f $tarball ]; then
40 ./builder -g "$spec"
41fi
42
43stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
44cat > $stmp <<'EOF'
45@extra_headers@
46Optional: @optional@
47@optional-pkg@
48@optional-ext@
49License: @release_license@
50State: @release_state@
51EOF
52pear makerpm --spec-template=$stmp --rpm-pkgname=pearize $tarball
53template=pearize.spec
54rm -f $stmp
55
56mv $template .$template~
57template=.$template~
58
59# take as argument dependency in form NAME EQUALITY VERSION
60# adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
61add_epoch() {
62 local dep="$@"
63 local pkg="$1"
64 local ver="$3"
65
66 # already have epoch
67 if [[ "$ver" = *:* ]]; then
68 echo "$dep"
69 return
70 fi
71
72 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
73 epoch=$(echo "$query" | grep -v 'installed' || :)
74 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
75 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
76 else
77 echo "$dep"
78 fi
79}
80
81preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
82# take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
83sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
84
85# create backup
86bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
87
88# parse requires
89requires=$(grep '^Requires:' $template || :)
90if [ -n "$requires" ]; then
91 echo "$requires" | while read tag dep; do
92 dep=$(add_epoch $dep)
93 if ! grep -q "^Requires:.*$dep" $preamble; then
94 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
95 fi
96 done
97fi
98
99# parse conflicts
100conflicts=$(grep '^Conflicts:' $template || :)
101if [ -n "$conflicts" ]; then
102 echo "$conflicts" | while read tag dep; do
103 dep=$(add_epoch $dep)
104 if ! grep -q "^Conflicts:.*$req" $preamble; then
105 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
106 fi
107 done
108fi
109
110# parse optional deps
111optional=$(grep '^Optional:' $template || :)
112if [ -n "$optional" ]; then
113 echo "$optional" | while read tag dep; do
114 for req in $dep; do
115 m=$(grep "^%define.*_noautoreq" $spec | grep -o "$req" || :)
116 if [ -z "$m" ]; then
117 sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
118 fi
119 done
120 done
121fi
122has_opt=$(egrep -c '^Optional-(pkg|ext):' $template || :)
123if [ "$has_opt" -gt 0 ]; then
124 if ! grep -q optional-packages.txt $spec; then
125 sed -i -e '
126 /^%clean/{
127 i%post
128 iif [ -f %{_docdir}/%{name}-%{version}/optional-packages.txt ]; then
129 i\ cat %{_docdir}/%{name}-%{version}/optional-packages.txt
130 ifi
131 i
132 }
133 /^%doc install.log/{
134 s/$/ optional-packages.txt/
135 }
136 ' $spec
137 fi
138fi
139
140# parse state
141state=$(awk '/^State:/{print $2}' $template)
142sed -i -e "/^%define.*_status/{
143 /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/
144}" $spec
145
146rm -f $preamble
147
148diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
149if ! diff -u $bak $spec > $diff; then
150 vim -o $spec $diff
151 rm -f $diff
152else
153 echo "$spec: No diffs"
154fi
155#exit 1
This page took 0.043821 seconds and 4 git commands to generate.