#!/usr/bin/perl -w


print "ARGV[0]=$ARGV[0]\n";

&doit;
exit(0);

# doit()
sub doit
{
	local $flag = 1;
	local $package = $ARGV[0];

	while($flag)
	{
		$flag = 0;
		open my $fh, "emerge $package -p|" || die "could not open: emerge $package -p";
		while(<$fh>) {
			#print $_;
			if(/^\-\s+(.*)\-[\d\.]+[\_\-a-zA-Z\d]*\s+\(masked by\:\s+(\~\S+)\s+keyword\)/) {
				unmask($1, $2);
				$flag = 1;
				last;
			}
		}
		close($fh);
	}
}

sub unmask
{
	local($name, $arch) = @_;

	print "unmasking: $name\n";

	open my $fh, ">>/etc/portage/package.keywords" || die "can't open package.keywords: $!";
	print $fh "$name $arch\n";
	close $fh;
}

