2 # VFS-wrapper for RPM (and src.rpm) files
4 # Copyright (C) 1996-2004,2009
5 # Free Software Foundation, Inc.
8 # Erik Troan <ewt@redhat.com> 1996
9 # Jakub Jelinek <jj@sunsite.mff.cuni.cz> 1996, 2004
10 # Tomasz Kłoczko <kloczek@rudy.mif.pg.gda.pl> 1997
11 # Wojtek Pilorz <wpilorz@bdk.lublin.pl>
13 # Michele Marziani <marziani@fe.infn.it>
15 # Marc Merlin <marcsoft@merlins.org> 1998
17 # Michal Svec <rebel@penguin.cz> 2000
19 # Andrew V. Samoilov <sav@bcs.zp.ua>
20 # 2004: Whitespace(s) & single quote(s) in filename workaround
21 # https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=64007
22 # Slava Zanko <slavazanko@gmail.com>
23 # 2009: Totally rewritten.
24 # Alexander Chumachenko <ledest@gmail.com>
25 # 2013: add dependency version output
26 # Denis Silakov <denis.silakov@rosalab.ru>
27 # 2013: tar payload support.
28 # Arkadiusz Miśkiewicz <arekm@maven.pl>
29 # 2013: improve support for EPOCH
30 # add support for PREINPROG/POSTINPROG/PREUNPROG/POSTUNPROG
31 # add support for VERIFYSCRIPTPROG
32 # add support for TRIGGERSCRIPTS/TRIGGERSCRIPTPROG
33 # Jiri Tyr <jiri.tyr@gmail.com>
34 # 2016: add support for PRETRANS/PRETRANSPROG/POSTTRANS/POSTTRANSPROG
36 # This file is part of the Midnight Commander.
38 # This program is free software: you can redistribute it and/or modify
39 # it under the terms of the GNU General Public License as published by
40 # the Free Software Foundation, either version 3 of the License, or
41 # (at your option) any later version.
43 # This program is distributed in the hope that it will be useful,
44 # but WITHOUT ANY WARRANTY; without even the implied warranty of
45 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 # GNU General Public License for more details.
48 # You should have received a copy of the GNU General Public License
49 # along with this program. If not, see <http://www.gnu.org/licenses/>.
52 # override any locale for dates
57 if rpmbuild
--version >/dev
/null
2>&1; then
63 if rpm
--nosignature --version >/dev
/null
2>&1; then
64 RPM
="rpm --nosignature"
65 RPMBUILD
="$RPMBUILD --nosignature"
69 RPM_QUERY_FMT
="$RPM -qp --qf"
75 rpm_filename
=$1; shift
77 FILEPREF
="-r--r--r-- 1 root root "
79 mcrpmfs_getSupportedTags
()
84 mcrpmfs_getDesription
()
86 $RPM -qip "${rpm_filename}"
89 mcrpmfs_getAllNeededTags
()
91 supportedTags
=`mcrpmfs_getSupportedTags`
92 if test "`echo supportedTags | grep -c CONFLICTS`" -eq 1; then
93 tag_CONFLICTS
="|CONFLICTS=%{CONFLICTS}"
100 "|VERSION=%{VERSION}"\
101 "|RELEASE=%{RELEASE}"\
102 "|DISTRIBUTION=%{DISTRIBUTION}"\
104 "|DESCRIPTION=%{DESCRIPTION}"\
105 "|SUMMARY=%{SUMMARY}"\
108 "|LICENSE=%{LICENSE}"\
109 "|REQUIRES=%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}"\
110 "|OBSOLETES=%{OBSOLETES}"\
111 "|PROVIDES=%{PROVIDES} %{PROVIDEFLAGS:depflags} %{PROVIDEVERSION}"\
113 "|PACKAGER=%{PACKAGER}" \
115 |
tr '\n' ' ' # The newlines in DESCRIPTION mess with the sed script in mcrpmfs_getOneTag().
118 mcrpmfs_getRawOneTag
()
120 $RPM_QUERY_FMT "$1" "${rpm_filename}"
125 echo "$AllTAGS" |
$SED "s/.*|${1}=//" | cut
-d '|' -f 1
128 mcrpmfs_printOneMetaInfo
()
130 if test "$3" = "raw"; then
131 metaInfo
=`mcrpmfs_getRawOneTag "%{$2}"`
133 metaInfo
=`mcrpmfs_getOneTag "$2"`
136 if test -n "${metaInfo}" -a "${metaInfo}" != "(none)"; then
137 echo "${FILEPREF} 0 ${DATE} ${1}"
143 mcrpmfs_list_fastRPM
()
145 echo "$FILEPREF 0 $DATE INFO/DISTRIBUTION"
146 echo "$FILEPREF 0 $DATE INFO/VENDOR"
147 echo "$FILEPREF 0 $DATE INFO/DESCRIPTION"
148 echo "$FILEPREF 0 $DATE INFO/SUMMARY"
149 echo "dr-xr-xr-x 1 root root 0 $DATE INFO/SCRIPTS"
150 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PRETRANS"
151 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTTRANS"
152 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREIN"
153 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTIN"
154 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREUN"
155 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTUN"
156 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/VERIFYSCRIPT"
157 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/TRIGGERSCRIPTS"
158 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
159 echo "$FILEPREF 0 $DATE INFO/PACKAGER"
160 echo "$FILEPREF 0 $DATE INFO/URL"
161 echo "$FILEPREF 0 $DATE INFO/EPOCH"
162 echo "$FILEPREF 0 $DATE INFO/LICENSE"
163 echo "$FILEPREF 0 $DATE INFO/REQUIRES"
164 echo "$FILEPREF 0 $DATE INFO/OBSOLETES"
165 echo "$FILEPREF 0 $DATE INFO/PROVIDES"
166 echo "$FILEPREF 0 $DATE INFO/CONFLICTS"
167 echo "$FILEPREF 0 $DATE INFO/CHANGELOG"
170 mcrpmfs_list_fullRPM
()
172 mcrpmfs_printOneMetaInfo
"INFO/DISTRIBUTION" "DISTRIBUTION"
173 mcrpmfs_printOneMetaInfo
"INFO/VENDOR" "VENDOR"
174 mcrpmfs_printOneMetaInfo
"INFO/DESCRIPTION" "DESCRIPTION"
175 mcrpmfs_printOneMetaInfo
"INFO/SUMMARY" "SUMMARY"
177 if test "`mcrpmfs_getRawOneTag \"%{RPMTAG_PRETRANS}%{RPMTAG_POSTTRANS}%{RPMTAG_PREIN}%{RPMTAG_POSTIN}%{RPMTAG_PREUN}%{RPMTAG_POSTUN}%{VERIFYSCRIPT}%{TRIGGERSCRIPTS}\"`" != "(none)(none)(none)(none)(none)(none)(none)(none)"; then
178 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/PRETRANS" "RPMTAG_PRETRANS" "raw"
179 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/POSTTRANS" "RPMTAG_POSTTRANS" "raw"
180 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/PREIN" "RPMTAG_PREIN" "raw"
181 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/POSTIN" "RPMTAG_POSTIN" "raw"
182 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/PREUN" "RPMTAG_PREUN" "raw"
183 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/POSTUN" "RPMTAG_POSTUN" "raw"
184 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/VERIFYSCRIPT" "VERIFYSCRIPT" "raw"
185 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/TRIGGERSCRIPTS" "TRIGGERSCRIPTS" "raw"
186 echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
189 if test "`mcrpmfs_getRawOneTag \"%{RPMTAG_PRETRANSPROG}%{RPMTAG_POSTTRANSPROG}%{RPMTAG_PREINPROG}%{RPMTAG_POSTINPROG}%{RPMTAG_PREUNPROG}%{RPMTAG_POSTUNPROG}%{VERIFYSCRIPTPROG}%{TRIGGERSCRIPTPROG}\"`" != "(none)(none)(none)(none)(none)(none)(none)(none)"; then
190 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/PRETRANSPROG" "RPMTAG_PRETRANSPROG" "raw"
191 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/POSTTRANSPROG" "RPMTAG_POSTTRANSPROG" "raw"
192 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/PREINPROG" "RPMTAG_PREINPROG" "raw"
193 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/POSTINPROG" "RPMTAG_POSTINPROG" "raw"
194 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/PREUNPROG" "RPMTAG_PREUNPROG" "raw"
195 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/POSTUNPROG" "RPMTAG_POSTUNPROG" "raw"
196 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/VERIFYSCRIPTPROG" "VERIFYSCRIPTPROG" "raw"
197 mcrpmfs_printOneMetaInfo
"INFO/SCRIPTS/TRIGGERSCRIPTPROG" "TRIGGERSCRIPTPROG" "raw"
200 mcrpmfs_printOneMetaInfo
"INFO/PACKAGER" "PACKAGER"
201 mcrpmfs_printOneMetaInfo
"INFO/URL" "URL"
202 mcrpmfs_printOneMetaInfo
"INFO/EPOCH" "EPOCH"
203 mcrpmfs_printOneMetaInfo
"INFO/LICENSE" "LICENSE"
205 mcrpmfs_printOneMetaInfo
"INFO/REQUIRES" "REQUIRES"
206 mcrpmfs_printOneMetaInfo
"INFO/OBSOLETES" "OBSOLETES"
207 mcrpmfs_printOneMetaInfo
"INFO/PROVIDES" "PROVIDES"
208 mcrpmfs_printOneMetaInfo
"INFO/CONFLICTS" "CONFLICTS"
209 mcrpmfs_printOneMetaInfo
"INFO/CHANGELOG" "CHANGELOGTEXT" "raw"
214 # set MCFASTRPM_DFLT to 1 for faster rpm files handling by default, to 0 for
217 if test -z "$MCFASTRPM"; then
218 MCFASTRPM
=$MCFASTRPM_DFLT
221 DESC
=`mcrpmfs_getDesription 2>/dev/null` ||
{
222 echo "$FILEPREF 0 "`date +"%b %d %H:%M"`" ERROR"
225 DATE
=`mcrpmfs_getRawOneTag "%{BUILDTIME:date}\n" | cut -c 5-11,21-24`
226 PAYLOAD
=`mcrpmfs_getRawOneTag "%{PAYLOADFORMAT}\n" | sed s/ustar/tar/`
228 HEADERSIZE
=`printf '%s\n' "$DESC" | wc -c` # 'echo' can't be used for arbitrary data (see commit message).
229 printf '%s %s %s HEADER\n' "${FILEPREF}" "${HEADERSIZE}" "${DATE}"
230 echo "-r-xr-xr-x 1 root root 39 $DATE INSTALL"
231 case "${rpm_filename}" in
233 echo "-r-xr-xr-x 1 root root 39 $DATE REBUILD"
236 echo "-r-xr-xr-x 1 root root 39 $DATE UPGRADE"
240 echo "dr-xr-xr-x 3 root root 0 $DATE INFO"
241 if [ `mcrpmfs_getRawOneTag "%{EPOCH}"` = "(none)" ]; then
242 echo "$FILEPREF 0 $DATE INFO/NAME-VERSION-RELEASE"
244 echo "$FILEPREF 0 $DATE INFO/NAME-EPOCH:VERSION-RELEASE"
246 echo "$FILEPREF 0 $DATE INFO/GROUP"
247 echo "$FILEPREF 0 $DATE INFO/BUILDHOST"
248 echo "$FILEPREF 0 $DATE INFO/SOURCERPM"
249 echo "$FILEPREF 0 $DATE INFO/BUILDTIME"
250 echo "$FILEPREF 0 $DATE INFO/RPMVERSION"
251 echo "$FILEPREF 0 $DATE INFO/OS"
252 echo "$FILEPREF 0 $DATE INFO/SIZE"
254 if test "$MCFASTRPM" = 0 ; then
260 echo "$FILEPREF 0 $DATE CONTENTS.$PAYLOAD"
266 HEADER
) mcrpmfs_getDesription
> "$2"; exit 0;;
268 echo "# Run this script to install this RPM package" > "$2"
269 echo $RPM -ivh "${rpm_filename}" >> "$2"
273 echo "# Run this to upgrade this RPM package" > "$2"
274 echo $RPM -Uvh "${rpm_filename}" >> "$2"
278 echo "# Run this to rebuild this RPM package" > "$2"
279 echo $RPMBUILD --rebuild "${rpm_filename}" >> "$2"
282 ERROR
) mcrpmfs_getDesription
> /dev
/null
2> "$2"; exit 0;;
283 INFO
/NAME-VERSION-RELEASE
)
284 echo `mcrpmfs_getOneTag "NAME"`-`mcrpmfs_getOneTag "VERSION"`-`mcrpmfs_getOneTag "RELEASE"` > "$2"
287 INFO
/NAME-EPOCH
:VERSION-RELEASE
)
288 echo `mcrpmfs_getOneTag "NAME"`-`mcrpmfs_getOneTag "EPOCH"`:`mcrpmfs_getOneTag "VERSION"`-`mcrpmfs_getOneTag "RELEASE"` > "$2"
291 INFO
/RELEASE
) mcrpmfs_getOneTag
"RELEASE" > "$2"; exit 0;;
292 INFO
/GROUP
) mcrpmfs_getRawOneTag
"%{GROUP}\n" > "$2"; exit 0;;
293 INFO
/DISTRIBUTION
) mcrpmfs_getOneTag
"DISTRIBUTION" > "$2"; exit 0;;
294 INFO
/VENDOR
) mcrpmfs_getOneTag
"VENDOR" > "$2"; exit 0;;
295 INFO
/BUILDHOST
) mcrpmfs_getRawOneTag
"%{BUILDHOST}\n" > "$2"; exit 0;;
296 INFO
/SOURCERPM
) mcrpmfs_getRawOneTag
"%{SOURCERPM}\n" > "$2"; exit 0;;
297 INFO
/DESCRIPTION
) mcrpmfs_getRawOneTag
"%{DESCRIPTION}\n" > "$2"; exit 0;;
298 INFO
/PACKAGER
) mcrpmfs_getOneTag
"PACKAGER" > "$2"; exit 0;;
299 INFO
/URL
) mcrpmfs_getOneTag
"URL" >"$2"; exit 0;;
300 INFO
/BUILDTIME
) mcrpmfs_getRawOneTag
"%{BUILDTIME:date}\n" >"$2"; exit 0;;
301 INFO
/EPOCH
) mcrpmfs_getOneTag
"EPOCH" >"$2"; exit 0;;
302 INFO
/LICENSE
) mcrpmfs_getOneTag
"LICENSE" >"$2"; exit 0;;
303 INFO
/RPMVERSION
) mcrpmfs_getRawOneTag
"%{RPMVERSION}\n" >"$2"; exit 0;;
304 INFO
/REQUIRES
) mcrpmfs_getRawOneTag
"[%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}\n]" >"$2"; exit 0;;
305 INFO
/PROVIDES
) mcrpmfs_getRawOneTag
"[%{PROVIDES} %{PROVIDEFLAGS:depflags} %{PROVIDEVERSION}\n]" >"$2"; exit 0;;
306 INFO
/SCRIPTS
/PRETRANS
) mcrpmfs_getRawOneTag
"%{RPMTAG_PRETRANS}\n" >"$2"; exit 0;;
307 INFO
/SCRIPTS
/PRETRANSPROG
) mcrpmfs_getRawOneTag
"%{RPMTAG_PRETRANSPROG}\n" >"$2"; exit 0;;
308 INFO
/SCRIPTS
/POSTTRANS
) mcrpmfs_getRawOneTag
"%{RPMTAG_POSTTRANS}\n" >"$2"; exit 0;;
309 INFO
/SCRIPTS
/POSTTRANSPROG
) mcrpmfs_getRawOneTag
"%{RPMTAG_POSTTRANSPROG}\n" >"$2"; exit 0;;
310 INFO
/SCRIPTS
/PREIN
) mcrpmfs_getRawOneTag
"%{RPMTAG_PREIN}\n" >"$2"; exit 0;;
311 INFO
/SCRIPTS
/PREINPROG
) mcrpmfs_getRawOneTag
"%{RPMTAG_PREINPROG}\n" >"$2"; exit 0;;
312 INFO
/SCRIPTS
/POSTIN
) mcrpmfs_getRawOneTag
"%{RPMTAG_POSTIN}\n" >"$2"; exit 0;;
313 INFO
/SCRIPTS
/POSTINPROG
) mcrpmfs_getRawOneTag
"%{RPMTAG_POSTINPROG}\n" >"$2"; exit 0;;
314 INFO
/SCRIPTS
/PREUN
) mcrpmfs_getRawOneTag
"%{RPMTAG_PREUN}\n" >"$2"; exit 0;;
315 INFO
/SCRIPTS
/PREUNPROG
) mcrpmfs_getRawOneTag
"%{RPMTAG_PREUNPROG}\n" >"$2"; exit 0;;
316 INFO
/SCRIPTS
/POSTUN
) mcrpmfs_getRawOneTag
"%{RPMTAG_POSTUN}\n" >"$2"; exit 0;;
317 INFO
/SCRIPTS
/POSTUNPROG
) mcrpmfs_getRawOneTag
"%{RPMTAG_POSTUNPROG}\n" >"$2"; exit 0;;
318 INFO
/SCRIPTS
/VERIFYSCRIPT
) mcrpmfs_getRawOneTag
"%{VERIFYSCRIPT}\n" > "$2"; exit 0;;
319 INFO
/SCRIPTS
/VERIFYSCRIPTPROG
) mcrpmfs_getRawOneTag
"%{VERIFYSCRIPTPROG}\n" > "$2"; exit 0;;
320 INFO
/SCRIPTS
/TRIGGERSCRIPTS
) $RPM -qp --triggers "${rpm_filename}" > "$2"; exit 0;;
321 INFO
/SCRIPTS
/TRIGGERSCRIPTPROG
) mcrpmfs_getRawOneTag
"%{TRIGGERSCRIPTPROG}\n" > "$2"; exit 0;;
322 INFO
/SCRIPTS
/ALL
) $RPM -qp --scripts "${rpm_filename}" > "$2"; exit 0;;
323 INFO
/SUMMARY
) mcrpmfs_getRawOneTag
"%{SUMMARY}\n" > "$2"; exit 0;;
324 INFO
/OS
) mcrpmfs_getRawOneTag
"%{OS}\n" > "$2"; exit 0;;
325 INFO
/CHANGELOG
) mcrpmfs_getRawOneTag
"[* %{CHANGELOGTIME:date} %{CHANGELOGNAME}\n%{CHANGELOGTEXT}\n\n]\n" > "$2"; exit 0;;
326 INFO
/SIZE
) mcrpmfs_getRawOneTag
"%{SIZE} bytes\n" > "$2"; exit 0;;
327 INFO
/OBSOLETES
) mcrpmfs_getRawOneTag
"[%{OBSOLETENAME} %|OBSOLETEFLAGS?{%{OBSOLETEFLAGS:depflags} %{OBSOLETEVERSION}}:{}|\n]" > "$2"; exit 0;;
328 INFO
/CONFLICTS
) mcrpmfs_getRawOneTag
"[%{CONFLICTNAME} %{CONFLICTFLAGS:depflags} %{CONFLICTVERSION}\n]" >"$2"; exit 0;;
329 CONTENTS.
*) $RPM2CPIO "${rpm_filename}" > "$2"; exit 0;;
338 INSTALL
) echo "Installing \"${rpm_filename}\""; $RPM -ivh "${rpm_filename}"; exit 0;;
339 UPGRADE
) echo "Upgrading \"${rpm_filename}\""; $RPM -Uvh "${rpm_filename}"; exit 0;;
340 REBUILD
) echo "Rebuilding \"${rpm_filename}\""; $RPMBUILD --rebuild "${rpm_filename}"; exit 0;;
344 # Let the test framework override functions and variables.
345 [ -n "$MC_TEST_RPM_REWRITE" ] && .
"$MC_TEST_RPM_REWRITE"
347 AllTAGS
=`mcrpmfs_getAllNeededTags "$1"`
351 list
) mcrpmfs_list
; exit 0;;
352 copyout
) mcrpmfs_copyout
"$1" "$2"; exit 0;;
353 run
) mcrpmfs_run
"$1"; exit 1;;