TIP Regenerate package keywords

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

The following command-sequence generates new /etc/portage/package.{keywords/unmask) files based upon the packages currently installed:

Code: the script
#!/bin/sh
KEYWORDS="/etc/portage/package.keywords"
UNMASK="/etc/portage/package.unmask"

mv ${KEYWORDS} ${KEYWORDS}~
mv ${UNMASK} ${UNMASK}~

echo "Rewriting package.keywords"
equery -N l -i | sed -nre '/(M~|M | ~)/ s/(^.+\] | \(.+$)//gp' | sed -re 's/^/=/g' >> ${KEYWORDS}

echo "Rewriting package.unmask"
ALL=$(wc -l ${KEYWORDS} | awk '{print $1}')
COUNT=0
while read KEYWORD; do
	COUNT=$[$COUNT + 1]
	echo -ne " $[${COUNT} * 100 / ${ALL}]% finished\r"
	emerge -pv ${KEYWORD} | grep "package.mask" &>/dev/null && echo ${KEYWORD} >> ${UNMASK}
done < ${KEYWORDS}
echo "                                               "
echo "Done"
Note: equery is part of app-portage/gentoolkit

You may use this to:

  • Remove outdated lines from your package.(keywords/unmask) file
  • Replace unmasked packages with information on specific versions

The latter is useful, if you unmasked a lot of packages and you find the regular dependency problems occurring on portage-tree-updates annoying.

After execution, check whether emerge -pve world exits without errors. If not, you may either correct errors by hand or just restore the backup.

Personal tools