LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-09-2011, 08:43 AM   #1
Rickert
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Rep: Reputation: Disabled
How to replace files from existing RPM package?


Suppose I have an already installed RPM package on my system. I want create another package which can overwrite some files of that existing package. How could I do that? Note that this is not an upgrade. Simply some modules (packaged in RPM) share some configure files. Each time a module is updated, the configure files needs to be updated as well. All modules share the same configure files.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-09-2011, 10:28 AM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Do you have rpmbuild installed? That tool should solve your problem.
 
Old 11-09-2011, 10:40 AM   #3
Rickert
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Of course I do have rpmbuild. However, the problem is, I have to build 2 packages, both packages share the same config files. In fact, each has their own physical config files of the same type, and each time a package is update or freshly insall, the config files of that package are gonna be replaced by the current config files of the other package, and both packages will use the latest config files.

You can consider each time a new module is install, the latest config files will replace the current config files which is used by several other rpm packages in the system. RPM seems to not allow it. I don't know how to overwrite or delete the old config files correctly. If I left it there, the new config files can' be installed because of conflicts (other package is using).
 
Old 11-09-2011, 11:22 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Rickert View Post
Of course I do have rpmbuild. However, the problem is, I have to build 2 packages, both packages share the same config files. In fact, each has their own physical config files of the same type, and each time a package is update or freshly insall, the config files of that package are gonna be replaced by the current config files of the other package, and both packages will use the latest config files.

You can consider each time a new module is install, the latest config files will replace the current config files which is used by several other rpm packages in the system. RPM seems to not allow it. I don't know how to overwrite or delete the old config files correctly. If I left it there, the new config files can' be installed because of conflicts (other package is using).
I am not sure - can rpm2cpio help: http://www.rpm.org/max-rpm/s1-rpm-mi...-rpm2cpio.html ?
 
Old 11-09-2011, 06:28 PM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Quote:
.. each time a package is update or freshly insall, the config files
of that package are gonna be replaced by the current config files of
the other package, and both packages will use the latest config files.
From 'man rpm' : --replacefiles http://linux.die.net/man/8/rpm


Suggest : Use this command for the "update" :
# rpm -Uvh --replacefiles <package>.rpm

..
 
