Skip to content

Instantly share code, notes, and snippets.

@garymacindoe
Created April 15, 2015 12:14
Show Gist options
  • Save garymacindoe/59924db9f3f8b75f696f to your computer and use it in GitHub Desktop.
Save garymacindoe/59924db9f3f8b75f696f to your computer and use it in GitHub Desktop.
Checks for invalid/obsolete entries in Gentoo Portage's package.use files
#!/bin/bash
#
# Author: Gary Macindoe
# Date: May 2013
files="/etc/portage/package.use"
if [ -d "${files}" ]
then
files="${files}/*"
fi
for file in ${files}
do
echo -e "\E[1;33;40m${file}:"
grep -Ev '^[ \t]*#|^$' ${file} | while read atom uses
do
packages="$(equery -q l ${atom} 2>/dev/null)"
if [ $? -ne 0 ]
then
echo -e "\E[0;31;40mNo package installed matching ${atom}"
fi
package_uses=""
skip=2
for package in ${packages}
do
package_use="$(equery -q u ${package} 2>/dev/null)"
if [ $? -ne 0 ]
then
echo -e "\E[0;31;40mUnable to find use flags for ${package} (most likely the ebuild has been removed)"
if [ ${skip} -ne 0 ]
then
skip=1
fi
else
package_uses="${package_uses} $(echo ${package_use} | sed -e's/^-\|+//g')"
skip=0
fi
done
if [ ${skip} -eq 0 ]
then
echo -ne " \E[0;36;40m$(echo ${atom} | cut -d'/' -f1)/\E[0;32;40m$(echo ${atom} | cut -d'/' -f2)"
for use in ${uses}
do
if [ ! "$(echo ${package_uses} | grep -- $(echo ${use} | sed -e's/^-\|+//g'))" ]
then
if [ "$(echo ${use} | cut -c1)" = "-" ]
then
echo -ne " \E[1;34;40m${use}"
else
echo -ne " \E[1;31;40m${use}"
fi
fi
done
echo
fi
done
done
if [ -e "/etc/portage/make.conf" ]
then
file="/etc/portage/make.conf"
else
file="/etc/make.conf"
fi
if [ -e "${file}" ]
then
echo -e "\E[1;33;40m${file}:"
uses="$(grep ^USE= ${file} | cut -d'"' -f2)"
for use in ${uses}
do
u=$(echo ${use} | sed -e's/^-\|+//g')
equery -q h ${u} &>/dev/null
if [ $? -ne 0 ]
then
if [ "$(echo ${use} | cut -c1)" = "-" ]
then
echo -ne " \E[1;34;40m${use}"
else
echo -ne " \E[1;31;40m${use}"
fi
fi
done
fi
echo -e "\E[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment