#!/bin/sh -e
#
# Test if the CUPS server is working.

. /usr/share/debian-edu-config/testsuite-lib.sh

if test -r /etc/debian-edu/config ; then
    . /etc/debian-edu/config
fi

if [ -f /etc/cups/cupsd.conf ] ; then
    :
else
    echo "error: $0: /etc/cups/cupsd.conf is missing.  Is cupsys installed?"
    exit 1
fi

if pidof cups-browsed > /dev/null ; then
    echo "success: $0: cups-browsed is running."
else
    echo "error: $0: cups-browsed is not running."
    exit 1
fi

netstat_check ipp tcp "cupsd" || exit 1

# * Ignore SSL certificate checking as the name do not match the server
#   name
# * Wait for 10 seconds
WGETOPTS="--no-check-certificate --timeout=10"

unset http_proxy || true
unset ftp_proxy  || true

# Since Jessie, Expect CUPS to only listed on port 631 on localhost.
for url in "http://localhost:631/" "https://localhost:631/" ; do
    if wget -O - $WGETOPTS $url > /dev/null 2>&1 ; then
	echo "success: $0: URL '$url' is working."
    else
	echo "error: $0: URL '$url' is not working."
    fi
done

exit 0
