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
33 if [ -z "$spec" ]; then
34 echo >&2 "Usage: $0 SPECFILE"
37 if [ ! -f "$spec" ]; then
38 echo >&2 "$spec doesn't exist?"
42 if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then
43 echo >&2 "Please install php-pear-PEAR_Command_Packaging"
46 echo "Processing $spec"
51 rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}"
54 tarball=$(getsource $spec 0)
55 if [ -z "$tarball" ]; then
56 echo >&2 "Spec is missing Source0!"
60 if [ ! -f $tarball ]; then
64 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
68 License: @release_license@
69 State: @release_state@
71 pear make-rpm-spec --spec-template=$stmp --output=$template $tarball
74 mv $template .$template~
77 # take as argument dependency in form NAME EQUALITY VERSION
78 # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
85 if [[ "$ver" = *:* ]]; then
90 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
91 epoch=$(echo "$query" | grep -v 'installed' || :)
92 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
93 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
99 preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
100 # take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
101 sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
104 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
106 # ensure rpm-build-macros is present
107 if ! grep -q "^BuildRequires:.*rpmbuild(macros)" $preamble; then
108 sed -i -e "/^BuildRequires:.*rpm-php-pearprov/aBuildRequires:\trpmbuild(macros) >= 1.300" $spec
111 requires=$(grep '^BuildRequires:' $template || :)
112 if [ -n "$requires" ]; then
113 echo "$requires" | while read tag dep; do
114 dep=$(add_epoch $dep)
115 if ! grep -q "^BuildRequires:.*$dep" $preamble; then
116 sed -i -e "/^BuildRoot/iBuildRequires:\t$dep" $spec
121 requires=$(grep '^Requires:' $template || :)
122 if [ -n "$requires" ]; then
123 echo "$requires" | while read tag dep; do
124 dep=$(add_epoch $dep)
125 if ! grep -q "^Requires:.*$dep" $preamble; then
126 dep=$(echo "$dep" | sed -e 's,php-pear-PEAR\b,php-pear-PEAR-core,')
127 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
133 conflicts=$(grep '^Conflicts:' $template || :)
134 if [ -n "$conflicts" ]; then
135 echo "$conflicts" | while read tag dep; do
136 dep=$(add_epoch $dep)
137 if ! grep -q "^Conflicts:.*$req" $preamble; then
138 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
143 # parse optional deps
144 optional=$(grep '^Suggests:' $template || :)
145 if [ -n "$optional" ]; then
146 echo "$optional" | while read tag dep; do
147 dep=$(add_epoch $dep)
148 if ! grep -q "^Suggests:.*$dep" $preamble; then
149 sed -i -e "/^BuildRoot/iSuggests:\t$dep" $spec
155 # convert pear package name to file pattern
156 req=$(echo "$req" | sed -e 's,^php-pear-,pear(,;y,_,/,;s,$,.*),')
159 # process only php-pear-* packages
164 m=$(grep "^%define.*_noautoreq" $spec || :)
166 sed -i -e "/^BuildRoot:/{
168 a# exclude optional dependencies
169 a%define\ \ _noautoreq\ $req
173 m=$(echo "$m" | grep -o "$req" || :)
175 sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
182 optional=$(grep '^Optional-ext:' $template || :)
183 if [ -n "$optional" ]; then
184 tmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
185 echo "$optional" | while read tag ext; do
186 grep -q "PHP extension .$ext" && continue
188 echo '%{name} can optionally use PHP extension "$ext"' >> optional-packages.txt
191 /%pear_package_setup/ {
199 has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :)
200 if [ "$has_opt" -gt 0 ]; then
201 if ! grep -q 'rpmbuild(macros)' $spec; then
204 aBuildRequires: rpmbuild(macros) >= 1.300
208 if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then
212 i%pear_package_print_optionalpackages
220 if ! grep -q '%doc.*optional-packages.txt' $spec; then
223 s/$/ optional-packages.txt/
230 state=$(awk '/^State:/{print $2}' $template)
231 sed -i -e "/^%define.*_status/{
232 /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/
236 #license=$(awk '/^License:/{print $2}' $template)
237 #sed -i -e "s/^License:.*/License:\t$license/" $spec
241 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
242 if ! diff -u $bak $spec > $diff; then
246 echo "$spec: No diffs"