#!/bin/sh
#
# Startup script for local custom services

case $1 in
    start)
        if [ -z "`pgrep -f blueproximity.sh`" ] ; then
          echo "Starting blueproximity.sh"
          nice sh /opt/btproximity/blueproximity.sh >/dev/null 2>&1 &
# An example how to run script under a dedicated user (slightly more secure)
# - don't forget to set access rights correctly
# - user must have valid shell in /etc/passwd
#          su btuser -c "exec nice sh ~pavel/btproximity/blueproximity.sh" >/dev/null 2>&1 &
        fi
    ;;
    stop)
        pid=`pgrep -f blueproximity.sh`
        if [ -n "$pid" ] ; then
          echo "Stopping blueproximity.sh"
          kill $pid
          killall hcitool 2>/dev/null
        fi
    ;;
    restart)
        $0 stop
        sleep 1
        $0 start
    ;;
    *)
        echo "usage: $0 (start|stop|restart)"
        exit 1
    ;;
esac
