#!/bin/sh

msg_usage()
{
	self=$0
	apt-get -v|head -n1
	cat <<EOF
Usage: $self [options] command
       $self [options] install|remove pkg1 [pkg2 ...]
       $self [options] source pkg1 [pkg2 ...]
       $self [options] add file1 [file2 ...]
       $self [options] showpkg pkg1 [pkg2 ...]
       $self [options] showsrc pkg1 [pkg2 ...]

apt is a unified command line interface tool for all apt utilities,
including apt-get, apt-cache and apt-cdrom. Basically, it understands
all the command these utilities use and redirect them to appropriate
one.

Commands:
   update - Retrieve new lists of packages
   upgrade - Perform an upgrade
   install - Install new packages (pkg is libc6 not libc6.rpm)
   remove - Remove packages
   source - Download source archives
   build-dep - Configure build-dependencies for source packages
   dist-upgrade - Distribution upgrade, see apt-get(8)
   clean - Erase downloaded archive files
   autoclean - Erase old downloaded archive files
   check - Verify that there are no broken dependencies
   add - Add a package file to the source cache
   gencaches - Build both the package and source cache
   showpkg - Show some general information for a single package
   showsrc - Show source records
   stats - Show some basic statistics
   dump - Show the entire file in a terse form
   dumpavail - Print an available file to stdout
   unmet - Show unmet dependencies
   search - Search the package list for a regex pattern
   show - Show a readable record for the package
   depends - Show raw dependency information for a package
   whatdepends - Show raw dependency information on a package
   pkgnames - List the names of all packages
   dotty - Generate package graphs for GraphVis
   policy - Show policy settings

Options:
  -h   This help text.
  -q   Loggable output - no progress indicator
  -qq  No output except for errors
  -d   Download only - do NOT install or unpack archives
  -s   No-act. Perform ordering simulation
  -y   Assume Yes to all queries and do not prompt
  -f   Attempt to continue if the integrity check fails
  -m   Attempt to continue if archives are unlocatable
  -u   Show a list of upgraded packages as well
  -b   Build the source package after fetching it
  -D   When removing packages, remove dependencies as possible
  -p=? The package cache.
  -s=? The source cache.
  -i   Show only important deps for the unmet command.
  -c=? Read this configuration file
  -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp

See the apt-get(8) and apt-cache(8) manual pages for more information.
EOF
}

while getopts ":hq:dsyfmubDip:s:c:o:" option
do
	case $option in
	h)
		msg_usage
		exit 1
		;;
	d | s | y | f | m | u | b | D | i)
		opts="$opts -$option"
		;;
	q | p | s | c | o)
		opts="$opts -$option$OPTARG"
		;;
	h | *)
		msg_usage
		exit 1
	esac
done

shift $(($OPTIND - 1))

cmd=$1
shift
case "$cmd" in
	update | upgrade | install | remove | source | build-dep | dist-upgrade | clean | autoclean | check)
		apt-get $opts $cmd $@
		;;
	add | gencaches | showpkg | showsrc | stats | dump | dumpavail | unmet | search | show | depends | whatdepends | pkgnames | dotty | policy)
		apt-cache $opts $cmd $@
		;;
	*)
		msg_usage
		exit 1
		;;
esac
