#! /bin/zsh # # this file: # http://user.it.uu.se/~embe8573/conf/.zsh/apt # https://dataswamp.org/~incal/conf/.zsh/apt offending-packages () { ls -lut /var/lib/dpkg/info } alias am='aptitude show' alias as='aptitude search' alias ai='sudo apt-get --install-suggests install' alias ari='sudo apt-get --install-suggests reinstall' alias ar='sudo apt-get remove' alias ap='sudo apt-get purge' aok () { sudo apt-get -qq update sudo apt-get -qq autoremove sudo aptitude -q=2 autoclean sudo apt-get -qq check apt list --upgradable } aok-2 () { aok sudo apt-get -qq upgrade } alias aouk=aok-2 require-bin () { local -a bins 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 install --only-upgrade $@ else sudo apt-get upgrade fi } alias au=apt-get-upgrade apt-get-upgrade-dist () { apt-get-update sudo apt-get dist-upgrade } 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 -a files files=($@) deb-file-to-pack $files file-to-pack $files } alias bin2pack=bin-to-pack pack-to-file () { local pack=$1 local only_bins=$2 local -a files files=("${(@f)$(dpkg --listfiles $pack)}") if [[ $only_bins == 1 ]]; then for f in $files; do [[ -x $f && ! -d $f ]] && echo $f done else for f in $files; 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 () { dpkg --search $files 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 alias file2pack=file-to-pack get-source () { apt-get 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 }