#!/bin/sh

#*********************************************************************************************************
#*   __     __               __     ______                __   __                      _______ _______   *
#*  |  |--.|  |.---.-..----.|  |--.|   __ \.---.-..-----.|  |_|  |--..-----..----.    |       |     __|  *
#*  |  _  ||  ||  _  ||  __||    < |    __/|  _  ||     ||   _|     ||  -__||   _|    |   -   |__     |  *
#*  |_____||__||___._||____||__|__||___|   |___._||__|__||____|__|__||_____||__|      |_______|_______|  *
#* http://www.blackpantheros.eu | http://www.blackpanther.hu - kbarcza[]blackpanther.hu * Charles Barcza *
#*************************************************************************************(c)2002-2017********


showmsg() {
if [ -n "$DISPLAY" ];then
    if [ -x /usr/bin/bubbled ];then 
	bubblemsg other "$1 $2"
     elif [ -x /usr/bin/notify-send ];then
	notify-send -t 12000 -u normal -i natpos "$1" "$2"
    fi
 else
 	$ECHO $E "$1" "$2"
	$ECHO ""
fi
}

run() {
    dump1090 --quiet --net --net-ro-size 500 --net-ro-rate 5 --net-buffer 5 --write-json /usr/share/dump1090/data &
    sleep 2
}

if [ ! -n "$(pidof dump1090 2>/dev/null)" ];then
    run
    [ ! -n "$(pidof dump1090 2>/dev/null)" ] && showmsg "VirtualRadar Daemon" "Can't started! Check dump1090 error messages." && exit
else
    showmsg "VirtualRadar Daemon" "Already running..."
fi

default-browser http://127.0.0.1/virtualradar
