#!/bin/sh -e

# Author: Martin Pitt <martin.pitt@ubuntu.com>
# (C) 2005  Canonical Ltd.
#
# Get the status of IPP network browsing through exit code:
#
# 0: sharing is disabled (default configuration)
# 1: sharing is enabled for LAN
# 2: the configuration was adapted manually; in this case enable_sharing cannot
#    be used

MAINCONF=/etc/cups/cupsd.conf
PORTSCONF=/etc/cups/cups.d/ports.conf

[ -f $MAINCONF -a -f $PORTSCONF ] || exit 2

# if PORTSCONF is not included -> custom
egrep -qi "^[[:space:]]*Include[[:space:]]+($PORTSCONF|$(basename $PORTSCONF))[[:space:]]*(#.*)?\$" $MAINCONF || exit 2

if egrep -qi '^[[:space:]]*(Port|Listen)[[:space:]]+(631)[[:space:]]*(#.*)?$' $PORTSCONF; then
    exit 1
fi
if egrep -qi '^[[:space:]]*Listen[[:space:]]+(localhost:631)[[:space:]]*(#.*)?$' $PORTSCONF; then
    exit 0
fi
exit 2
