#!/bin/bash - # deb--wrapper/reminder for various apt* and dpkg command # $Id: deb 1377 2007-09-06 18:17:16Z root $ PROGRAM=$(basename $0) # What's our name? VERSION='$Id: deb 1377 2007-09-06 18:17:16Z root $' COPYRIGHT='Copyright 2007 JP Vossen (http://www.jpsdomain.org/)' LICENSE='GNU GENERAL PUBLIC LICENSE v2' #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Help # Called like: Usage function Usage { # Note use of <<- 'here document' style which strips leading TABs but # not leading space, allowing for more or less proper indenting. # Follow the classic man page format less -n <<-EoN NAME $PROGRAM--wrapper/reminder for various apt* and dpkg command SYNOPSIS $PROGRAM [command] [arguments] COMMANDS * The | in upd|ate means you only need to type the "upd" part. * means one or more space delimited package names * means a single egrep regular expression (e.g. 'zip|arj') upd|ate # Update the package cache (do this at least weekly) che|ck,chk # Check for available upgrades upche|ck,upchk # Update, then check for available upgrades upg|rade # Upgrade all installed packages dist|-upgrade # Really upgrade all installed packages se|arch;find # Search for in the package cache sh|ow,info # Show details about package showpkg # Show name and various depends info for in|stall # Install package rem|ove # Remove package # (--purge removes config files too!) what # Show the name and version of if installed which,installed,list # Same as previous files # List the files installed by package dep|ends # Show packages depends on rdep|ends # Show other packages that depend on pro|vides # Show the capability that provides whatpro|vides # Show the package that provides clean # Remove downloaded package files from the cache autoclean # Remove obsolete packages from the cache purge # Purge the local cache, forces complete re-download stats # Show package cache stats Examples: $PROGRAM update $PROGRAM find zip $PROGRAM install zip DESCRIPTION ($VERSION) The Debian Advanced Package Tool (apt) is a very powerful and flexible packaging tool. But its functions are scattered among a number of tools and it's hard to keep track of what's where, especially coming from yum, which is very simple. Just as rpm is the basis for yum, dpkg is the basis for apt, but like yum apt has a package cache and various ways to manipulate it. This is just a wrapper to unify the tools. AUTHOR / BUG REPORTS JP Vossen (jp {at} jpsdomain {dot} org) http:www/jpsdomain.org COPYRIGHT & LICENSE $COPYRIGHT $LICENSE SEE ALSO * apt-file * http://www.debian.org/doc/manuals/apt-howto/index.en.html * http://nakedape.cc/wiki/PackageManagerCheatsheet * http://www.togaware.com/linux/survivor/Wajig_Overview.shtml Wajig is similar to this script and is far more comprehensive, but also much larger and more complicated. * aptitude is more powerful than apt-get, and includes some features of apt-cache as well (but it likes to install "recommended" packages by default (http://people.debian.org/~dburrows/aptitude-doc/en/ch02s04s05.html#configRecommends-Important)). * man pages for apt-get, aptitude, apt-cache, apt-query, dpkg, and even rpm and yum * localepurge and deborphan are great too EoN } # end of function Usage #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Show the command to run, then run it # Called like: Run foo function Run { echo "$*" eval $* } ########################################################### # Main # These are the programs we need apt_get="$(type -P aptitude)" # Use aptitude if available # If aptitude is available, do *not* treat recommendations as dependencies # when installing new packages! If it's not there, fall back to 'apt-get'. [ $apt_get ] && apt_get="$apt_get --without-recommends" \ || apt_get='apt-get' apt_cache='apt-cache' dpkg='dpkg' dpkg_query='dpkg-query' egrep='egrep' sort='sort' # Use less if we can, else use more less=$(type -P less) [ $less ] && less="$less --quit-if-one-screen" || less='more' # Figure out what to do and go do it case "$1" in # upd|ate # Update the package cache (do this at least weekly) upd* ) Run "$apt_get update" ;; # che|ck,chk # Check for available upgrades che*|chk ) # apt_get -s, --simulate, --just-print, --dry-run, --recon, --no-act # $apt_get --simulate dist-upgrade Run "$apt_get --simulate upgrade" ;; # upche|ck,upchk # Update, then check for available upgrades upche*|upchk ) $0 update && $0 check ;; # upg|rade # Upgrade all installed packages upg* ) Run "$apt_get upgrade $*" ;; # dist|-upgrade # Really upgrade all installed packages dist* ) Run "$apt_get dist-upgrade" ;; # se|arch;find # Search for in the package cache se*|find ) shift Run "$apt_cache search $* | $sort | $less" ;; # sh|ow,info # Show details about package sh*|info ) shift Run "$apt_cache show $* | $less" ;; # showpkg # Show name and various depends info for showpkg ) shift Run "$apt_cache showpkg $* | $less" ;; # in|stall # Install package in* ) shift Run "$apt_get install $*" ;; # rem|ove # Remove package rem* ) shift Run "$apt_get remove $*" ;; # what # Show the name and version of if installed # which,installed,list # Same as previous what|which|installed|list ) shift [ "$1" ] && and_maybe_grep="| $egrep -i $1" # dpkg-query -W | --show Run "$dpkg_query --show | perl -pe 's/^(.*?)\t(?:\d:)?(.*)\$/\$1_\$2/;' \ | sort $and_maybe_grep" ;; # files # List the files installed by package files ) shift # dpkg -L | --listfiles Run "$dpkg -L $* | $less" ;; # dep|ends # Show packages depends on dep* ) shift Run "$apt_cache depends $* | $less" ;; # rdep|ends # Show other packages that depend on rdep* ) shift Run "$apt_cache rdepends $* | $less" ;; # pro|vides # Show the capability that provides pro* ) echo 'Not implemented yet' exit 2 ;; # whatpro|vides # Show the package that provides whatpro* ) # dpkg_query -S | --search Run "$dpkg_query --search $2" ;; # clean # Remove downloaded package files from the cache clean ) Run "$apt_get clean" ;; # autoclean # Remove obsolete packages from the cache autoclean ) Run "$apt_get autoclean" ;; # purge # Purge the local cache, forces complete re-download purge ) Run "$apt_get purge" ;; # stats # Show package cache stats stats ) Run "$apt_cache stats" ;; verify ) # Verify all installed packages # Use debsums echo "Like rpm -Va, but not implemented yet--use debsums" ;; changelog ) # Show package changes echo "Not implemented--use apt-listchanges" # lynx http://master.debian.org/cgi-bin/get-changelog\?package=$1 ;; -h|--help|help|'?' ) Usage exit 0 ;; * ) echo -e "\nBad command: try $PROGRAM -h" exit 1;; esac