#!/bin/bash
printer="<Printer ColorLaserJet2>
    UUID urn:uuid:4dbda407-b81f-35e4-5555-815c59503cfd
    Info ColorLaserJet2
    Location 2nd Floor
    DeviceURI ipp://gamow.tecnico.ulisboa.pt:631/printers/ColorLaserJet2
    State Idle
    StateTime 1372216899
    Type 6
    Accepting Yes
    Shared No
    JobSheets none none
    QuotaPeriod 0
    PageLimit 0
    KLimit 0
    OpPolicy default
    ErrorPolicy retry-job
</Printer>"

if [ ! `whoami` == "root" ]; then
  echo "Please run this as root";
  exit 1;
fi

echo "Stoping CUPS service"
service cups stop
if [ ! $? == 0 ]; then
  echo "Failed to stop CUPS, service not running"
fi

echo "Configuring printer: ColorLaserJet2"
echo "$printer" >> /etc/cups/printers.conf

echo "Starting CUPS service"
service cups start