This is possible, but not with the rpm command. I wrote a perl script that does this; it creates a specification file based on rpm -q outputs and performs a “build” that simply copies the installed files from the system.
You can find it here: https://github.com/cormander/rogue-beret-tools/blob/master/scripts/rpm-repack
Usage example, mailx rpm:
Request:
$ rpm -ql mailx /bin/mail /etc/mail.rc /usr/bin/Mail /usr/lib/mail.help /usr/lib/mail.tildehelp /usr/share/man/man1/Mail.1.gz /usr/share/man/man1/mail.1.gz
Cancel it:
$ ./rpm-repack -p mailx Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.9773 + umask 022 + cd /usr/src/redhat/BUILD + /usr/lib/rpm/brp-compress + /usr/lib/rpm/brp-strip + /usr/lib/rpm/brp-strip-static-archive + /usr/lib/rpm/brp-strip-comment-note Processing files: mailx-8.1.1-44.2.2 Provides: mailx Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 Requires: libc.so.6 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.3) libc.so.6(GLIBC_2.3.4) libc.so.6(GLIBC_2.4) rtld(GNU_HASH) Checking for unpackaged file(s): /usr/lib/rpm/check-files /tmp/tlkN4yrYEi Wrote: ~/rpmbuild/RPMS/i386/mailx-8.1.1-44.2.2.i386.rpm
Request a new package:
$ rpm -qpl ~/rpmbuild/RPMS/i386/mailx-8.1.1-44.2.2.i386.rpm /bin/mail /etc/mail.rc /usr/bin/Mail /usr/lib/mail.help /usr/lib/mail.tildehelp /usr/share/man/man1/Mail.1.gz /usr/share/man/man1/mail.1.gz
The code is not elegant at all, but functional. It copies a lot of rpm information (everything from rpm -qi and most scripts), but this is by no means comprehensive. In addition, it cannot copy the GPG signature and will not have the same checksums as the original RPM file.
NOTE. This is not the “right” way to create and distribute RPM packages, and it is mainly written for troubleshooting and educational purposes.
source share