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 :)
7 # needs 'pear' for 'pear make-rpm-spec' command, ./builder for fetching sources.
8 # You should have all PEAR packages installed to get best results (needed for epoch autodetection)
9 # So far there are 3 packages with epoch > 0:
10 # $ grep ^Epoch:.* php-pear-*.spec | grep -v 'Epoch:.*0'
11 # php-pear-MDB2.spec:Epoch: 1
12 # php-pear-MDB.spec:Epoch: 1
13 # php-pear-PEAR.spec:Epoch: 1
15 # To create completely new PEAR package spec, follow something like this:
16 # $ pear download RDF-alpha
17 # File RDF-0.1.0alpha1.tgz downloaded
18 # $ pear make-rpm-spec RDF-0.1.0alpha1.tgz
19 # Wrote RPM spec file php-pear-RDF.spec
22 # TODO: adjust similiarily noautoreqdeps
23 # BUGS: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
24 # see php-pear-DBA_Relational.spec
25 # Something strange: Requires: php-common < 4:3:5.1
27 # NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE.
29 # Send blames and beer
\b\b\b\bideas to glen@pld-linux.org
32 APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
36 if [ -z "$spec" ]; then
37 echo >&2 "Usage: $0 SPECFILE"
40 if [ ! -f "$spec" ]; then
41 echo >&2 "$spec doesn't exist?"
45 if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then
46 echo >&2 "Please install php-pear-PEAR_Command_Packaging"
49 echo "Processing $spec"
54 rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}"
57 tarball=$(getsource $spec 0)
58 if [ -z "$tarball" ]; then
59 echo >&2 "Spec is missing Source0!"
63 if [ ! -f $tarball ]; then
64 $APPDIR/builder -g "$spec"
67 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
71 License: @release_license@
72 State: @release_state@
74 pear make-rpm-spec --spec-template=$stmp --output=$template $tarball
77 mv $template .$template~
80 # take as argument dependency in form NAME EQUALITY VERSION
81 # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
88 if [[ "$ver" = *:* ]]; then
93 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
94 epoch=$(echo "$query" | grep -v 'installed' || :)
95 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
96 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
102 preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
103 # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
104 sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
107 bak=$(LC_ALL=C cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
109 # ensure rpm-build-macros is present
110 if ! grep -q "^BuildRequires:.*rpmbuild(macros)" $preamble; then
111 sed -i -e "/^BuildRequires:.*rpm-php-pearprov/aBuildRequires:\trpmbuild(macros) >= 1.300" $spec
114 requires=$(grep '^BuildRequires:' $template || :)
115 if [ -n "$requires" ]; then
116 echo "$requires" | while read tag dep; do
117 dep=$(add_epoch $dep)
118 if ! grep -q "^BuildRequires:.*$dep" $preamble; then
119 sed -i -e "/^BuildRoot/iBuildRequires:\t$dep" $spec
124 requires=$(grep '^Requires:' $template || :)
125 if [ -n "$requires" ]; then
126 echo "$requires" | while read tag dep; do
127 dep=$(add_epoch $dep)
128 if ! grep -q "^Requires:.*$dep" $preamble; then
129 dep=$(echo "$dep" | sed -e 's,php-pear-PEAR\b,php-pear-PEAR-core,')
130 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
136 conflicts=$(grep '^Conflicts:' $template || :)
137 if [ -n "$conflicts" ]; then
138 echo "$conflicts" | while read tag dep; do
139 dep=$(add_epoch $dep)
140 if ! grep -q "^Conflicts:.*$req" $preamble; then
141 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
146 # parse optional deps
147 optional=$(grep '^Suggests:' $template || :)
148 if [ -n "$optional" ]; then
149 echo "$optional" | while read tag dep; do
150 dep=$(add_epoch $dep)
151 if ! grep -q "^Suggests:.*$dep" $preamble; then
152 sed -i -e "/^BuildRoot/iSuggests:\t$dep" $spec
158 # convert pear package name to file pattern
159 req=$(echo "$req" | sed -e 's,^php-pear-,pear(,;y,_,/,;s,$,.*),')
162 # process only php-pear-* packages
167 m=$(grep "^%define.*_noautoreq" $spec || :)
169 sed -i -e "/^BuildRoot:/{
171 a# exclude optional dependencies
172 a%define\ \ _noautoreq\ $req
176 m=$(echo "$m" | grep -o "$req" || :)
178 sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
185 optional=$(grep '^Optional-ext:' $template || :)
186 if [ -n "$optional" ]; then
187 tmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
188 echo "$optional" | while read tag ext; do
189 grep -q "PHP extension .$ext" && continue
191 echo '%{name} can optionally use PHP extension "$ext"' >> optional-packages.txt
194 /%pear_package_setup/ {
202 has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :)
203 if [ "$has_opt" -gt 0 ]; then
204 if ! grep -q 'rpmbuild(macros)' $spec; then
207 aBuildRequires: rpmbuild(macros) >= 1.300
211 if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then
215 i%pear_package_print_optionalpackages
223 if ! grep -q '%doc.*optional-packages.txt' $spec; then
226 s/$/ optional-packages.txt/
233 state=$(awk '/^State:/{print $2}' $template)
234 sed -i -e "/^%define.*_\?status/{
235 s/%define[[:space:]]*_status.*/%define\t\t_status\t\t$state/
236 s/%define[[:space:]]*status.*/%define\t\tstatus\t\t$state/
240 #license=$(awk '/^License:/{print $2}' $template)
241 #sed -i -e "s/^License:.*/License:\t$license/" $spec
245 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
246 if ! diff -u $bak $spec > $diff; then
250 echo "$spec: No diffs"