Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, I want to extract one .rpm file and want to add one .txt file and then I want to rebuld it . will it work or not . I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2011
    Posts
    4

    how to exract rpm files and rebuild it again?


    Hello,
    I want to extract one .rpm file and want to add one .txt file and then I want to rebuld it .

    will it work or not .
    I got some thing like

    rpm2cpio command but is that the only way to extract .Kindly tell me is there any other efficient way to do this and also tell me how to rebuld this again into .rpm file.

    Thanks

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,392
    Get the spec file or the source rpm of that package.
    In any case: edit the spec file and rebuild the rpm with rpmbuild.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Mar 2011
    Posts
    4
    Thanks ..
    I got some files after the rpm2cpio commad and then i have changed some document and then made a tar ball of all that file now I want to make that tar to a rpm.

    suppose I have xyz.rpm then

    1.rpm2cpio xyz.rpm | cpio -mvid (this will give some files)

    then I changed some files and do as follows
    2.tar -cfv xxx.tar <foldername>/ (foldername= where all files are there from the xyz.rpm)

    then I have tried with rpmbuild option but it is not working
    3.rpmbuild -tb xxx.tar

    I can't able to do this ,can any one tell me how to to do this.

    Thanks

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,392
    No, unpacking the rpm is the wrong way.

    You either need the spec file and all sources
    or the source rpm.

    Then you edit the spec file to include your textfile
    Then you build a new rpm with the rpmbuild command and your specfile.
    You must always face the curtain with a bow.

  5. #5
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Like irithori says, you are going about it wrong. you need to understand how an RPM file works. It is true that an RPM is just basically a cpio archive of files, but it comes with pre and post install scripts and various macros that affect how it gets installed.

    To wit, you need to build the RPM using within these constraints. Here's what you need to do, in a nutshell.

    1. create an RPM build environment for your regular user
    Code:
    mkdir ~/rpms
    cd ~/rpms
    mkdir BUILD RPMS SOURCES SPECS SRPMS
    2. create an rpm config file:
    Code:
    cat -> ~/.rpmmacros
    # adds Packager info to RPM
    %packager Your Name
    
    # set this to your distro version (.el5 = RHEL 5, .fc16 = Fedora 16, etc.)
    %dist .el5
    
    # set toplevel for all rpm subdirs (e.g., system _topdir is /usr/src/redhat)
    %_topdir %(echo $HOME/rpms)
    
    # gpg username (uncomment this to be able to sign packages)
    #%_gpg_name "user@localhost"
    
    # buildroot dir
    %buildroot /var/tmp/%{name}-%{version}-%{release}
    <CTRL+D>
    3. install the Source RPM for the package you wish to modify, e.g.:
    Code:
    rpm -ivh cool-package-1.0.src.rpm
    this will install at least two files:
    Code:
    ~/rpms/SPECS/cool-package.spec
    ~/rpms/SOURCES/cool-package-1.0.tar.gz
    4. modify the source package, e.g.:
    Code:
    cd ~/rpms/SOURCES
    tar zxf cool-package-1.0.tar.gz
    If you are changing the source tarball, it is a good idea to up the version:
    Code:
    mv cool-package-1.0 cool-package-1.1
    now carry on with modifying the source, then tar it back up (reflecting the new version, if changed):

    Code:
    tar zcf cool-package-1.1.tar.gz
    5. modify the SPEC file. Use an editor that has syntax highlighting, it is a big help. I use vim. if you changed the version, change it in the spec file (the Version: tag). if you added a file, make sure it gets installed in the %install section, and make sure it is listed in the %files section. also, you should add a line to the %changelog section, noting your changes (reflect the version change there, too, if necessary).

    6. rebuild the rpm:
    Code:
    rpmbuild -bb ~/rpms/SPECS/cool-package.spec
    The RPM will get written to the ~/rpms/RPMS directory (under the relevant arch subdir)

    btw, don't build as rpms as root, it is a great way to fubar your system.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •