#! /bin/bash
#
# Test ability to connect to remote IPP server.
#
# Exits:   0 doesn't seem to have a problem
#          1 remote host $1 or queue $2 not set
#          2 the remote host $1 is unreachable
#          3 no connection possible to port 631 on host $1 (no cups server running ?)
#          4 queue does not accept a print job (queue does not exist or queueing disabled ?)
#
# Johannes Meixner <jsmeix@suse.de>, 2000, 2002
# Jan Holesovsky <kendy@suse.cz>, 2000
# Jiri Srain <jsrain@suse.cz>, 2002
# $Id: test_remote_ipp 2928 2002-06-27 08:53:17Z jsrain $

#set -x
MY_NAME=${0##*/}
HOST="$1"
QUEUE="$2"
[ -z "$HOST" -o -z "$QUEUE" ] && { echo -en "\nUsage:\n$MY_NAME HOST QUEUE [TIMEOUT]\n" 1>&2 ; exit 1 ; }
TIMEOUT="$3"
[ -z "$TIMEOUT" ] && TIMEOUT=10

# test whether the remote host is accessible
ping -c 1 -w $TIMEOUT $HOST || { echo -en "\nHost $HOST unreachable\n" ; exit 2 ; }

# test whether connection is possible to port 631 (ipp) on the remote host
netcat -w $TIMEOUT -z $HOST 631 || { echo -en "\nNo connection possible to port 635 (ipp)\n" ; exit 3 ; }

# test the queue and server
echo -en "\r" | lp -d $QUEUE -h $HOST 2>&1;

RES=$?

if [ $RES -eq 0 ];
 then
    exit 0;
else
    exit 4;
fi

