未安装RPM包内文件树及脚本获取
RPM(RedHatPackageManager)软件包管理工具是某些Linux系统中的打包以及安装卸载软件工具,使用十分方便,本文主要从两个方面出发来介绍:
1、RPM包的具体构成;
2、RPM包在未安装的情况下,提取包中的文件树信息以及与包相关的脚本信息。
RPM包的具体构成
RPM package filescontain four sections. The first is a leading identification areathat marks the file as an RPM package (created with a particularversion of the RPM system). The remaining sections are the signature,the tagged data (called the header), and the payload. Each of thesesections has important information about the package, although thepayload section contains the actual content of the package.
Signature
The signatureappears after the lead or identifier section, which marks the file asan RPM file. Like your signature when you sign a check, the RPMsignature helps verify the integrity of the package. No, thesignature doesn’t check for bugs in software applications. Instead,it ensures that you have downloaded a valid RPM archive.
The signature worksby performing a mathematical function on the header and archivesections of the file. The mathematical function can be an encryptionprocess, such as PGP (Pretty Good Privacy), or a message digest inMD5 format.
Header
The header containszero or more tagged blocks of data that pertain to the package. Theheader contains information such as copyright messages, versionnumbers, and package summaries.The optional PRE tag holds apre-installation script, a script that the rpm command runs prior toinstalling the files in the package payload.
Payload
The payload sectioncontains the actual files used in the package. These files areinstalled when you install the package. To save space, data in thepayload section is compressed in GNU gzip format.
上边这几段节选自fedoraRPM Guide文档(http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/index.html),由上可知RPM包最核心的东西就是Header和Payload,前者主要包含RPM包的一些基本信息以及包在安装或者卸载时执行的脚本,后者主要包括就是RPM包真正安装到系统中的文件。
RPM内容获取
1)文件树获取,即真正安装到系统中的文件获取。
在Linux环境下,可以使用rpm2cpio结合cpio命令获取。具体用法如下:
rpm2cpiogimp-devel-2.6.9-6.el6_5.x86_64.rpm | cpio -dimv
执行完毕后即可在当前目录看到gimp包解压出来的文件在Windows环境下,可以直接使用压缩软件进行解压查看,比如用7-Zip查看
2)脚本获取,即在软件安装或卸载时执行的脚本程序。
在Linux环境下,可以使用rpm命令获取。具体用法如下:
rpm-qp --scripts jdk-7u25-linux-x64.rpm > jdk-7u25-linux-x64.sh
一般会包括preinstallation, postinstallation,preuninstallation,以及postuninstallationscripts,有的包可能不需要部分脚本。另外,如果软件包已经安装,也可以获取相关脚本,去掉上边选项p即可。如rpm-qp --scripts httpd >httpd.sh