943,982 Members | Top Members by Rank

Ad:
Feb 9th, 2007
0

comparing versions

Expand Post »
i need to find if the system has the latest version of a particular package and install if it dosent. how do i compare the versions?
assume that i use rpm to find the installed version and a separate file has info of the required(latest) version.
how do i do it ?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ripper is offline Offline
2 posts
since Feb 2007
Feb 9th, 2007
0

Re: comparing versions

What program are you tryin to update the revision for?
Reputation Points: 11
Solved Threads: 0
Light Poster
Joshua Gourgues is offline Offline
29 posts
since Feb 2007
Feb 14th, 2007
0

Re: comparing versions

What program are you tryin to update the revision for?
php,mysql and apache
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ripper is offline Offline
2 posts
since Feb 2007
Feb 14th, 2007
0

Re: comparing versions

It depends, on Linux play around for a while with rpm -qa, on Solaris play around with pkginfo, on AIX, HP, and SCO (as well as the FreeBSD/NetBSD deriviates) I can't really help you. I don't remember there software management commands.

But as you can see, it depends on your operating system. It also depends on whether the packaging system was used at all, or if someone downloaded the source and compiled it, or maybe just a tar file version of a binary program.
Last edited by masijade; Feb 14th, 2007 at 2:42 am. Reason: added bsd types
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Apr 5th, 2007
0

Re: comparing versions

Hi,
This may be your lucky day. I searched all over the internet and couldn't find an RPM compare program - you'd think there would be hundreds of them....So I wrote my own. Not elegant, but very functional. The key to getting useful information from rpm is using query formats --qf

The guts of this script is

# rpm -q -a --qf '%{NAME}&-%{VERSION}&-%{RELEASE}&(%{ARCH})

This script is probably real close to what you're wanting to do. It compares the installed RPMS against a -r requirements file. This script can show you how to parse off the version number from a RPM
so you can compare it against your requirements file.

# <this script> -c <fn> will generate a list of RPMS installed
# <this script> -r <fn> will compare against a requirements file

== snip =========================================
#!/bin/bash
# Andrew Campagnola
# This script will compare installed RPMs against a list of required RPMS
# It will also compare and list the versions of the RPMs
# ===============================================
# Options
# -a Report ALL RPMs - found, missing or mismatched versions
# -v Report missing and mismatched versions
# -m Only report missing RPMS
# -c Create a local RPM list file

usage="USAGE: rpmcompare [camvVh?:ri] \n-a(ALL) -m(MISSING) -v(MISMATCHED VERSION) -r <required rpms file> -i <installed RPMs file> -c <create local list> -V Verbose"

let verbose=0
let pause_mode=1

while getopts "Vh?i:r:c:avmp" options
do
case $options in
a ) report="all"
;;
c ) report="make_local_list"
catalog_file=$OPTARG
;;
v ) report="version"
;;
m ) report="missing"
;;
V ) let verbose=1
;;
p ) let pause_mode=1
;;
r ) required_file=$OPTARG
;;
i ) installed_file=$OPTARG
;;
h ) echo -e $usage
exit 1
;;
? ) echo -e $usage
exit 1
;;
* ) echo -e $usage
exit 1
;;
esac
done

if [ ! -n "$1" ]
then
echo -e $usage
exit 1
fi

echo -e "------------------------------\nReport Type = $report \nVerbose=$verbose \nReq's File: $required_file \nInstalled File: $installed_file\nPause Mode: $pause_mode\n------------------------------"
#
# -c Make a Local RPM Listing File (./local_installed_rpms)
#

if [ "$report" = "make_local_list" ] ; then

## rpm -q --qf '%{NAME}-%{VERSION}-%{RELEASE}(%{ARCH})(%{GROUP})\n' $var
rpm -q -a --qf '%{NAME}&-%{VERSION}&-%{RELEASE}&(%{ARCH})\n' > temp1
cat temp1 | tr ' ' '\n'| sort > temp2
cp temp2 $catalog_file
rm -f temp1 temp2
echo -e "Completed writing RPM catalog $catalog_file"
exit 0