Old 11-10-2011, 06:25 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Rickert View Post
Suppose I have an already installed RPM package on my system. I want create another package which can overwrite some files of that existing package. How could I do that?
Quote:
Originally Posted by Rickert View Post
the problem is, I have to build 2 packages, both packages share the same config files.
Apart from what is generated on the fly in say a %post or created by a user, systems using RPM package management consider configuration files integral parts of a package if it's in the %files list. As official RPM packages do not, consider replacing a binary, library or configuration file owned by one package with that of another package as a design stage mistake. If your packages are only meant to destroy your own systems I'd say go right ahead. But if you are going to distribute them the answer must be "no": use another method of integrating changes. (BTW as you carefully avoided posting any specifics and examples there's no way telling what will work.)


Quote:
Originally Posted by Sergei Steshenko View Post
I am not sure - can rpm2cpio help (..) ?
You're correct to voice doubt here as using 'rpm2cpio' is a good way to fsck up a system managed with RPM: it bypasses the standard install method and any such changes won't be visible to the RPMDB (OK, unless you use "--justdb" afterwards). Avoid.


Quote:
Originally Posted by knudfl View Post
Suggest : Use this command for the "update" :
# rpm -Uvh --replacefiles <package>.rpm
Use of --force, be it --replacefiles or otherwise, is yet another way to b0rk a system managed with RPM, in this case by overriding sanity checks. Best avoid.
 
2 members found this post helpful.
Old 11-10-2011, 06:59 AM   #7
Rickert
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
Apart from what is generated on the fly in say a %post or created by a user, systems using RPM package management consider configuration files integral parts of a package if it's in the %files list. As official RPM packages do not, consider replacing a binary, library or configuration file owned by one package with that of another package as a design stage mistake. If your packages are only meant to destroy your own systems I'd say go right ahead. But if you are going to distribute them the answer must be "no": use another method of integrating changes. (BTW as you carefully avoided posting any specifics and examples there's no way telling what will work.)
In my system, it requires to use rpm. So there's not other system allowed here. The situation is like this:

Suppose I have 3 modules, which is three binaries files to put in a /opt/boot/ folder (this is a custom folder). In order for the system to load all the modules, it needs to read in a configure file like this:

Code:
module1=mod1.bin.verA1
module2=mod2.bin.verA1
module3=mod3.bin.verA1
Initially, I will have to create 3 rpm packages to install in the system. Each will packaged with the same configure file, with new content. Each time a module is updated, a new binary needs to be replaced. Consider I have an updated module1 which is mod1.bin.verA2, I need to create an rpm package to upgrade the existing package. The update package will contain the binary file and the new configure file with content like this:

Code:
module1=mod1.bin.verA2
module2=mod2.bin.verA1
module3=mod3.bin.verA1
After a patch, a new configure file with new updated module are replaced. However, the problem with this is, even after the installation of the first module, the second package will cause conflicts and won't be installed properly. Same happens for upgrading (different packages update the shared configure files).

I am thinking of separting the configure files and the modules into two separated packages, and each time an upgrade occurs, there will be two packages released, one for configure file and one for binary files. I will need to propose this idea and wait for acceptance though, because the above method is a requirement..
 
1 members found this post helpful.
Old 11-10-2011, 07:34 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If I understand your post correctly you should use %config(noreplace). Updating a package then forces a %{config}.rpmnew to be created. The admin then can 'diff -Urn %{config} %{config}.rpmnew > %{config}.diff', review changes and use say 'patch' to make them stick. Hindsight, true, but if loading order was a requirement it might have been better had configuration loading been incorporated in the design phase. For example daemons these days often use a /etc/%{name}.d/ directory and allow separate uniquely numbered configuration files to be placed there to preserve loading order. If redesign isn't possible (;-p) another way could be to regenerate the configuration file in %post based on RPMDB output? See querying the RPMDB using say 'rpm -q %{name} --qf="%{NAME} %{RELEASE} %{INSTALLTIME}\n"|sort -k3'. And if 'at' is running this could even be handed off as a job in a %post scriptlet to ensure any ops are done after RPM transactions are completed.
 
2 members found this post helpful.
Old 11-10-2011, 09:35 AM   #9
Rickert
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
If I understand your post correctly you should use %config(noreplace). Updating a package then forces a %{config}.rpmnew to be created. The admin then can 'diff -Urn %{config} %{config}.rpmnew > %{config}.diff', review changes and use say 'patch' to make them stick. Hindsight, true, but if loading order was a requirement it might have been better had configuration loading been incorporated in the design phase. For example daemons these days often use a /etc/%{name}.d/ directory and allow separate uniquely numbered configuration files to be placed there to preserve loading order. If redesign isn't possible (;-p) another way could be to regenerate the configuration file in %post based on RPMDB output? See querying the RPMDB using say 'rpm -q %{name} --qf="%{NAME} %{RELEASE} %{INSTALLTIME}\n"|sort -k3'. And if 'at' is running this could even be handed off as a job in a %post scriptlet to ensure any ops are done after RPM transactions are completed.
This seems promising. I will try it soon. However, I'm not sure if it applies to multiple packages sharing same configuration files, since the method only considers the case for single package only.

Last edited by Rickert; 11-10-2011 at 10:39 AM.
 
Old 11-10-2011, 12:10 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Given each packages .spec file contains lines like "%define name module1" and "%define version verA2", as long as you update packages the RPMDB can be queried for all packages with "^.*%{name}.*" in it, etc, etc. When ready post your proposed scriptlet (preferably between BB code tags) and we'll look at it.
 
Old 11-10-2011, 03:03 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by unSpawn View Post
...
You're correct to voice doubt here as using 'rpm2cpio' is a good way to fsck up a system managed with RPM: it bypasses the standard install method and any such changes won't be visible to the RPMDB (OK, unless you use "--justdb" afterwards). Avoid.
...
???????????????

I meant to convert RPM o CPIO archive, and the latter can trivially be converted into a regular directory tree, and in the latter a file can be trivially updated.
 
Old 11-10-2011, 03:41 PM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Sergei Steshenko View Post
I meant to convert RPM o CPIO archive, and the latter can trivially be converted into a regular directory tree, and in the latter a file can be trivially updated.
Heh, that actually would be trivial and irrelevant to the OP's actual question. As far as I understand what he wants, that is.
 
  


Reply

Tags
rpmnew



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RPM spec file to replace existing config files. wills Linux - Server 2 09-29-2011 04:08 AM
How to remove existing rpm and install latest downloaded package samiksha Linux - Software 9 12-08-2010 04:49 AM
Why is rpm skipping some package files? khym_chanur Mandriva 3 06-29-2007 08:45 PM
How to add a file to an existing rpm package SharpyWarpy Linux - Software 3 06-20-2004 05:59 AM
How to extract files from an rpm package mayankjohri Linux - Networking 3 06-12-2002 12:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration