#!/bin/bash

. /usr/local/lib/labtool.shlib
trap on_exit EXIT

#DEBUG=true
QUEUE=remote-test
STATION_NUM="$(hostname -s | grep -o "[0-9]*")"
QUEUE_URL="http://instructor.example.com/printers/printer${STATION_NUM}"
TEMP_FILE="$(mktemp)"



check_root

check_host "server"

echo -n "* Checking for local print queue... "

if lpstat -a | grep -q remote-test
then
    echo "PASS"
else
    echo "FAIL"
    echo "Local print queue not found."
fi


echo -n "* Checking local print queue destination... "

if lp -d remote-test /etc/passwd &>/dev/null

then
    debug "* Print job submitted."

else
    exit 2
    
fi


if wget -q -O $TEMP_FILE $QUEUE_URL
    then
        # Get rid of CRLF
	    sed -i 's/..$//' $TEMP_FILE
        if diff /etc/passwd $TEMP_FILE &>/dev/null
            
        then
            echo "PASS"
        else
            echo "FAIL"
        fi  
    else
        echo "FAIL"
fi

exit
