#!/bin/sh
# $Id: get_hesiod_pcap,v 1.6 2007/09/26 16:21:24 jdreed Exp $

# Support script used by LPRng to fetch Hesiod printcap entries
#
# Modified from Athena's get_hesiod_pcap script

PATH=/usr/bin:/bin
# A file containing the name of an MIT printer
CONFIG=/etc/mit-lprng.conf

# Read in config
source $CONFIG

read printer

case "$printer" in
all)
    # If printer is "all", it wants a list of all available printers, the
    # first of which will be considered the default printer. We can't get
    # all printers, so just give the default.

    if [ -z "$PRINTER" ]; then
	PRINTER="$DEFPRINTER"
	if [ -z "$PRINTER" ]; then
	    # We have no default.  Let LPRng come up with its own default.
	    exit 0
	fi
    fi
    echo "all:all=$PRINTER"
    ;;

*)
    # Otherwise just look up the printer it asked for
    if [ -x /usr/bin/hesinfo ]; then
	PCAP=`hesinfo $printer pcap 2>/dev/null`
    else
	PCAP=`host -t txt $printer.pcap.ns.athena.mit.edu | sed -e 's/.*\"\(.*\)\".*/\1/'`
	# Some versions of host(1) don't set their exit status correctly.
	echo $PCAP | grep -q NXDOMAIN
	[ $? = 0 ] && exit 0
    fi
    
    if [ true != "$FORCEAUTH" ]; then
	PCAP=`echo $PCAP | sed '/ka#0/s/auth=kerberos5://g'`
    fi
    echo $PCAP | sed 's/kerberos5/kerberos/g'
    ;;
esac

exit 0
