#!/bin/sh
export SDL_NOMOUSE=1
export HOME=/usr/local/home

clear

if [ ! -d /usr/local/dmenu ] #Dmenu not found, run DinguXMB
then
	echo "LOADING  DINGUXMB. . ."
	cd /usr/local/dinguxmb
	if [ -f ./dinguxmb.sh ]
	then
		./dinguxmb.sh
	else
		if [ -f ./dinguxmb.dge ]
		then
			./dinguxmb.dge
		else
			if [ -f ./dinguxmb ]
			then
				./dinguxmb
			else
				echo "DinguXMB executable not found!"
			fi
		fi
	fi
	sync #hopefully works around corruption problem a bit
else
	if [ ! -d /usr/local/dinguxmb ] #Dinguxmb not found, run Dmenu
	then
		echo "LOADING  DMENU. . ."
		cd /usr/local/dmenu
		if [ -f ./dmenu.sh ]
		then
			./dmenu.sh
		else
			if [ -f ./dmenu.dge ]
			then
				./dmenu.dge
			else
				if [ -f ./dmenu ]
				then
					./dmenu
				else
					echo "DMenu executable not found!"
				fi
			fi
		fi
	sync #hopefully works around corruption problem a bit
	else					# both DMenu and DinguXMB found, present frontend select:
		echo ""
		echo ""
		echo ""

		echo -e "\033[0;5;31;47m    #########   ###########  ####    ###   \033[0;1;31;40m  ########   ###    ###  ###    ###  "
		echo -e "\033[0;5;31;47m    ###    ###      ###      #####   ###   \033[0;1;31;40m ###    ###  ###    ###  ###    ###  "
		echo -e "\033[0;5;31;47m    ###    ###      ###      ######  ###   \033[0;1;31;40m ###         ###    ###   ###  ###   "
		echo -e "\033[0;5;31;47m    ###    ###      ###      ### ### ###   \033[0;1;31;40m ###         ###    ###    ######    "
		echo -e "\033[0;5;31;47m    ###    ###      ###      ###  ######   \033[0;1;31;40m ###   ####  ###    ###   ###  ###   "
		echo -e "\033[0;5;31;47m    ###    ###      ###      ###   #####   \033[0;1;31;40m ###    ###  ###    ###  ###    ###  "
		echo -e "\033[0;5;31;47m    #########   ###########  ###    ####   \033[0;1;31;40m  ########    ########   ###    ###  "
		echo -e "\033[0;5;32;47m           .-,--'            .            .\033[0;1;32;40m   .---.     .          .            "
		echo -e "\033[0;5;32;47m            \|__ ,-. ,-. ,-. |- ,-. ,-. ,-|\033[0;1;32;40m   \___  ,-. |  ,-. ,-. |-           "
		echo -e "\033[0;5;32;47m             |   |   | | | | |  |-' | | | |\033[0;1;32;40m       \ |-' |  |-' |   |            "
		echo -e "\033[0;5;32;47m            \`'   '   \`-' ' ' \`' \`-' ' ' \`-^\033[0;1;32;40m   \`---' \`-' \`' \`-' \`-' \`'           "
		echo -e "\033[0;5;32;47m___________________________________________\033[0;1;32;40m_____________________________________\033[0m"

		echo -e "\033[0;5;30;47m  ___  _                 __  ____  __ ___  \033[0;1;40;37m     ___                             "
		echo -e "\033[0;5;30;47m |   \(_)_ _  __ _ _  _  \ \/ /  \/  | _ ) \033[0;1;40;37m    |   \  _ __   ___  _ _  _  _     "
		echo -e "\033[0;5;30;47m | |) | | ' \/ _\` | || |  >  <| |\/| | _ \ \033[0;1;40;37m    | |) || '  \ / -_)| ' \| || |    "
		echo -e "\033[0;5;30;47m |___/|_|_||_\__, |\_,_| /_/\_\_|  |_|___/ \033[0;1;40;37m    |___/ |_|_|_|\___||_||_|\_,_|    "
		echo -e "\033[0;5;30;47m             |___/                         \033[0;1;40;37m                                     "

		echo -e "\033[0;5;30;47m___________________________________________\033[0;1;40;37m_____________________________________"
		echo -e "\033[0;5;30;47m                                           \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m        \033[0;5;30;44m                          \033[0;5;30;47m         \033[0;1;40;37m     \033[0;5;30;44m                            \033[0;1;40;37m    "
		echo -e "\033[0;5;30;47m        \033[0;5;30;44m  ___     ___  ____ ___   \033[0;5;30;47m         \033[0;1;40;37m     \033[0;5;30;44m   ____ ___ ____ ____ ___   \033[0;1;40;37m    "
		echo -e "\033[0;5;30;47m        \033[0;5;30;44m  |  \ __ |__] |__| |  \  \033[0;5;30;47m         \033[0;1;40;37m     \033[0;5;30;44m   [__   |  |__| |__/  |    \033[0;1;40;37m    "
		echo -e "\033[0;5;30;47m        \033[0;5;30;44m  |__/    |    |  | |__/  \033[0;5;30;47m         \033[0;1;40;37m     \033[0;5;30;44m   ___]  |  |  | |  \  |    \033[0;1;40;37m    "
		echo -e "\033[0;5;30;47m        \033[0;5;30;44m                          \033[0;5;30;47m         \033[0;1;40;37m     \033[0;5;30;44m                            \033[0;1;40;37m    "
		echo -e "\033[0;5;30;47m        \033[0;5;30;44m                          \033[0;5;30;47m         \033[0;1;40;37m     \033[0;5;30;44m                            \033[0;1;40;37m    "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                \033[0;5;30;44m          \033[0;5;30;47m                 \033[0;1;40;37m                                     "
		echo -e "\033[0;5;30;47m                                           \033[0;1;40;37m                                     "
		echo -e "\033[0;1;32mPRESS D-PAD BEFORE START TO LOAD DINGU XMB   \033[0;1;31mOR\033[0;1;32m   JUST PRESS START TO LOAD DMENU\033[0m"

		read action 				# <----Get user input.
		clear

		while [ 1 = 1 ]
		do
			if [ "$action" = "[A" -o "$action" = "[B" -o "$action" = "[D" -o "$action" = "[C" ]	# D-Pad UP, DOWN, LEFT, RIGHT
			then
				echo "LOADING  DINGUXMB. . ."
				cd /usr/local/dinguxmb
				if [ -f ./dinguxmb.sh ]
				then
					./dinguxmb.sh
				else
					if [ -f ./dinguxmb.dge ]
					then
						./dinguxmb.dge
					else
						if [ -f ./dinguxmb]
						then
							./dinguxmb
						else
							echo "DinguXMB executable not found!"
						fi
					fi
				fi
			else
				echo "LOADING  DMENU. . ."
				cd /usr/local/dmenu
				if [ -f ./dmenu.sh ]
				then
					./dmenu.sh
				else
					if [ -f ./dmenu.dge ]
					then
						./dmenu.dge
					else
						if [ -f ./dmenu]
						then
							./dmenu
						else
							echo "DMenu executable not found!"
						fi
					fi
				fi
			fi
			sync #hopefully works around corruption problem a bit
		done
	fi
fi
exit
