Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have Gentoo VM that I use to test different puppet recipes and I frequently need to remove packages to bring it to clean initial state. While I could do this by hand when there are only few packages installed (and remove dependencies with emerge -av --depclean) but there are some recipes involving installation of few dozen of perl modules which I need to clean after testing. I think about packing them into single virtual ebuild but I already have test system dirty with many installed packages and I want to avoid reviewing them one by one. So question is how do I find list of packages installed after some specific date?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can use app-portage/genlop for this.

genlop -l --date some_date

will list all packages merged on or after that date. (You can also specify an end date.)

To get a list of packages suitable for emerge --unmerge, try something like:

genlop -ln --date 2011/10/02 | perl -ne '/>>> (.*)/ and print " =$1";'

Do double-check that list before actually unmerging, removing system packages by accident is not fun.

Another way of getting a list of things merged after a given date is looking at the BUILD_TIME saved in the portage database.

#!/bin/bash
stime=$(date -d "$1" +%s)

for dir in /var/db/pkg/*/* ; do
    if [ -f $dir/BUILD_TIME ] ; then
        btime=$(<$dir/BUILD_TIME)
        if [ $btime -ge $stime ] ; then
            package=$(basename $dir)
            category=$(basename $(dirname $dir))
            echo $category/$package
        fi
    fi
done

Call this with a date (i.e. ./script "2001/09/30 21:32") and you'll get a list of packages merged since that date.

Portage doesn't store whether a merge was a new install or an update in its database. You could reconstruct that information from the emerge.log file assuming you have all your system's history there.

A simpler way of handling all this would be to use package sets. Create a set each time you try out a new recipe, and use that to do your cleanups. (Depclean is still necessary.)

# echo dev-perl/IO-AIO > /etc/portage/sets/my_set
# emerge -a @my_set

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-perl/IO-AIO-2.33 

Would you like to merge these packages? [Yes/No] y
>>> Recording @my_set in "world" favorites file...

...
>>> Installing (1 of 1) dev-perl/IO-AIO-2.33
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.
# emerge -a --unmerge @my_set
 * This action can remove important packages! In order to be safer, use
 * `emerge -pv --depclean <atom>` to check for reverse dependencies before
 * removing packages.

>>> These are the packages that would be unmerged:

 dev-perl/IO-AIO
    selected: 2.33 
   protected: none 
     omitted: none 

All selected packages: dev-perl/IO-AIO-2.33

>>> 'Selected' packages are slated for removal.
>>> 'Protected' and 'omitted' packages will not be removed.

Would you like to unmerge these packages? [Yes/No] 
share|improve this answer
    
Thanks for suggestion, I've tried it. Unfortunately genlop relies on parsing portage logfiles and doesn't reflect current system state so its output includes already removed packages and some packages are included multiple times as they were installed multiple times and there are also some packages included which happened to be updated at the same time period. So after all I still need to check all packages one by one what I'm trying to avoid. –  AlexD Oct 2 '11 at 9:26
    
Added more info and a better way to handle your scenario. HTH. –  Mat Oct 2 '11 at 10:06
    
Thanks, direct access to /var/pkg/db is much better. I've modified your script to use equery depends to skip packages which have anything depended on them so I could get list of packages which is safe to remove without breaking other packages. Sets is interesting feature but it couldn't solve use case when package included in set is also used by some other package which is not included in set, so removing set would break this other package. –  AlexD Oct 7 '11 at 7:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.