The Secret to Unmasking in Gentoo (and Prefix too)

If you ever dip your toes into Gentoo Prefix, the first thing you’ll probably notice is that a lot of your software is either missing or masked. If you’re sharp, or have lots of experience already with Gentoo, you’ll also notice that your profile comes with the ~ unstable keyword by default. You see, Gentoo Prefix is a pretty small project in comparison to Gentoo itself, as far as I can tell, so not as much testing goes into every package, and not every package can be and/or is currently handled by Gentoo Prefix.

Let’s assume, however, that you really don’t care, like me. Let’s assume you want to try things and out and, like every other good citizen of Linux, you plan on tracking down and reporting every bug you find to the Gentoo/Alt bug tracker. You will most certainly try to emerge something that hasn’t been reasonably stabilized yet, like Pidgin. (I will go into more length on Pidgin later. For now, a summary would be “not for the faint of heart”.) If you’re running an x64 Prefix, just about anything you try to emerge will be keyworded or masked. Not discouraged, you’ll start adding the appropriate entries to your package.keywords and package.unmask directories. After your fifteenth entry, or third round of emerge’s, it gets pretty tedious.But that still doesn’t discourage you, because you quickly whip out the following command to finish it off:

unmask pidgin pidgin

If you try and look for this tool in the Gentoo repository, you will not find it. The unmask script is a handy little thing I snatched off the Gentoo Wiki (before it collapsed). Since I can’t find the page it was hosted on, and since I modified it to make it work with /etc/portage/package.*/ directories rather than files, I’m going to repost it here. Unfortunately there were no credits saved so I am unable to credit the author. If you know who wrote this, please step forward and let me know so I can add their name to the file and this blog post.

Update (2009/07/12): it turns out such unmasking software has snuck into the portage tree without me noticing. I would prefer it over this script, since anything is more stable than this script. See the comments area for more info.

#!/usr/bin/perl -w
use strict;

sub emerge
        my $package = shift;
        $_ = `emerge -pv "${package}" 2>&1`;

        if(m/^- (\S+) \(masked by:.*package.mask/mi) {
                print "Unmasking ${1} in package.unmask\n";
                print UNMASK "=${1}\n";
                return 1;
        if(m/^- (\S+) \(masked by:.*keyword/mi) {
                print "Unmasking ${1} in package.keywords\n";
                print KEYWORDS "=${1} **\n";
                return 1;
        if(m/^!!! masked or don't exist:\n(\S+)/mi) {
                while(emerge($1) != 0){}
                return 1;
        return 0;

our $filename = $ARGV[1];
if( ! $ARGV[1] ) {
        $filename = 'new';

open(UNMASK, ">>/Users/jacob/Library/Gentoo_x86/etc/portage/package.unmask/${filename}.unmask");
open(KEYWORDS, ">>/Users/jacob/Library/Gentoo_x86/etc/portage/package.keywords/${filename}.keywords");
our $package = $ARGV[0];
$package =~ s/"/\\"/g;
while(emerge($package) != 0){}
print "Done\n";

The usage is very simple. Simply run “unmask =cat/package-version somenamehere“. The first argument will take any valid package atom, and unmask or keyword it and all its dependencies automatically. The second argument is the name of the file where all that unmasking and keywording will take place. For example, if I ran “unmask =net-im/pidgin-2.5.7-r00.1 pidgin” the script above would unmask Pidgin v2.5.7-r00.1 (version explanation coming soon) and save all the unmasking in /etc/portage/package.unmask/pidgin.unmask and keywording in /etc/portage/package.keywords/pidgin.keywords.

The script is pretty simple and can get messed up easily, so don’t be surprised if something doesn’t work completely right. The arguments are pretty much assumed to be safe, for example. Also, there are a few times where it’s said “Done” but it really simply means it couldn’t find any more messages about lack of keywords or masks. More often than not emerge is actually running into an entirely different error that has to be solved first before unmask can continue.

Post a comment or leave a trackback: Trackback URL.


  • malditonerd  On July 12, 2009 at 1:19 pm

    You should check autounmask:

    ~ $ eix autounmask
    [I] app-portage/autounmask
    Available versions: 0.27
    Installed versions: 0.27(14:04:47 06/29/09)
    Description: autounmask – Unmasking packages the easy way

    It does exactly the same as your script does.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: