#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/apt alias am='aptitude show' alias as='aptitude search' alias ar='sudo apt-get -qq remove' alias ap='sudo apt-get -qq purge' package-versions () { apt list -a $1 } alias vers=package-versions apt-install () { apt-get-update sudo apt-get -qq install $@ } alias ai=apt-install apt-reinstall () { apt-get-update sudo apt-get -qq reinstall $@ } alias aii=apt-reinstall a1 () { sudo apt-get -qq check sudo apt-get -qq update sudo apt-get -qq --purge -y autoremove sudo aptitude -q=99 autoclean sudo find /etc -name '.dpkg-' -o -name '.ucf-' -o -name '*.merge-error' apt -a list --upgradable } a2 () { a1 sudo apt -qq upgrade sudo apt dist-upgrade } require-bin () { local bins=($@) local all_good=true local fun=$funcstack[2] echo "checking requirements for" echo "\n ${fun}\n" for b in $bins; do echo -n " $b: " type $b &> /dev/null if (( ! $? )); then set-color green echo OK else set-color red echo fail all_good=false fi reset-color done if ( ! $all_good ); then echo "\nnot all" return 1 else echo "\nall systems ready" return 0 fi } apt-installed () { apt list --installed } apt-get-update () { sudo apt-get -qq update } apt-get-upgrade () { apt-get-update if [ $# > 0 ]; then sudo apt-get -qq install --only-upgrade $@ else sudo apt-get -qq upgrade fi } alias au=apt-get-upgrade apt-get-upgrade-dist () { apt-get-update sudo apt-get -qq dist-upgrade } packs () { apt-cache pkgnames | wc -l } command-to-pack () { if [[ $# = 1 ]]; then local cmd=$1 local whereis_path=$(whereis $cmd | awk '{print $2}') local bin=$(readlink -e $whereis_path) if [[ -z $bin ]]; then local fun=$funcstack[1] echo \ "$fun error: no such command (\"$cmd\")" \ "\nNB: $fun deals with installed software," \ "\n to track the package of any binary, use" \ "\n $ bin-to-pack BINARY-NAME" >&2 return fi bin-to-pack $bin else echo "syntax: $0 COMMAND" >&2 fi } alias cmd2pack=command-to-pack bin-to-pack () { local fs=($@) deb-file-to-pack $fs file-to-pack $fs } alias bin2pack=bin-to-pack pack-to-file () { local pack=$1 local only_bins=$2 local fs=("${(@f)$(dpkg --listfiles $pack)}") if [[ $only_bins == 1 ]]; then for f in $fs; do [[ -x $f && ! -d $f ]] && echo $f done else for f in $fs; do [[ -f $f ]] && echo $f done fi | sort } alias files-from=pack-to-file pack-to-bin () { local pack=$1 pack-to-file $pack 1 # only_bins } alias bins-from=pack-to-bin deb-file-to-pack () { local fs=($@) dpkg --search $fs 2> /dev/null | cut -d ':' -f 1 } file-to-pack () { sudo apt-file update > /dev/null apt-file search $@ } alias file-there=file-to-pack get-source () { apt-get -qq source $@ } alias get-src=get-source get-command-source () { if [[ $# = 1 ]]; then local cmd=$1 get-source $(cmd2pack $cmd) else echo "syntax: $0 COMMAND" >&2 fi } # aptitude search -F %V "?exact-name(units)" file-url () { local pack=$1 local ver=$(dpkg-query -f '${Version}\n' -W $pack) local file=$2 local url=https://sources.debian.org/data/main/u/$pack/$ver/$file echo $url }