#!/bin/bash if [[ x$(qlist -IC app-portage/portage-utils)x == xx || \ x$(qlist -IC app-portage/gentoolkit)x == xx ]] ; then echo "This utility requires both app-portage/portage-utils" >&2 echo "and app-portage/gentoolkit. Emerge them both and try again." >&2 exit 1 fi declare -a arguments atoms arguments=( ) atoms=( ) verbose=yes redic=no for arg in "$@" ; do case $arg in -q|--quiet) verbose=no ;; -r|--redic) redic=yes ;; *) arguments=( "${arguments[@]}" "$arg" ) ;; esac done [[ ${#arguments[*]} == 0 ]] && arguments=( '@world' ) for arg in "${arguments[@]}" ; do if [[ ${arg} == @* ]] ; then newatoms=( "${arg}" ) else newatoms=( "$( qlist -eICv "${arg}" | sed 's/^/=/' )" ) fi newatoms=( $( dumpworld "${newatoms[@]}" ) ) result=$? [[ ${result} != 0 ]] && { echo "dumpworld failed, giving up." >&2 ; exit ${result} ; } atoms=( "${atoms[@]}" "${newatoms[@]}" ) done # OK, we have all the packages -- remove dups, there could be a bunch. atoms=( $( for atom in "${atoms[@]}" ; do echo "${atom}" ; done | sort -u ) ) [[ ${verbose} == yes ]] && \ echo "Checking for files depended upon by the specified atom(s):" >&2 && \ echo >&2 total=0 totalfilechars=0 for atom in "${atoms[@]}" ; do # turns out equery filse includes certain files (/usr/lib/debug... but why?) # that qlist excludes so ... we'd might as well get all the bad news possible files=$( equery -Cq files "${atom}" ) result=$? [[ $result == 0 ]] || { echo "equery -Cq files ${atom} failed." >&2 ; exit $result ; } count=$( echo "${files}" | wc -l ) (( total += count )) while read filename ; do (( totalfilechars += ${#filename} )) done < <( echo "${files}" ) if [[ ${verbose} == yes ]] ; then if [[ ${redic} == yes ]] ; then echo "${files}" else echo "${atom}: ${count}" >&2 fi fi done [[ ${verbose} == yes ]] && echo >&2 && echo >&2 [[ ${verbose} == yes ]] && echo -n "TOTAL: " echo -n "${total}" averagepathlen=$(( totalfilechars / ${total} )) [[ ${verbose} == yes ]] && echo -n " files (in ${#atoms[*]} ebuilds, average path length: ${averagepathlen})" echo echo exit 0