#!/bin/bash
if [ `id -u` -ne 0 ];then
	sudo $0 $*
	exit
fi
NAME=BIRCH--BP003
PORT=serial:/dev/ttyS0?baud=9600
FILTER_PATH=/usr/lib/cups/filter
PPD_NAME=bp003.ppd
[ $# -ge 1 ] && NAME=$1
[ $# -ge 2 ] && PORT=$2
echo Prepare to install $NAME...
if [ -f $FILTER_PATH/rastertoesccmd ];then
	echo The filter exists.
else
	echo Copy Filter...
	cp -f rastertoesccmd $FILTER_PATH
	[ $? ] && chmod 755 $FILTER_PATH/rastertoesccmd
fi
WANT_INST=yes
lpstat -p $NAME &>/dev/null && WANT_INST=no
if [ $WANT_INST == yes ];then
	echo Install PPD...
	lpadmin -p $NAME -P $PPD_NAME -v $PORT -E
	[ $? ] && lpadmin -d $NAME
	[ $? ] && echo $NAME is connected to $PORT
else
	echo The printer driver exists.
fi
echo Finished!
echo You can browse 'http://localhost:631' and manage it!
