#!/bin/sh
# USB Dect dongle hotplug
#
# TODO: add voip action

wait_rc()
{
    loop=0
    while [ $loop -lt 120 ]; do
        loop=$(($loop+1))
        if [ ! -f /var/run/rc.pid ]; then
            break
        else
            echo "rc script is not finished... Waiting 15 seconds ($loop)"
            sleep 15
        fi
    done
    if [ -f /var/run/rc.pid ]; then
        echo "rc script is not finished after 2 minutes... Stop Waiting"
    fi
}

export PATH=/bin:/sbin:/usr/bin:/usr/sbin
export LD_LIBRARY_PATH=/lib:/usr/lib

case $ACTION in
	add)
		echo "Starting USB Dect"
		wait_rc
		/usr/etc/init.d/mdg start
		/usr/etc/init.d/voip reload_device
		;;
	remove)
		echo "USB Dect dongle removed"
		wait_rc
		/usr/etc/init.d/mdg stop
		;;
esac	
