#!/bin/sh
# Copyright (c) 2001 Graham Williams, Kayon Toga, Joe Wreschnig
# Feta plugin for querying Debian servers.
# Licensed under the GNU GPL.

OPTS=`getopt -n configure -o V,q,t,y -- $@`
if [ $? != 0 ] ; then exit 1; fi
eval set -- "$OPTS"
QUIET=0

while true ; do
 case "$1" in
  -q) QUIET=1; shift;;
  -t|-V|-y) shift;;
  --) shift; break;;
 esac
done

if [ $# -eq 0 ]; then
 echo "E: You must provide at least one package name."
 exit 1
fi

if [ $QUIET -eq 0 ]; then
 echo "If you recieve no response, the package is not available on the Debian"
 echo "servers."
fi

if ping -c 1 packages.debian.org 2>&1 >/dev/null; then
 for i in $*; do
 echo
 echo "Contacting Debian server about $i... "
  results=${scratch_dir}/whatis.results
  wget --output-document=- http://packages.debian.org/cgi-bin/search_packages.pl\?keywords=$i\&searchon=names\&subword=1\&release=all 2> /dev/null |
   egrep '<TD><B><A HREF|<TD COLSPAN=2>' |
    perl -p -e 's|<[^>]*>||g;s|^  ||g;s|^&nbsp; | |;s|&nbsp;||g;s|&quot;|"|g;'
 done
else
 echo "E: The Debian server could not be contacted."
 exit 1
fi
