#!/usr/bin/sh

#*********************************************************************************************************
#*   __     __               __     ______                __   __                      _______ _______   *
#*  |  |--.|  |.---.-..----.|  |--.|   __ \.---.-..-----.|  |_|  |--..-----..----.    |       |     __|  *
#*  |  _  ||  ||  _  ||  __||    < |    __/|  _  ||     ||   _|     ||  -__||   _|    |   -   |__     |  *
#*  |_____||__||___._||____||__|__||___|   |___._||__|__||____|__|__||_____||__|      |_______|_______|  *
#* http://www.blackpantheros.eu | http://www.blackpanther.hu - kbarcza[]blackpanther.hu * Charles Barcza *
#*************************************************************************************(c)2002-2019********
##   blackPanther Default Apps Collection
base=$(basename $0)
. /etc/blackPanther-default-apps.conf

PID=$(pidof dotnet 2>/dev/null)

if [ ! -f $HOME/.AgentDVR/.installed ];then
    exec /usr/bin/agentdvr-server &
    echo "First run! Preparing...."
    bubblemsg "AgentDVR Server" "First run! Preparing.. please Wait!"
    sleep 10
fi

if [ ! -n "$PID" ];then
    echo "Not running server! Try start now...."
    bubblemsg "AgentDVR Server" "Not running! Start from client now..."
    until pids=$(pidof dotnet)
    do   
	echo "Wait for $PID 5sec"
	systemctl --user start agentdvr
        #exec /usr/bin/agentdvr-server &
        bubblemsg "AgentDVR Wait" "Wait to server is started..."
	sleep 5
    done
	sleep 1
fi

/usr/lib64/agentdvr-viewer/AgentDVR

