TIP_Filtering_Packages
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
When building Xen instances on my work station, I definitely wanted to use quickpkg to make use of what I had on hand -- but I didn't want to make packages of OpenOffice, Mozilla or JDK 1.6! Deft use of equery, egrep, sed and then equery again allows us to filter on many different axes to get rid of a bunch of time-consuming, space-consuming packages.
| Code: filtering our packages |
#!/bin/sh
##
## List installed packages if they are likely to be useful in a Xen
## instance.
##
function packages {
equery --quiet list
}
## a helper function, to parse multiline token lists into regex alternations
function tokens_to_alternation {
echo $1 | sed -r 's/[[:space:]]/|/g'
}
## filters out packages in the 'do not want' categories
function category_filter {
do_not_want="
sys-kernel x11- virtual gnome- media-video media-sound net-wireless
dev-java
"
egrep -v "^("`tokens_to_alternation "$do_not_want"`")"
}
## eliminate packages with any of the 'do_not_want' tokens in their names
function name_filter {
do_not_want="
mozilla gimp scim uim xvid
x11 xorg
opengl mesa glut
gtk cairo gnome
"
egrep -v `tokens_to_alternation "$do_not_want"`
}
## this is by far the most expensive operation, making multiple calls to
## equery and writing to a tmp file after every one
function use_flag_filter {
c=/tmp/has_gui_cache
[ -f $c ] && rm $c
touch $c
do_not_want="
xorg xv X gnome kde xfs xft glut gtk gtk2 qt qt3 qt4 opengl
"
for flag in $do_not_want
do
equery --quiet hasuse $flag | sort >> $c
done
sort $c | uniq > /tmp/has_gui
comm -2 -3 - /tmp/has_gui
}
packages | category_filter | name_filter | use_flag_filter
|
Last modified: Thu, 27 Dec 2007 02:30:00 +1100 Hits: 2,950
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should be using interactive floor plans and real estate agent tools.
