#!/bin/bash
killall -s9 driver_abbiati
cd /home/IGP/terminal/abbiati
./run.sh &
exit

. ./terminal.config

exit;
#za logiranje loaderja
CLIENT_MAC=`cat /sys/class/net/e*/address|head -n 1`

#ni potrebno v 18-ki
#$HOME_DIR/manage_unity_plugin.sh hide

#map touchscreen to apropriate monitor
#xinput map-to-output $TOUCH_DEVICE_ID $OUTPUT_NAME
#killall touch_bind_to_monitor.sh
#nohup $HOME_DIR/touch_bind_to_monitor.sh &
#sleep 2	

#transform touchscreen coordinates
#correct touch orientation - not needed for most touchscreens.., still some need correction, enable this line if necessary
#$HOME_DIR/touch_transform.sh 


#izkjlucimo tipkovnico USB
#killall keyboard_disable_after_unplug.sh
#nohup $HOME_DIR/keyboard_disable_after_unplug.sh &

#binary name, ki ga bomo zagnali
export BIN_FILENAME=/$HOME_DIR/rouletteloader

#debug
#export DISABLE_REBOOT_ON_EXIT=1

#nastavitev x serverja in virtual terminal Ctrl+Alt+Fn
export X_DISPLAY=:0
export VIRTUAL_TERMINAL=vt5

#preverimo ali je ruleta aktivirana
#if  [ -z `cat $HOME_DIR/flavor_prefix` ]; then
#	echo ""
#	echo "Roulette has not been activated yet."
#	echo "Please complete the steps in 'POPE->Activate New Roulette' widzard."
#	exit 0;
#fi

# board hardware identification
export CPU_VENDOR_ID=`cat /proc/cpuinfo | grep "vendor_id" |head -1| cut -c 13-26`
export CPU_FAMILY="F"`cat /proc/cpuinfo | grep "cpu family" |head -1| cut -c 14-16`
export CPU_MODEL="M"`cat /proc/cpuinfo | grep -P "model\t" |head -1| cut -c 10-12`
export CPU_STEPPING="S"`cat /proc/cpuinfo | grep -P "stepping\t" |head -1| cut -c 12-14`
[ "AuthenticAMD_F22_M0_S1" == ""$CPU_VENDOR_ID"_"$CPU_FAMILY"_"$CPU_MODEL"_"$CPU_STEPPING ] && export AUDIODEV=hw:1,0 && echo "RUNAPP.SH: This is mainboard KINO_KBN_i2"

#logfile
declare -x LOG_FILENAME=$OLD_GAMES_DIR/"LOADER_"$CLIENT_MAC".log"
export 1>/dev/null 2>/dev/null

#zazenemo binary
echo "RUNAPP.SH: Loading libraries from $LD_LIBRARY_PATH"
ps -A|grep -e unity -e gdm &>/dev/null
if [ $? -ne 0  ]; then
#zagon na diskless terminalih
    echo "RUNAPP.SH: No X server at \$DISPLAY [$DISPLAY], starting with xinit" >&2
    xinit $BIN_FILENAME -- $X_DISPLAY $VIRTUAL_TERMINAL 2>/dev/null
    echo ""
    chvt 6 ##gremo v VT6, kjer se zacenja nalaganje koncnega programa
else
#zagon lokalno, na masterju
#    echo "select RES_NUM_VALUE,RES_STR_VALUE from GET_PARAM('ROULETTE', 'LICENSED_TO', 11)" | $HOME_DIR/../sqlexec.sh | grep "UNREGISTRED"  2>&1 1>/dev/null
#    if [ $? -ne 0 ]; then
#        echo Activated, hiding unity plugin
#	ACTIVATED=1
        echo "RUNAPP.SH: X server running at \$DISPLAY [$DISPLAY]" >&2
        $BIN_FILENAME &
	PID1=$!
#    else
#        echo Not Activated, running Pope with activation
#	ACTIVATED=0
#    je vse to ze v init_roulette.sh
#	nohup /home/ROULETTE/popeinit.sh -activate -fullscreen &
#    fi

    sleep 3
    if [ `xrandr --query|grep +0|wc -l` -ge 2 ]; then
       wmctrl -r "Roulette Loader" -e 0,0,1080,-1,-1 & #uncomment for Loader Screen on BOTTOM MONITOR - should be on same monitor as PlayerBoard, check file RUN_LADY_SLOT.sh
    else
       wmctrl -r "Roulette Loader" -e 0,0,0,-1,-1 & #uncomment for Loader Screen on UPPER MONITOR - should be on same monitor as PlayerBoard, check file RUN_LADY_SLOT.sh
    fi
    wmctrl -r "Roulette Loader" -b add,fullscreen &

 #   wait $PID1
 #   if [ $ACTIVATED -ne 1 ]; then
 #       $HOME_DIR/manage_unity_plugin.sh show
 #   fi
fi


exit 0;
