LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-10-2005, 01:25 PM   #1
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Rep: Reputation: 15
Compare installed RPM versions using Bash script


Hello All,

I am a newbie to the UNIX/Linux flavors and I am attempting to create an installer using RPM. Within my script I want to make sure that the systems has an installed vesion of RPM that is equal to or greater than a specified version. The below snippet gets the current version of RPM, but I am not sure how to parse the values to check for correctness.


#===========BEGIN Code snippet ==========

#============================================
f_Check_RPM_Version() # Checks the installed version of RPM
#============================================
{
ROOT_BIN_RPM="/bin/rpm"
USR_BIN_RPM="/usr/bin/rpm"
USR_LOCAL_BIN_RPM="/usr/local/bin/rpm"

#Checks to see if the RPM application
#is installed on the system
if [[ -e $ROOT_BIN_RPM || -e $USR_BIN_RPM|| -e $USR_LOCAL_BIN_RPM ]]; then
RPM_VERSION=`rpm -q rpm`

#****NEED to compare versions here *****
STR_BASE_ACCEPTABLE_VER="rpm-4.2-0.69"
#****NEED to compare versions here *****

printf "$STR_RPM_CORRECT_VERSION $RPM_VERSION"
else
printf "$STR_RPM_INCORRECT_VERSION"

exit 1
fi

} # end f_Check_RPM_Version()


#===========END Code snippet ==========



Any help you can proved would be greatly appreciated.

Best Regards,
-Jim
 
Old 01-10-2005, 02:24 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Just clarification: You want to check if $RPM_VERSION is greater or equal to rpm-4.2-0.69?? Is that right?
 
Old 01-10-2005, 02:30 PM   #3
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Original Poster
Rep: Reputation: 15
RE: Compare installed RPM versions using Bash script

Correct. I am looking to check if $RPM_VERSION is greater or equal to rpm_4.2-0.69.


Thanks
 
Old 01-10-2005, 02:49 PM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Note: this is untested...

Code:
#****NEED to compare versions here *****

STR_BASE_ACCEPTABLE_VER="rpm-4.2-0.69"

if  [[ "$RPM_VERSION" < "$STR_BASE_ACCEPTABLE_VER" ]]; then
    echo "$RPM_VERSION is too low..."
else
    echo "$RPM_VERSION is fine"
fi

#****NEED to compare versions here *****
Have a look at http://www.tldp.org/LDP/abs/html/comparison-ops.html for comparison operators in bash...

Last edited by bulliver; 01-10-2005 at 02:51 PM.
 
Old 01-10-2005, 03:41 PM   #5
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Original Poster
Rep: Reputation: 15
Talking

THANKS for your help bulliver. Your code snippet is just what I was looking for. In my attempt I was fudging up the '['. I will be sure to check out that link.

Best Regards,
-Jim
 
Old 01-28-2005, 10:31 AM   #6
QICBoy
LQ Newbie
 
Registered: Jan 2005
Posts: 1

Rep: Reputation: 0
This is a string comparison, so it will fail on rpm_4.12-0.69. Isn't there a more reliable method, like using an rpm command?
 
Old 01-28-2005, 10:40 AM   #7
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Original Poster
Rep: Reputation: 15
Using your example....any built RPM has the following format of:

"[Product Name] - [Distribution Type] - [Major Version] . [Minor Version]. [Maintenance-Revision Version] - [Build Version].[Architecture]"

If this format is not followed then all bets are off. In my case what I ended up doing was stripping the [Major Version] . [Minor Version]. [Maintenance-Revision Version] - [Build Version] out of the string and then do a numerical comparison. Messy but I have not found any quick an easy way around this issue. If you come across anything please feel free to post it.

-Jim
 
  


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
Bash script to compare dir contents Boffy Programming 2 08-02-2005 06:08 AM
Does anyone know of a bash script that will determine if RPM exists on a system? jimwelc Linux - Software 3 12-28-2004 03:01 PM
How do you compare variable in bash programming? chynna_v Programming 6 09-08-2004 02:17 AM
Multiple RPM versions installed Tomasfuego Linux - Software 0 05-15-2003 02:28 PM
Help with a Directory Compare Script bullfrog Linux - General 1 02-04-2003 08:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:10 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