#!/usr/bin/env bash
while [ -n "${1}" ]
do
case "${1}" in
-d) disp_deptree=TRUE ;;
-a) disp_pkg=TRUE ;;
-p) disp_ports=TRUE ;;
-h)
cat <<EOF
This tool will walk all your installed packages for out-of-date ports.
You must update your ports tree before this will be accurate.
-d Display deptree
-a Display list of out-of-date packages
-p Display list of port directory names corresponding to out-of-date packages
EOF
exit 8
;;
*) echo "Unknown option: ${1}"; echo "${0} -h for help"; exit 8 ;;
esac
shift
done
str_repeat() {
repeat="${1}"
while [ "${repeat}" -gt 0 ]
do
echo -n "${2}"
repeat=$(( ${repeat} - 1))
done
}
clear_deps() {
depth=0
storevar="list_${depth}"
eval list=\${${storevar}}
while [ -n "${list}" ]
do
echo "Clearing $storevar"
unset $storevar
depth=$(( ${depth} + 1 ))
storevar="list_${depth}"
eval list=\${${storevar}}
done
}
resolve_deps(){
depth="${1}"
storevar="list_${depth}"
shift
while [ -n "${1}" ]
do
[ -n "${disp_deptree}" ] && str_repeat ${depth} -
[ -n "${disp_deptree}" ] && echo "${1}"
eval ${storevar}="\"\${${storevar}} ${1}\""
deps=$(pkg_info -Rq "${1}" | sed -e '/^$/d')
if [ -n "${deps}" ]
then
resolve_deps $(( ${depth} + 1 )) ${deps}
depth=$(( ${depth} - 1 ))
storevar="list_${depth}"
fi
shift
done
}
print_deps() {
depth=0
storevar="$(printf "list_%u" "${depth}")"
eval list=\${${storevar}}
while [ -n "${list}" ]
do
for item in ${list}
do
printf "%u\t%s\n" "${depth}" "${item}"
done
depth=$(( ${depth} + 1 ))
storevar="list_${depth}"
eval list=\${${storevar}}
done
}
clear_deps
[ -n "${disp_deptree}" ] && echo ""
resolve_deps 0 $(pkg_version -vl '<' | cut -d' ' -f1)
[ -n "${disp_pkg}" ] && echo ""
[ -n "${disp_pkg}" ] && print_deps | sort --key=2 --reverse | uniq -f 1 | sort | cut -f 2
[ -n "${disp_ports}" ] && echo ""
[ -n "${disp_ports}" ] && print_deps | sort --key=2 --reverse | uniq -f 1 | sort | cut -f2 | while read name
do
pkgdb -qo "${name}"
done