Saturday, 7 April 2007

Portage package.use Helper Script

I have sort of switched to Gentoo; I use it all the time except when I have to rescue Gentoo... It is more hands-on, but tools are definitely stronger. Compiling everything on installation offers a slight speed improvement, but what I really enjoy is the flexibility. You can choose the flags before compilation, compiling features in/out.

The file that you use to inform Portage (Gentoo's package manager) of your choices regarding these flags (USE flags) is /etc/portage/package.use by default. You have to add lines to it all the time, both to compile the source to fit your needs and to keep these settings for when you update this software later on. Syntax is [=]pkg-type/pkgname[version] flagyouwant -flagyoudontwant; the square brackets are for version-specific flags, you have to use them both for the version specific function to work. pkg-type is about the way packages are organized in Portage, examples are media-sound, X11-wm, kde-base.

The problem is, it is cumbersome to use echo "blah/blah flag mlag clag" >> /etc/portage/package.use all the time. Furthermore, if you use this, you will probably end up with duplicate entries (whose consequences, if there are any, I have no idea about), and your package.use file will be really messy; hard to review and modify.

Although I am pretty sure that there is a monstrously strong piece of program available in Portage for this task, I was feeling a bit rusty, so I decided to write a small executable Perl script to handle this. It is called, here's the twist, "use".

You are free to use/manipulate/silently mock it any way you want (oh yeah?). Use it once per package, execute as use [blah/]blah flag mlag -clag. The script will scan package.use file, if there is an existing entry, it will modify it to suit your choice. If not, it will create one. Then it will output in the right syntax back into the file, both lines and use flags sorted alphabetically (in a primitive way).

And feel free to give me feedback. Download it here.

No comments: