How to "repackage" a RPM file for example cpio2rpm without installing the RPM?

Dr Bob picture Dr Bob · May 14, 2012 · Viewed 16.8k times · Source
  1. I'm able to extract files from a RPM file, but how do I "rebuild" it, for example cpio2rpm?
  2. I have extracted RPM file using following command. rpm2cpio theFileName.rpm | cpio –idmv
  3. I have to modify the few web application files like *.php, *.html or .js. These files don’t require any source recompilation. So I would like to replaces or change these files with modification without rebuilding rpm. Since, I need to do this for multiple platforms like Redhat Linux and SUSE, and multiple architecture like 32 and 64 bit OS.
  4. I am expecting to do these changes on only on system and without rebuild rpm and there would not be have target system architecture dependency (like i386, 64).
  5. I am not looking like command rpmbuild –rebuild the.src.rpm since, I don’t have source. I need to be rebuild binary .RPM file(not source .rpm)
  6. I want to do this without source and platform or architecture independent and without using spec file if possible.

    Any buddy, could you please suggest any solution or any free tools.

    Thank you to all whoever spends time to read and reply to my thread.

Answer

simon3270 picture simon3270 · May 22, 2014

You can use rpmrebuild to modify an actual rpm file (it doesn't need to be installed).

Most of the examples for this use complicated inline edit commands to modify known files in particular ways, but you can use a normal editor. I used this to fix a shell script in an rpm file that I didn't have the source for. Call the command as

rpmrebuild -ep theFileName.rpm

This puts you in an editor with the spec file for the RPM. The name of the file will be something like ~/.tmp/rpmrebuild.12839/work/spec.2. If you look in, in this example, ~/.tmp/rpmrebuild.12839/work, you will find all of the files used to make the RPM (in my case, the file was in root/usr/sbin within that directory). So, go to another window, cd to that directory, and edit any files you need to change.

When you have finished editing files, go back to the edit window with the spec file, make any changes you need to that file (I didn't have any, since I wasn't adding or deleting files), save the file, and say "y" to the "Do you want to continue" question. It will then build a new RPM file, and tell you where it has put it (in my case, in ~/rpmbuild/RPMS/x86_64/)