ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to write a spec file that will install a program, however, if the program is already installed the rpm should exit. In my spec file i check the return code of an 'rpm -q xxxx > /dev/null 2>&1' query. if the package is not found then i can move forward with the installation.
Code:
rpm -q xxxx > /dev/null 2>&1
rc=$?
if["$rc" = 0]
then
.........
fi
However, the return value is always 1. When i remove the pipe to the bit bucket, i see the error "cannot get shared lock on /var/lib/rpm'. It seems to me that this might mean i cant use rpm commands from inside a rpm spec file, since the calling rpm has a lock on the rpm db. Is this true?
if so, does anyone have any good suggestions for checking to see if a package is already installed without using 'rpm -q'?
i don't really think it's place to make that judgement, are the standard rpm syntaxes not enough to handle these situations? e.g. -i will (AFAIR) refuse to install when it's already there in any version, and -U will refuse to install if the package is not newer than the existing one. what's your motiviation to do what appears to be reinventing the wheel?
Thanks for the reply and sorry for not being more clear. I tried to make a simplified example of my situation. I really have two parallel programs siblings of sorts but different programs. If program 1 is installed, i do not want to be able to install program 2.
I know that this same *.rpm file works on RHEL 4 with RPM 4.3.3, so I was thinking that RPM 4.1.1 puts a lock on the database which excludes reads as well, but RPM 4.3.3 handles the database differently. However, a cursory google search wasnt too enlightening.
Thanks for the suggestion. I had the Conflicts identifier in the wrong place. After I moved it before the package marker it worked fine. rpm -q --conflicts XX returnedd XX, YY.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.