#!/bin/sh
#This shell for printer Hotplug .
#Author Zero 06-05-31
echo "Begin hotplug shell">/tmp/logForPrinter

PATH=/sbin:/bin:/usr/sbin:/usr/bin
log=/tmp/logForPrinter
PrinterName=""
Product=""
PPD=""
cd /sys/bus/usb/drivers/usblp
sleep 5
tempDir=$(ls -l | grep "device" | awk '{print $11}')
cd $tempDir
echo "tempDir=$tempDir" >> $log
cd ..
PrinterInfoDir=$(pwd)
echo "PrinterInfoDir=$PrinterInfoDir" >> $log
PrinterFactory=$(cat manufacturer)
PrinterName=$PrinterFactory
#For UI read the Manufacture
touch /tmp/Manufacture 
echo "$PrinterFactory" > /tmp/Manufacture

echo "$(cat manufacturer)" >> $log
echo "PrinterFactory=$PrinterFactory" >> $log
Product=$(cat product)

#For UI read the Model
touch /tmp/Model
echo "$Product" > /tmp/Model
echo "Product=$Product" >> $log
	echo "PrinterName=$PrinterName" >> $log

DriverURI=$(lpinfo -v | grep "direct usb" | sed -e 's;direct ;;g')

#To set the destnation for host pc ,if don't set the host can't print
lpadmin -d $PrinterName
#set the printer queue
lpadmin -p $PrinterName -E -v $DriverURI
#make the printer work
/etc/rc.d/S80cupsd.sh stop
/etc/rc.d/S80cupsd.sh start
echo "lpstat -p" >> $log
#For UI read the Status	
touch /tmp/Status
lpstat -p > /tmp/Status




