Sometimes after incorrect updates duplicated packages appear in the system
For example:
<...>
alt-python27-2.7.13-3.el6.x86_64 is a duplicate with alt-python27-2.7.11-7.el6.x86_64
alt-python27-2.7.13-4.el6.x86_64 is a duplicate with alt-python27-2.7.13-3.el6.x86_64
alt-python27-libs-2.7.13-3.el6.x86_64 is a duplicate with alt-python27-libs-2.7.11-7.el6.x86_64
alt-python27-libs-2.7.13-4.el6.x86_64 is a duplicate with alt-python27-libs-2.7.13-3.el6.x86_64
<...>
First of all, we need the full list of dupes:
package-cleanup --dupes | tail -n +3
We'll also need to save this list into a file:
package-cleanup --dupes | tail -n +3 > duplist.txt
The main idea is to do the following (for each package):
- Remove the lowest version from the rpmdb: rpm -e --justdb --nodeps $PKGNAME
- Reinstall the highest version:yum -y reinstall $PKGNAME
It is a good idea to check what is going to be done before real operations:
(This will only display a list of all the commands without execution)
cat duplist.txt | sort --version-sort | awk 'NR % 2 {print "rpm -e --justdb --nodeps " $1 } !(NR % 2) {match($0, "-[0-9]");print "yum -y reinstall " substr($0,0,RSTART-1)}'
Then we perform the necessary operations:
("pipe sh" has been added at the end in order to execute the sequence):
cat duplist.txt | sort --version-sort | awk 'NR % 2 {print "rpm -e --justdb --nodeps " $1 } !(NR % 2) {match($0, "-[0-9]");print "yum -y reinstall " substr($0,0,RSTART-1)}' | sh
Alternatively, all this could be performed without an intermediary file:
package-cleanup --dupes | tail -n +3 | sort --version-sort | awk 'NR % 2 {print "rpm -e --justdb --nodeps " $1 } !(NR % 2) {match($0, "-[0-9]");print "yum -y reinstall " substr($0,0,RSTART-1)}' | sh
Comments
0 comments
Please sign in to leave a comment.