#!/bin/sh


PARM=$1
PARM2=$2


case $PARM2 in
    dell) OEM="Dell"
          ;;
       *) OEM="Lexmark"
          ;;
esac



listDevices(){

    lst=""
    if [ -f /usr/local/lexmark/legacy/bin/.scripts/findby_usblp.sh ]; then
        lst=`/usr/local/lexmark/legacy/bin/.scripts/findby_usblp.sh wsu| sed 's/\ /\//g' | grep ${OEM}`
    elif [ -f /usr/local/lexmark/wsu_legacy/bin/.scripts/findby_usblp.sh ]; then
        lst=`/usr/local/lexmark/wsu_legacy/bin/.scripts/findby_usblp.sh wsu| sed 's/\ /\//g' | grep ${OEM}`
    fi
    for i in $lst 
    do
	num=`echo $i | awk -F\; '{print $1}'`
        model=`echo $i | awk -F\; '{print $2}' | sed 's/\// /g' | sed 's/MANUFACTURER:Lexmark International //g'`
        echo "${model}&&:&&/dev/usb/lp${num}"
    done

}


countDevices(){
num=0
    if [ -f /usr/local/lexmark/legacy/bin/.scripts/findby_usblp.sh ]; then
        num=`/usr/local/lexmark/legacy/bin/.scripts/findby_usblp.sh wsu| grep ${OEM} | wc -l`
        echo $num
    elif [ -f /usr/local/lexmark/wsu_legacy/bin/.scripts/findby_usblp.sh ]; then
        num=`/usr/local/lexmark/wsu_legacy/bin/.scripts/findby_usblp.sh wsu| grep ${OEM} | wc -l`
        echo $num 
    fi

}



case $PARM in

    -c) countDevices
        ;;
     *) listDevices
        ;;

esac







