#!/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 1 secondes ($loop)"
            sleep 1
        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/usbdect_apig start voip_reload_device
		;;
	remove)
		echo "Stopping USB Dect..."
		wait_rc
		/usr/etc/init.d/usbdect_apig stop voip_reload_device
		;;
esac	
