#!/bin/bash # Copyright Paul Sladen 2005-05-20 # Distributable under the terms of the GNU GPL v2. VERSION="0.0.1" usage () { cat << EOF 1>&2 usage: ${0##*/} [-h|--help] action [package|search-string|.deb] (see --help for more information) EOF } usage_full () { cat << EOF Usage: ${0##*/} [-h|--help] [package|pattern|.deb] apt-foo and dpkg wrapper to make life *really* baz-esq simple. Options: -h, --help this help Actions: build fakeroot apt-get -b source build-dep sudo apt-get build-dep clean sudo apt-get clean dist-upgrade sudo apt-get dist-upgrade install sudo apt-get install sudo dpkg -i purge sudo apt-get --purge remove remove sudo apt-get remove source apt-get source update sudo apt-get update upgrade sudo apt-get upgrade search apt-cache search show apt-cache show showpackage|showpkg apt-cache showpkg statistics|stats apt-cache stats reconfigure sudo dpkg-reconfigure find|which dpkg -S list dpkg -l listfiles dpkg -L status dpkg -s select sudo dselect | sudo synaptic archives grep '^deb ' /etc/apt/sources.list enable main|restricted|universe|multiverse info apt-cache show | grep -E '^(Description:)? ' setup sudo apt-setup EOF #Gentoo compatibility mode (TODO): # emerge sudo apt-get build-dep && mkdir -p /tmp/emerge-$$ # (cd /tmp/emerge-$$ ; fakeroot apt-get -b source && # sudo dpkg -i *.deb ) ; rm -rf /tmp/emerge-$$ } case "$1" in # apt-get build|emerge) priv=fakeroot ; command=apt-get ; action=source ; flags=-b ;; build-dep|clean|dist-upgrade|remove|update|upgrade) priv=sudo ; command=apt-get ; action="$1" ;; install) case "$2" in *.deb) priv=sudo ; command=dpkg ; action=-i ;; *) priv=sudo ; command=apt-get ; action="$1" ;; esac ;; purge) priv=sudo ; command=apt-get ; action=remove ; flags=--purge ;; source) command=apt-get ; action=source ;; # apt-cache search|show|showpkg) command=apt-cache ; action="$1" ;; statistics|stats) command=apt-cache ; action="stats" ;; # dpkg-reconfigure reconfigure) priv=sudo ; command=dpkg-reconfigure ;; # dpkg find|which) command=dpkg ; action=-S ;; list|listfiles|status) command=dpkg ; action="--$1" ;; # dselect / synaptic select) echo "$DISPLAY" case "$DISPLAY" in *:*) priv=sudo ; command=synaptic ;; ""|*) priv=sudo ; command=dselect ;; esac ;; # grepping archives) exec grep '^deb ' /etc/apt/sources.list ;; enable) shift exec sudo sed -i.apt-enable -e "s/^deb\ .*$/& $*/" /etc/apt/sources.list ;; info) shift apt-cache show "$@" | grep -E '^(Description:)? ' ; exit ;; # apt-setup setup) priv=sudo ; command=apt-setup ;; # assistance -h|--help|help) usage_full ; exit ;; "") usage ; exit ;; *) echo "E: Invalid action '$1'" >2 usage ; exit ;; esac shift echo running: $priv "$command" "$action" $flags "$@" if [ "x$priv" = "x" ] ; then exec "$command" "$action" $flags "$@" else exec $priv "$command" $action $flags "$@" fi