#!/usr/bin/perl -w
# use:
# equery list > plist
# cat plist | cut -d '/' -f2 | cut -d '-' -f1 | sort | uniq > plist2
# for i in $(cat plist2) ; do emerge -s $i >> plist3 ; done
# cat plist3 | perl $THIS_SCRIPT
use strict;
use warnings;
my @packages ;
my $temp_pkg ;
my $temp_curr ;
my $temp_disp ;
while(<>) {
if ($_ =~ /\*\s+([\w|\-|\d|\/]+)/) {
#print "found package! " ;
$temp_pkg = $1 ;
next;
}
elsif ($temp_pkg && $_ =~ /Latest version available: (.*)/) {
#print "found avail! " ;
$temp_disp = $1 ;
next;
}
elsif ($temp_pkg && $temp_disp && $_ =~ /Latest version installed: (.*)/) {
#print "found current!\n" ;
$temp_curr = $1 ;
next;
}
else {
if ($temp_pkg and $temp_curr and $temp_disp and not grep(/^$temp_pkg$/, @packages) ) {
if ($temp_curr ne $temp_disp && $temp_curr ne '[ Not Installed ]') {
print "Adding [$temp_pkg] to packages to update ($temp_disp > $temp_curr)\n" ;
push @packages, $temp_pkg ;
}
}
#print "deleting...\n ";
$temp_pkg = undef;
$temp_curr = undef;
$temp_disp = undef;
}
}
print "\n\nemerge -vupD " . join(' ', @packages) . "\n\n" ;