Alunduil's Hosting Gentoo Hackery and Other Fun …

23Jul/09

Cleaning /etc/portage/package.*

Inroduction

After a while the files in /etc/portage become cluttered with the common, "Let's try this . . . whoops that didn't work . . . let's try this." No matter how hard you try to keep this clean you have probably forgotten something along the way. Installing a testing package then removing it because you found a better one later, etc. Well what's an easy way to clean these files up and make sure that we minimize their sizes and keep our Gentoo system crisp (or as crisp as we can by just managing these files)? I've written some bash one-liners that assist with this and could easily be adapted into a script that automates a lot of the cleaning for you.

In all of these scripts change the /etc/portage/package.use to the file you are interested in cleaning.

Checking for Multiple Occurrences of an Atom Within a File

for atom in $(gawk '{print $1}' /etc/portage/package.use); do [ "$(grep ${atom} /etc/portage/package.use | wc -l)" -gt "1" ] && echo "${atom}"; done

Checking for N Uses of a Use Flag in /etc/portage/package.use

I use this to move frequently used use flags to /etc/make.conf if it seems appropriate.

for flag in $(gawk '{print $2}' /etc/portage/package.use); do [ "$(grep "${flag}" /etc/portage/package.use | wc -l)" -gt "2" ] && echo "${flag}"; done

Checking for Removed Atoms Within a File

for atom in $(gawk '{print $1}' /etc/portage/package.use); do [ "$(portageq match / ${atom} | wc -l)" -lt "1" ] && echo "${atom}"; done