fi
#
# Get required rpms list file (Remote Computer)
#
until test -f "$required_file"
do
echo "Can't find required file ("$required_file") - I need a file with the list of required RPMS: "
read required_file
done
#
# Got name of req file, now load it
#
echo "Reading Remote RPMS List from: < $required_file >"
remote_rpms=`cat $required_file | sort`
#
# Check for -i (Local Computer) List Of Installed RPMS
# If not supplied, a list will be generated using `rpm -qa`
#
if [ -s "$installed_file" ]
then
installed_rpms=`cat $installed_file`
echo -e "Reading Local Installed RPMS List from: < $installed_file >"
else
echo "No local catalog file specified: Querying (Local) installed RPMS"
## ? installed_rpms=`rpm -q --qf "\%{NAME}-\%{VERSION}-\%{RELEASE}(\%{ARCH})\n"`

rpm -q -a --qf '%{NAME}&-%{VERSION}&-%{RELEASE}&(%{ARCH})\n' > temp1
cat temp1 | tr ' ' '\n'| sort > temp2
installed_rpms=`cat temp2`
rm -f temp1 temp2
fi

echo "================================================================"

for check in $remote_rpms
do
let rpm_base_match=0

# c_base=${check%%-[0-9]*} # don't trim nums they can be part of name
c_base=${check%%&*}
# Trim Off Archecture from right of version
# c_arch="(${check##*(}"
c_arch=${check##*&}
c_version=${check%%&*}
#
# Trim base name from left of version
c_version=${c_version#*&}

if [ "$verbose" = "1" ] ; then echo -e "Checking For Required RPM: \nName: $c_base \nArch: $c_arch\nVer: $c_version" ; fi
#
# Check installed local RPMS for a match to $c_base
#
for installed in $installed_rpms
do

let rpm_base_match=0
i_base=${installed%%&*}
#
# Trim Off Archecture from right of version to (
#
i_arch=${installed##*&}
i_version=${installed%%&*}
#
# Trim base name from left of version
i_version=${i_version#*&}

# echo -e "Raw check var:" $check
# echo -e "Raw installed var:" $installed

#
# Test Names -------------------------
#
if [ "$c_base" != "$i_base" ]
then
continue # skip to next installed
fi

# name matched - descend here
#
if [ "$c_arch" = "$i_arch" ]
then
rpm_base_match=1
if [ "$report" = "all" ]
then
echo -e "\nNames MATCH: $c_base $c_arch"
fi
#
# Name Match, Test Versions
#
if [ "$i_version" = "$c_version" ]
then
echo -e "Versions MATCH\n(Req)$required_file: $c_version $c_arch\n(Local)$installed_file: $i_version $i_arch"

else # Versions Mis-Match
echo -e "Versions MIS-MATCH\n(Req)$required_file: $c_version $c_arch\n(Local)$installed_file: $i_version $i_arch"

if [ "$pause_mode" = "1" ]
then
echo "Paused: Press Enter To Continue"
read dummy
fi
fi # if versions don't match
break
fi # if arch match

done # next $installed in installed_rpms

if [ "$rpm_base_match" = "0" ]
then
echo -e "----------------------------"
echo -e "Missing RPM: \nName: $c_base \nArch: $c_arch\nVer: $c_version"
if [ "$pause_mode" = "1" ]
then
echo "Paused: Press Enter To Continue"
read dummy
fi
fi # if versions don't match

if [ "$verbose" = "1" ]
then
echo -e "----------------------------"
fi

done # next $check in check_rpms

unset installed_rpms
unset check_rpms

exit 0
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ajcamp is offline Offline
10 posts
since May 2004
Apr 5th, 2007
0

Re: comparing versions

By the way, I'd be
VERY INTERESTED IN IMPROVEMENTS TO THIS SCRIPT.

Thanks
AJ
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ajcamp is offline Offline
10 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: samba server error
Next Thread in Shell Scripting Forum Timeline: Colorful clock of Time





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC