#!/bin/sh
PIDUDPE_PLUGIN="/var/run/usbhosts.pid"
UDPE_PLUGIN="/bin/pcb_plugin -vvvvv -n usbhosts -c /usr/lib/usb/usbhosts.odl"

start() {
    if ! mount | grep -q usbfs; then
        mount -t usbfs none /proc/bus/usb
    fi

    if [ -e ${PIDUDPE_PLUGIN} ]; then
        echo "usbhosts plug-in already started"
    else
        echo "Starting usbhosts plug-in"
        ${UDPE_PLUGIN};
    fi
}

stop() {
    if [ -e ${PIDUDPE_PLUGIN} ]; then
        echo "Stopping sbhosts plug-in"
        kill $(cat ${PIDUDPE_PLUGIN});
    else
        echo "usbhosts plug-in already stopped"
    fi
}

restart() {
    stop
    while test -e ${PIDUDPE_PLUGIN}; do
        sleep 1
    done
    start
}

case $1 in
    start)
        start
	;;
    stop)
        stop
	;;
    restart)
        restart
        ;;
    *)
        ;;
esac

