Skip to content

Instantly share code, notes, and snippets.

@livibetter
Created March 5, 2012 06:06
Show Gist options
  • Select an option

  • Save livibetter/1976974 to your computer and use it in GitHub Desktop.

Select an option

Save livibetter/1976974 to your computer and use it in GitHub Desktop.
Gentoo USEness
#!/bin/bash
# Written by Yu-Jie Lin
# This script is placed in Public Domain
#
# Dependency: eix
if ! type eix &>/dev/null; then
echo "Please emerge app-portage/eix first, eix is required tool." 1>&2
exit 1
fi
#########
# USEness
# TODO Any options in eix to get red of last line Found ## matches?
ALL_USES="$(FORMAT='<installedversions:USEONLY>' USEONLY='{haveuse}<use>\n{}' eix --nocolor -I | grep -v Found)"
TOTAL_USES=$(echo "$ALL_USES" | wc -w)
echo "USE flags in total = $TOTAL_USES"
echo -n "The Gentoo USEness = "
sed 's/ -.*//' <<< "$ALL_USES" |
awk -v t=$TOTAL_USES 'BEGIN {tc=1/t^2} {p=NF/t+tc; h += -p*log(p)/log(2)} END {print h}'
# NOTE tc is introduced for possible package version with no USE enabled, pretty sure it is a flaw.
###############
# Other numbers
INSTALLS=$(FORMAT='<category>/<name>\n' eix -I | grep -v Found | wc -l)
UNSTABLES=$(FORMAT='<category>/<name>\n' eix --installed-unstable | grep -v Found | wc -l)
UPGRADES=$(FORMAT='<category>/<name>\n' eix --upgrade | grep -v Found | wc -l)
OBSOLETES=$(FORMAT='<category>/<name>\n' eix --test-obsolete | grep -v Found | wc -l)
echo
echo "Installed Packages = $INSTALLS"
echo "Unstable Packages = $UNSTABLES"
awk -v i=$INSTALLS -v u=$UNSTABLES 'BEGIN {printf("Unstableness = %f%%\n", u/i*100)}'
echo "Upgradab' Packages = $UPGRADES"
awk -v i=$INSTALLS -v u=$UPGRADES 'BEGIN {printf("Upgradableness = %f%%\n", u/i*100)}'
echo "Obsolete Packages = $OBSOLETES"
awk -v i=$INSTALLS -v o=$OBSOLETES 'BEGIN {printf("Obsoleteness = %f%%\n", o/i*100)}'
@livibetter
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment