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