From b2b76a729a19ace65f0f0e70b1ceb1666b095ade Mon Sep 17 00:00:00 2001 From: Cedric Girard Date: Wed, 2 Mar 2011 17:47:51 +0100 Subject: [PATCH] quick script for sorting and deleting rpms --- tools/delete_old_rpm.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 tools/delete_old_rpm.sh diff --git a/tools/delete_old_rpm.sh b/tools/delete_old_rpm.sh new file mode 100755 index 0000000..abbd81b --- /dev/null +++ b/tools/delete_old_rpm.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +#### +# +# quick script that takes all rpm in the current directory +# and delete the smaller version when several versions of +# a same package exists +# +# Slow and not error-less +# +#### + +for file in *.rpm ; do + regex='(.*)-[^-]+-[^-]+\.rpm' + if [[ $file =~ $regex ]] ; then + pkg_name=${BASH_REMATCH[1]} + regex_same="$pkg_name-[^-]+-[^-]+\.rpm" + for same_pkg in *.rpm ; do + if [[ $same_pkg =~ $regex_same && `vercmp $file $same_pkg` -gt 0 ]] ; then + rm $same_pkg + echo $same_pkg removed + fi + done + fi +done