Home > Enterprise >  yum how to identify the installed rpm with lower version
yum how to identify the installed rpm with lower version

Time:10-31

The goal is to compare the list of rpms under folder /tmp/list_of_rpms to installed rpm, and if the package is installed with a lower version then print this rpm.

The approach to check if rpm is installed or not can be easily verified with

rpm -qi  gssproxy-0.7.0-30.el7_9.x86_64.rpm
package gssproxy-0.7.0-30.el7_9.x86_64.rpm is not installed

but actually this rpm installed with lower version as

rpm -qa | grep gssproxy
gssproxy-0.7.0-29.el7.x86_64

Can we identify also if rpm is installed with lower version?

The approach to take the installed rpm by rpm -qa | grep gssproxy and then comparing it to the rpm file /tmp/gssproxy-0.7.0-30.el7_9.x86_64.rpm by regex is very complicated.

CodePudding user response:

There's a dedicated tool called rpmdev-vercmp for comparing RPM versions. It's in the yum-utils package. apparently in a package named rpmdevtools.

Untested, but hopefully sufficient to get you started:

for rpm in /tmp/list_of_rpms/*.rpm; do
    base=${rpm#/tmp/list_of_rpms/}
    pkg=${base%-*-*}
    if installed=$(rpm -q "$base"); then
        rpmdev-vercmp "$pkg" "$installed" >/dev/null 2>&1
        case $? in 12) echo "$installed is less than $pkg";; esac
    fi
done

This doesn't do anything for packages which are not installed at all; perhaps you want to add an else clause and add a notification about those, too?

Some background from https://www.golinuxhub.com/2018/06/how-to-compare-rpm-version-bash-script-python-linux-algorithm/ but the actual code in that has problems. Also, https://unix.stackexchange.com/questions/163702/bash-script-to-verify-that-an-rpm-is-at-least-at-a-given-version

  • Related