LinuxQuestions.org
Visit Jeremy's Blog.
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 06-28-2007, 01:57 PM   #1
Okashiiken
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Rep: Reputation: 0
cannot use rpm -q in rpm spec file?


Hello,

SUSE 9
Bash 2.05b
RPM 4.1.1

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'?

Thanks.
 
Old 06-28-2007, 03:00 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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?
 
Old 06-28-2007, 04:12 PM   #3
Okashiiken
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Hi,

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,
Nick
 
Old 06-28-2007, 04:15 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
don't you want to define a conflict tags as part of the dependencies then? http://www.rpm.org/max-rpm/s1-rpm-de...endencies.html
 
Old 06-28-2007, 05:20 PM   #5
Okashiiken
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Sorry for the slow reply, I added it as a conflict and it doesnt seem to be working correctly.

Code:
%package        AA
Conflicts: 	XX , YY
Summary:        XX
Group:          system/tools
%description    AA
rpm -q XX returns XX-1.1.0-1

I had thought that for sure this would solve my problem. Am I adding the conflict incorrectly?

Thanks again
 
Old 06-29-2007, 02:13 AM   #6
Okashiiken
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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.

Thanks again.
 
  


Reply



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
Situation/condition in spec file for RPM Ameii83 Linux - Software 2 04-12-2007 12:06 AM
rpm spec file alrawab Linux - General 2 03-28-2007 06:39 AM
RPM Spec file adddy Linux - Software 8 11-07-2006 05:02 AM
questions on writing own rpm .spec file adrianmak Linux - Software 0 08-18-2005 06:03 AM
%file attribute for RPM SPEC files Brian of Gep Linux - Software 3 06-18-2004 04:51 AM

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

All times are GMT -5. The time now is 07:28 PM.

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