Package version testing script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Package version testing script
# 1  
Old 08-12-2010
Package version testing script

I was wondering if anyone already had a script to check rpm packages versions x.x.x or greater.

so I could do a:

Code:
# CheckRpmVersion Somepackage-1.2.3

And would output: whether the package is installed or not and if it was equal to or greater than the version 1.2.3.

I know I can pull out the Major.Minor.Sub and compare each one. But there has to be something simpler.

---------- Post updated at 09:52 AM ---------- Previous update was at 08:33 AM ----------

Here is what I came up with.

Code:
#!/bin/sh
#
#

REQ=$1

PKG=$(echo $REQ | awk -F- ' { print $1 } ')
echo $PKG
REQVer=$(echo $REQ | awk -F- ' { print $2 } ')
REQMajor=$(echo $REQVer | awk -F. ' { print $1 } ')
REQMinor=$(echo $REQVer | awk -F. ' { print $2 } ')
REQSub=$(echo $REQVer | awk -F. ' { print $3 } ')
echo "Requires:$REQMajor.$REQMinor.$REQSub"


PKGVer=$(/bin/rpm -q $PKG)
PKGMajor=$(echo $PKGVer | awk -F. ' { print $1 }' | awk -F- ' { print $2 } ')
PKGMinor=$(echo $PKGVer | awk -F. ' { print $2 }')
PKGSub=$(echo $PKGVer | awk -F. ' { print $3 }' | awk -F- ' { print $1 } ')
echo "Actual:$PKGMajor.$PKGMinor.$PKGSub"

if [[ $PKGMajor > $REQMajor ]];then
    echo "Good"
elif [[ $PKGMajor = $REQMajor && $PKGMinor > $REQMinor ]];then
    echo "Good"
elif [[ $PKGMajor = $REQMajor && $PKGMinor = $EREQMinor && $PKGSub > $REQSub ]];then
    echo "Good"
else
    echo "Bad"
fi

Code:
# ./RPMCheck.sh binutils-2.16.92.0.2
binutils
Requires:2.16.92
Actual:2.17.50
Good



---------- Post updated at 10:03 AM ---------- Previous update was at 09:52 AM ----------

One problem I found.

The example works but if I use compat-libstdc++-33-3.2.3 it tries to split at first -

---------- Post updated at 11:49 AM ---------- Previous update was at 10:03 AM ----------

Replaced:
Code:
REQVer=$(echo $REQ | awk -F- ' { print $2 } ')

With:
Code:
REQVer=$(echo $REQ | sed -e 's/\([A-Za-z0-9.-+]*\)-\([0-9]*\.\)/\2/')

So far it works good.

---------- Post updated at 12:34 PM ---------- Previous update was at 11:49 AM ----------

Found some other errors.

Here is the finished code. Please feel free to tear it apart and suggest better ways, PLEASE.

Code:
#!/bin/sh
#
#
REQ=$1
PKG=$(echo $REQ |sed -e 's/\([A-Za-z0-9.-+].*\)-[0-9]\..*/\1/')
REQVer=$(echo $REQ | sed -e 's/\([A-Za-z0-9.-+].*\)-\([0-9]*\.\)/\2/')
REQMajor=$(echo $REQVer | awk -F. ' { print $1 } ')
REQMinor=$(echo $REQVer | awk -F. ' { print $2 } ')
REQSub=$(echo $REQVer | awk -F. ' { print $3 } ')

PKGVer=$(/bin/rpm -q "$PKG" | sed 's/\.el[0-9]//')
PKGVer=$(echo $PKGVer | sed -e 's/\([A-Za-z0-9.-+].*\)-\([0-9]*\.\)/\2/')
PKGMajor=$(echo $PKGVer | awk -F. ' { print $1 }')
PKGMinor=$(echo $PKGVer | awk -F. ' { print $2 }')
PKGSub=$(echo $PKGVer | awk -F. ' { print $3 }' | awk -F- ' { print $1 } ')

if [[ $PKGMajor > $REQMajor ]];then
    echo "Good"
elif [[ $PKGMajor = $REQMajor && $PKGMinor > $REQMinor ]];then
    echo "Good"
elif [[ $PKGMajor = $REQMajor && $PKGMinor = $REQMinor && $PKGSub > $REQSub ]];then
    echo "Good"
elif [[ $PKGMajor = $REQMajor && $PKGMinor = $REQMinor && $PKGSub = $REQSub ]];then
    echo "Good"
else
    echo "Bad"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to install older package version on Ubuntu 18.04?

Hello, I'm running Ubuntu 18.04 and I would like to install libboost-python version 1.46. Currently I have installed version 1.65: wakatana@local-machine:~$ dpkg -l | grep libboost-python ii libboost-python-dev 1.65.1.0ubuntu1 amd64 ... (1 Reply)
Discussion started by: wakatana
1 Replies

2. Solaris

Global zone has an older version of package: pkg://Solaris/system/library

I try to install php-56 in a zone, but I have the following problem: pkg install php-56 Creating Plan (Running solver): \ pkg install: No solution was found to satisfy constraints maintained incorporations: None Creation Plan: dependency error (s) in proposed packages: Not... (0 Replies)
Discussion started by: ymk369
0 Replies

3. Solaris

Check that supersede of package version is installed

I need a programmatic way to check, that supersede of required package is installed. At Linux I do it using rpmvercm utility to compare installed package version to my minimal requirement. So - I need analog of Linux "rpmvercm" utility for Solaris (10/11) Let us say - I know that minimal version... (10 Replies)
Discussion started by: zuismanm
10 Replies

4. Shell Programming and Scripting

Compare two files containing package names and version number

I have 2 files each containing a list of same fedora packages but with different version number. I want to compare the 2 files and remove the lines containing a newer or older version number (1 Reply)
Discussion started by: asya18
1 Replies

5. Shell Programming and Scripting

To delete the common parts (version and suffix) to get the package name

I have lots of package version +suffix full name, but I just want to get the package name, which means delete the common parts eg: dtc-1.3.0+gitAUTOINC+033089f29099bdfd5c2d6986cdb9fd07b16cfde0-r4.1.x86_64.rpm ... (5 Replies)
Discussion started by: yanglei_fage
5 Replies

6. UNIX for Advanced & Expert Users

How to find dependancies of .dstream package (Solaris) & .rpm package( linux)

Friends, Please let meknow, How we can find the dependancies of .dstream package & .rpm package before installation ? For AIX, We can use the inutoc . command to create the .toc file for the bff package, What about Solaris & Linux ? (0 Replies)
Discussion started by: yb4779
0 Replies

7. Shell Programming and Scripting

Remove version numbers from package lists

I just upgraded my laptop from Fedora 13 to 14, and normally, before I do the upgrade (Fresh install) I run an rpm command to make a list of all the packages I have installed, but without the version and architectures specified, so that I can just feed that list to yum after the upgrade to... (2 Replies)
Discussion started by: Tsuroerusu
2 Replies

8. Debian

Package updated to same version

Hi, I recently did slight modifications to the basename utility from the coreutils package. I downloaded the source by typing "apt-get source coreutils", added a new option to the program, updated the respective manpage, build and installed it using "dpkg-buildpackage -uc -b && dpkg -i... (0 Replies)
Discussion started by: Gunther
0 Replies

9. UNIX for Dummies Questions & Answers

package version

hi, I have this problem. I run a script to check which version of a given package is installed and I need something returning a meaningfull answer also if the installation was done with the sources. Let's say that, a priori, I do not know how the package was installed. So far I have... (0 Replies)
Discussion started by: gcastell
0 Replies
Login or Register to Ask a Question