本文主要介绍使用 rpmrebuild 工具来反向提取 spec 文件

安装 rpmrebuild 工具

yum install -y epel-release centos-release
yum install -y rpm-build rpmrebuild rpm cpio

从 RPM 包中提取 SPEC 文件

这里以 minio 为例

rpmrebuild --package --notest-install --spec-only=minio.spec minio-20231101183725.0.0.x86_64.rpm

其中 --spec-only 是最终 spec 文件的名称

附录:帮助手册

 rpmrebuild --help
rpmrebuild is a tool to rebuild an rpm file from the rpm database
Usage: rpmrebuild [options] package
options:
-5 --md5-compat-digest use rpm 4.4 compatible digest (md5)
-a, --additional=<flags> additional flags to be pass to the rpmbuild
-b, --batch batch mode (ask no questions)
-c, --comment-missing=<y|n> comment missing files in the specfile. default : no.
-d, --directory=<dir> specify the working directory
-D, --define=<define> defines to be passed to the rpmbuild
-e, --edit-spec alias for --edit-whole
-f, --filter=<command> alias for --change-spec-whole
-i, --includes=<file> read options from the file <file>
-I, --install install the created rpm
-k, --keep-perm alias for --pug-from-fs
--pug-from-fs keep installed files permission, uid and gid
--pug-from-db (default) use files permission, uid and gid from rpm db
--cap-from-fs use files posix capabilities from installed files
--cap-from-db (default) use files posix capabilities from rpm database
-l, --list-plugin list installed plugins
-m, --modify=<command> alias for --change-files
-n, --notest-install do not perform a test install
-p, --package use package file, not installed rpm
-P, --autoprovide force rpm to auto generate "Provide:"
-r, --release=N force release to N
-R, --autorequire force rpm to auto generate "Require:"
-s, --spec-only=<specfile> generate specfile only. (If <specfile> "-" stdout will be used)
-v, --verbose verbose
--debug debug mode (do not remove temporary working files)
-V, --version print rpmrebuild version
-w, --warning print warning if detect filenames with globbing characters (default : no).
-y, --verify=<y|n> verify package (rpm -V) before processing (default : yes).
-h, --help print this help
--help-plugins print help about plugins options

Copyright (C) 2002-2007 by Eric Gerbier (<gerbier@users.sourceforge.net>)
this program is distributed under GNU General Public License