#!/bin/sh

#
#PURPOSE: This is going to be used to set the settings of the printer
#Author: Katerina Tsarouchas  January 6, 2000
#

Magic_Filter="/etc/magicfilter"

#PURPOSE: To display all the infomration in /usr/lib/rhs/rhs-printfilters/postscript.cfg.in
Red_Hat()
{
   echo " "
   sed -e 's/^.*#.*//'  < $RedHat_Print 
   rm -f /tmp/red_hat
}

#PURPOSE: To display the Resolution and the Device of the printer
Magicfilter()
{
   echo " "
   grep -h "004\%\!" $printer_path > /tmp/res_tmp
   grep -h "\-r" /tmp/res_tmp > /tmp/foo
   if [ -s /tmp/foo ]
   then
     sed -e 's/^.*\-r//' < /tmp/foo > /tmp/boo
     cut -d" " -f1 /tmp/boo > /tmp/resolution
     sed 's/^.*DEVICE=//' < /tmp/boo > /tmp/temp
     cut -d" " -f1 /tmp/temp > /tmp/device
     DEVICE=`cat /tmp/device`
     RESOLUTION=`cat /tmp/resolution`
     echo " "
     echo "Resolution=$RESOLUTION"
     echo "Device=$DEVICE"
     echo " "
   else
     echo " "
     echo "No resolution or device is found in $printer_name"
     echo " "
   fi
   rm -f /tmp/foo /tmp/resolution /tmp/boo /tmp/device /tmp/res_tmp /tmp/temp
}

############################ Main ########################################

if [ $# = 2 ]
then
  printer_name=$1
  printer_path=$2 
  RedHat_Print="/var/spool/lpd/$printer_name/postscript.cfg" 
 
  if [ -f $RedHat_Print ]
  then
    Red_Hat
  else
    Magicfilter
  fi
else
  echo "USAGE: ./print_config <filename>"
fi  
