diff options
-rwxr-xr-x | bin/aptitude | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/bin/aptitude b/bin/aptitude new file mode 100755 index 0000000..54cd585 --- /dev/null +++ b/bin/aptitude @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# vim:ts=4 + +# This is just a replacement - for quite a while, while already abandoning aptitude, I still kept +# aptitude installed just for typing "aptitude why $package". This script just does this. + +# Converting because we need ${ARGARR[*]} +ARGARR=( "$@" ) + +MYERR="\\033[1;31mE:\\033[0m" + +function myhelp { + printf "USAGE: %b ( why PACKAGE [PACKAGE ..] | help )\\n\\n" "$(basename "$0")" + ( + printf "why:;Lists the recursive depends of a package, i.e. why it is installed.\\n" + printf " ;Wrapper to 'apt[-cache] rdepends --installed PACKAGE'\\n" + printf "help:;This help" + )|column -ts\; + printf "\\n" +} +if [ -z "$1" ];then + printf "%b No parameter supplied.\\n" "$MYERR" >&2 + exit 10 +fi + +case "$1" in + help|"-h"|"--help") + myhelp + exit 0 + ;; + why) + if [ -z "$2" ];then + printf "%b No package name(s) supplied.\\n" "$MYERR" >&2 + exit 12 + fi + for i in "${@:2}";do + IFS=$'\n' + # shellcheck disable=SC2207 + WHYARR=( $(apt rdepends --installed "$i" 2>/dev/null) ) + if [ "$?" -ne 0 ];then + apt rdepends --installed "$i" >/dev/null + exit 2 + fi + unset IFS + WHYDEPS="$(printf "%b\\n" "${WHYARR[@]}"|grep -P "^[\ \t]*Depends:")" + WHYBREAKS="$(printf "%b\\n" "${WHYARR[@]}"|grep -P "^[\ \t]*Breaks:")" + #WHYARCHS="$(printf "%b\\n" "${WHYARR[@]}"|grep -P "^[\ \t]*$i:")" + printf "%b\\n" "$i" + for (( j=0;j<${#i};++j ));do printf "=";done;printf "\\n" + printf "Installed packages with dependencies:\\n" + if [ -n "$WHYDEPS" ];then + printf "%b\\n" "$WHYDEPS" + else + printf " NO INSTALLED DEPENDENCIES\\n" + fi + if [ -n "$WHYBREAKS" ];then + printf "Supplemental information:\\n" + printf "%b\\n" "$WHYBREAKS" + fi + printf "\\n" + done + ;; + *) + printf "%b Arguments not understood: %b\\n" "$MYERR" "${ARGARR[*]}" >&2 + exit 11 + ;; +esac |