TIP Mass Unmasking

From Gentoo Linux Wiki

Jump to: navigation, search
This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

[edit] Introduction

Despite the fact that this is rather hackish and definitely not The Right Way (tm), it works well to unmask packages in bulk. For example, if you want gnome-2.18, no questions asked: emerge-alpha "=gnome-base/gnome-2.18.0"

[edit] Preparation

As root:

mkdir bin
cd bin
touch emerge-alpha
ln -s emerge-alpha emerge-beta
vim emerge-alpha

[edit] The Script

File: emerge-alpha.sh
#!/bin/bash
# /usr/local/bin/emerge-alpha
# /usr/local/bin/emerge-beta
#
if [ ! -n "${1}" ]; then
       echo "USAGE: ${0} =port-cat/package-name-1.9"
fi


EMERGE=`nice -n 15 emerge --deep --update --newuse --nospinner "${1}" -pv`
ALPHA=`echo "${0}" | grep "alpha"`


PACKAGE=`echo "${EMERGE}" | grep "All ebuilds that could satisfy"`
PACKAGE_IS=`echo "${PACKAGE}" | cut -d' ' -f7 | cut -d'"' -f2`
PLAT="x86"
HAS_PLAT=`echo "${EMERGE}" | grep ~"${PLAT}"`
HARD_MASK=`echo "${EMERGE}" | grep "package.mask"`

if [ -n "${HARD_MASK}" ] && [ -n "${ALPHA}" ]; then
        echo "Unmasking ${PACKAGE_IS}"
        echo "${PACKAGE_IS}" >> /etc/portage/package.unmask
        ${0} ${1}
elif [ -n "${HARD_MASK}" ]; then
        echo "Hard Masked... use emerge-alpha if you dare"
fi

if [ -n "${HAS_PLAT}" ]; then
        echo "${PACKAGE_IS}: Adding Keyword ~${PLAT}"
        echo "${PACKAGE_IS} ~${PLAT}" >> /etc/portage/package.keywords
        ${0} ${1}
fi

echo "Attempting to emerge..."
echo "(If you are running emerge-beta and this fails, try emerge-alpha - DANGEROUS)"
nice -n 15 emerge --deep --update --newuse --nospinner "${1}"

[edit] Yet another Script

Here's another script written in Perl that basically does the same thing. It's been tested to unmask xorg-x11, kde, as well as other packages all at once.

[edit] Installation:

cat > /usr/bin/unmask
(copy the codes shown below and then hit Enter and Ctrl-D)
chmod 755 /usr/bin/unmask

[edit] Script:

File: /usr/bin/unmask
#!/usr/bin/perl
my( $pack ) = "" ;
$pack .= " $_" for ( @ARGV ) ;
my( $b ) = 1;
while( $b )
{
$b = '' ;
@out = `emerge -pv$pack` ;
$portage = '/etc/portage/package' ;
for ( @out )
{
	if ( /^-\s+(.+?\/.+?)\-\d+\..*?\(masked by: (.+?(\,\s+.+?)*)\)/i )
	{
		my( $package , $masked ) = ( $1 , $2 ) ;
		foreach $a ( split( /\,\s+/, $masked ) )
		{
			if ( $a eq "package.mask" )
			{
				$b .= "echo $package >> $portage.unmask\n" ;
			}
			elsif ( $a =~ /(\W.+?)\s+keyword/i )
			{
				$b .= "echo $package $1 >> $portage.keywords\n" ;
			}
			elsif ( $a =~ /(missing)\s+keyword/i )
			{
				$b .= "echo \"$package ~*\" >> $portage.keywords\n" ;
				$b .= "echo $package >> $portage.unmask\n" ;
			}
		}
		last ;
	}
}
print $b ;
print `$b` ;
}


[edit] Usage:

You can use the following codes to unmask xorg-x11 (for the latest version 7.0), kde, and kdm automatically (around 200+ packages):

 echo "x11-base/xorg-x11 ~*" >> /etc/portage/package.keywords
 echo "kde-base/kde ~*" >> /etc/portage/package.keywords
 echo "kde-base/kdm ~*" >> /etc/portage/package.keywords
 unmask xorg-x11 kde kdm
Personal tools