#!/bin/bash
. ~/.configured
ATTEMPT=0

function try_smolt {
        ((ATTEMPT=ATTEMPT+1))
        WID=`xdotool search "mythfrontend" | head -1`
        xdotool windowfocus $WID
        status=$?
        if [ $status = 0 ]
        then
                sleep 2
                xdotool key "ctrl+alt+p"
                xdotool key "ctrl+alt+p"
                fb_status=0
                echo "FB=NO" > ~/.configured
        fi

        if [ $ATTEMPT = 200 ]
        then
                fb_status=0
        fi

}


if [ ! -e /tmp/debug ]
then
	if [ ! -e /tmp/nomfe ]
	then
		if [ ! -e ~/.mythtv/pub-uuid ]
		then
			if [ x$FB != xNO ]
			then
				fb_status=4
				while [ $fb_status != 0 ]
				do
					try_smolt
					if [ $fb_status != 0  ]
					then
						sleep 1
					fi
				done
			fi
		fi
	fi
fi