#!/bin/sh
#                             ***Project Carousel USB Anniversary Edition***
#                                             by Spannernick
#                                       PCUAE idea by Spannernick,
#                                    For THEC64 Mini/THEC64,THEVIC20,
#                                            and THEA500 Mini,
#                                  This is free for non commercial use,
#                                               NOT to SELL.
#---------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------
#                                     PCUAE Boot Scrpit v1.5 by Spanner
#---------------------------------------------------------------------------------------------------------------------
#                                      DO NOT Edit or change this code.
#---------------------------------------------------------------------------------------------------------------------
#=================================
# THEC64 and THEA500 Code Togther
#=================================
case "$1" in
start)

exec > /dev/ttyS0
exec 2>&1
mount -o remount,rw /
killall SZZpcuboot
rm -f /etc/init.d/SZZpcuboot
sync
rm -f /etc/init.d/SZZpcuboot
sync
pcuaevers="5.1.1"
if [ -e /usr/share/amiberry/kickstarts ]
then
	# For THEA500, only if its different from THEC64
	clear
	echo " "
	echo " Starting THEA500 PCUAE Autoboot Mode Start-Up Script"
	echo " "
	echo " "
	echo " Project Carousel USB: Anniverasery Edition"
	echo "  ____  ____  _   _  _____  ____"
	echo " | _  ||  __|| | | ||  _  || ___|"
	echo " |  __|| |   | | | || |_| |||___ "
	echo " | |   | |__ | |_| || | | |||___"
	echo " |_|   |____||_____||_| |_||____|"
	echo "                           2020"
	echo " By Spannernick"
	echo " "
	sleep 1
	echo " For THEA500 Mini... "
	echo " "
	sleep 1
	killall S99skyline
	killall skyline
	killall manhattan
	/etc/init.d/S99skyline stop
	killall -9 S99skyline
	mount --bind /dev/null /etc/init.d/S99skyline
	echo " Checking USB Drive now..."
	echo " Please Wait 5 seconds to make sure the system sees it."
	# Need to make it wait for it to see the USB Drive
	killall manhattan
	killall manhattan
	sleep 5
	killall manhattan
	killall manhattan
	if [ -e /mnt ]
	then 
		echo " "
		echo " Checked USB Drive, yes its there, all OK...."
	fi
	
elif [ -e /usr/bin/colleen ]
then
    if [ ! -e /usr/bin/thespeccy ]
	then
		# For THE400, only if its different from THEA500, THEC64
		clear
		echo " "
		echo " Starting THE400 PCUAE Autoboot Mode Start-Up Script"
		echo " "
		echo " "
		echo " Project Carousel USB: Anniverasery Edition"
		echo "  ____  ____  _   _  _____  ____"
		echo " | _  ||  __|| | | ||  _  || ___|"
		echo " |  __|| |   | | | || |_| |||___ "
		echo " | |   | |__ | |_| || | | |||___"
		echo " |_|   |____||_____||_| |_||____|"
		echo "                           2020"
		echo " By Spannernick"
		echo " "
		sleep 1
		echo " For THE400 Mini... "
		echo " "
		sleep 1
		killall S99skyline
		killall skyline
		killall manhattan
		/etc/init.d/S99skyline stop
		killall -9 S99skyline
		mount --bind /dev/null /etc/init.d/S99skyline
		echo " Checking USB Drive now..."
		echo " Please Wait 5 seconds to make sure the system sees it."
		# Need to make it wait for it to see the USB Drive
		killall manhattan
		killall manhattan
		sleep 5
		killall manhattan
		killall manhattan
		if [ -e /mnt ]
		then 
			echo " "
			echo " Checked USB Drive, yes its there, all OK...."
		fi
	else
		# For THESpectrum, only if its different from THEA500, THEC64
		clear
		echo " "
		echo " Starting THESpectrum PCUAE Autoboot Mode Start-Up Script"
		echo " "
		echo " "
		echo " Project Carousel USB: Anniverasery Edition"
		echo "  ____  ____  _   _  _____  ____"
		echo " | _  ||  __|| | | ||  _  || ___|"
		echo " |  __|| |   | | | || |_| |||___ "
		echo " | |   | |__ | |_| || | | |||___"
		echo " |_|   |____||_____||_| |_||____|"
		echo "                           2020"
		echo " By Spannernick"
		echo " "
		sleep 1
		echo " For THESpectrum... "
		echo " "
		sleep 1
		killall S99skyline
		killall skyline
		killall manhattan
		/etc/init.d/S99skyline stop
		killall -9 S99skyline
		mount --bind /dev/null /etc/init.d/S99skyline
		echo " Checking USB Drive now..."
		echo " Please Wait 5 seconds to make sure the system sees it."
		# Need to make it wait for it to see the USB Drive
		killall manhattan
		killall manhattan
		sleep 5
		killall manhattan
		killall manhattan
		if [ -e /mnt ]
		then 
			echo " "
			echo " Checked USB Drive, yes its there, all OK...."
		fi
	fi
else
	# THEC64 code, only if its different from THEA500, THE400
	clear
	echo " "
	echo " Starting THEC64 PCUAE Autoboot Mode Start-Up Script"
	echo " "
	echo " "
	echo " Project Carousel USB: Anniverasery Edition"
	echo "  ____  ____  _   _  _____  ____"
	echo " | _  ||  __|| | | ||  _  || ___|"
	echo " |  __|| |   | | | || |_| |||___ "
	echo " | |   | |__ | |_| || | | |||___"
	echo " |_|   |____||_____||_| |_||____|"
	echo "                           2020"
	echo " By Spannernick"
	echo " "
	sleep 1
	echo " For THEC64/VIC20... "
	echo " "
	sleep 1
	killall S99redquark
	/etc/init.d/S99redquark stop
	killall -9 S99redquark
	mount --bind /dev/null /etc/init.d/S99redquark
	echo " Checking USB Drive now..."
	echo " Please Wait 5 seconds to make sure the system sees it."
	# Need to make it wait for it to see the USB Drive
	killall the64
	killall the64
	sleep 5
	killall the64
	killall the64
	if [ -e /mnt ]
	then 
		echo " "
		echo " Checked USB Drive, yes its there, all OK...."
	fi
fi
echo " "
echo " All OK... Firmware startup boot script blocked."
echo " "
echo " Checking for PCUAE USB Drive "
if [ -e /dev/sda1 ]
then
	echo " YES..."
	echo " OK, PCUAE is there, PCUAE USB Drive is pluged in."
	echo " dev/sda1 Avaliable"

	mount -o remount,rw /
	if [ ! -e /mnt2 ]
	then
		mkdir /mnt2
	fi
	mount /dev/sda1 /mnt2
	mount -o remount,rw /mnt2
	
elif [ -e /tmp/usbdrive/sda1 ]
then
	echo " YES..."
	echo " OK, PCUAE is there, PCUAE USB Drive is pluged in."
	echo " usbdrive/sda1 Avaliable"

	mount -o remount,rw /
	if [ ! -e /mnt2 ]
	then
		mkdir /mnt2
	fi
	mount /tmp/usbdrive/sda1 /mnt2
	mount -o remount,rw /mnt2
else
	 echo " OK...PCUAE USB Drive not pluged in to USB port."
fi
# ***IMPORTANT - THIS IS NOT USED BY YOU ***
# A Back Door in to PCUAE if there is a problem with this script and it don't load properly, 
# so I can get back in, if the carousel does not load up, and if I made a mistake in this script
# so I can edit it and correct it and then get it to copy it to the firmware again.
# Back Door is connected to the start.sh script on root.
if [ -e /mnt2/.options/boot/backdoor-open ]
then
	echo " Back Door is Open... :)"
	echo " OK... Booting from Back Door Script Only NOW."
	/mnt2/start.sh
else
	echo " Back Door is Closed... :)"
	echo " OK... Booting from PCUAE Autoboot Mode Startup Script Only."
fi
if [ -e /mnt2/.pcuaeselect ]
then
	echo " Checking Carousel/Mode Changer/boot scripts..."
	/mnt2/.options/boot/pcu_carousel_mode_changer1.sh
fi
if [ -e /usr/share/amiberry/kickstarts ]
then
	if [ -e /mnt2/.options/pcuae_option_flag_files/boot_the500_enabled ]
	then	
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..." 
			echo " " 
			echo " Starting PCUAE for THEA500 Flashing NAND"
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE THEA500 on $pcuaevers ..." 
			echo " " 
			echo " Starting PCUAE for THEA500..."
			/mnt2/.options/boot/autobootfirmware_ch.sh	
		fi
	else
		if [ -e /mnt2/.options/boot/autobootfirmware_ch.sh ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo "  No...Restore Toolkit v2.2 is Not Activated..."		
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE THEA500 on Version $pcuaevers ..." 
			echo " " 
			echo " Starting PCUAE for THE500..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		else
			# If there's no USB drive available quit immediately
			if [ ! -e /dev/sda1 ]
			then
				echo " NO..."
				echo " USB Drive is not plugged in"
				echo " Loading from the firmware now."
				if [ -e /usr/share/amiberry/kickstarts ]
				then
				    if [ -e /etc/amiberry_v1.0.0_enabled ]
					then
						mount -o remount,rw /
						echo " Mounting... Amiberry v3.3+ Redquark v1 v1.0.0 File now in the firmware."
						mount -o bind /usr/bin/ab /usr/bin/amiberry
						echo " Mounting... Manhattan v1 v1.0.0..."
						mount -o bind /usr/bin/ma /usr/bin/manhattan
						echo " Mounting... Resources v1 v1.0.0 in the Firmmware Now"
						mount -o bind /usr/bin/res /usr/share/manhattan/resources.bod
						
					elif [ -e /etc/amiberry_v1.1.1_enabled ]
					then
						mount -o remount,rw /
						echo " Mounting... Amiberry v3.3+ Redquark v1 v1.0.0 File now in the firmware."
						mount -o bind /usr/bin/ab1 /usr/bin/amiberry
						echo " Mounting... Manhattan v1 v1.0.0..."
						mount -o bind /usr/bin/ma1 /usr/bin/manhattan
						echo " Mounting... Resources v1 v1.0.0 in the Firmmware Now"
						mount -o bind /usr/bin/res1 /usr/share/manhattan/resources.bod
						
					elif [ -e /etc/amiberry_v1.2.1_enabled ]
					then
						mount -o remount,rw /
						echo " Mounting... Amiberry v3.3+ Redquark v1 v1.0.0 File now in the firmware."
						mount -o bind /usr/bin/ab2 /usr/bin/amiberry
						echo " Mounting... Manhattan v1 v1.0.0..."
						mount -o bind /usr/bin/ma2 /usr/bin/manhattan
						echo " Mounting... Resources v1 v1.0.0 in the Firmmware Now"
						mount -o bind /usr/bin/res2 /usr/share/manhattan/resources.bod
					else
					    echo " load defauld firmware..."
					fi
					echo " Starting THEA500 Carousel from the firmware."
					mount -o remount,ro /
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					killall -9 amiberry
					exit 0
				
				elif [ -e /usr/bin/colleen ]
				then
					mount -o remount,ro /
					echo " Starting THE400 Carousel from the firmware."
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					exit 0
				else
					mount -o remount,ro /
					echo " Starting THEC64/VIC20 Carousel from the firmware."
					umount /etc/init.d/S99redquark
					#/etc/init.d/S99redquark start
					killall the64
					killall the64
					exit 0
				fi
			
			elif [ ! -e /tmp/usbdrive/sda1 ]
			then
				echo " NO..."
				echo " USB Drive is not plugged in"
				echo " Loading from the firmware now."
				if [ -e /usr/share/amiberry/kickstarts ]
				then
				    if [ -e /etc/amiberry_v1.0.0_enabled ]
					then
						mount -o remount,rw /
						echo " Mounting... Amiberry v3.3+ Redquark v1 v1.0.0 File now in the firmware."
						mount -o bind /usr/bin/ab /usr/bin/amiberry
						echo " Mounting... Manhattan v1 v1.0.0..."
						mount -o bind /usr/bin/ma /usr/bin/manhattan
						echo " Mounting... Resources v1 v1.0.0 in the Firmmware Now"
						mount -o bind /usr/bin/res /usr/share/manhattan/resources.bod
						
					elif [ -e /etc/amiberry_v1.1.1_enabled ]
					then
						mount -o remount,rw /
						echo " Mounting... Amiberry v3.3+ Redquark v1 v1.0.0 File now in the firmware."
						mount -o bind /usr/bin/ab1 /usr/bin/amiberry
						echo " Mounting... Manhattan v1 v1.0.0..."
						mount -o bind /usr/bin/ma1 /usr/bin/manhattan
						echo " Mounting... Resources v1 v1.0.0 in the Firmmware Now"
						mount -o bind /usr/bin/res1 /usr/share/manhattan/resources.bod
						
					elif [ -e /etc/amiberry_v1.2.1_enabled ]
					then
						mount -o remount,rw /
						echo " Mounting... Amiberry v3.3+ Redquark v1 v1.0.0 File now in the firmware."
						mount -o bind /usr/bin/ab2 /usr/bin/amiberry
						echo " Mounting... Manhattan v1 v1.0.0..."
						mount -o bind /usr/bin/ma2 /usr/bin/manhattan
						echo " Mounting... Resources v1 v1.0.0 in the Firmmware Now"
						mount -o bind /usr/bin/res2 /usr/share/manhattan/resources.bod
					else
					    echo " load defauld firmware..."
					fi
					mount -o remount,ro /
					echo " Starting THEA500 Carousel from the firmware."
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					killall -9 amiberry
					exit 0
				
				elif [ -e /usr/bin/colleen ]
				then
				    mount -o remount,ro /
					echo " Starting THE400 Carousel from the firmware."
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					exit 0
				else
				    mount -o remount,ro /
					echo " Starting THEC64/VIC20 Carousel from the firmware."
					umount /etc/init.d/S99redquark
					#/etc/init.d/S99redquark start
					killall the64
					killall the64
					exit 0
				fi
			fi
		fi	
	fi
	
elif [ -e /usr/bin/the64 ]
then
	if [ -e /mnt2/.options/pcuae_option_flag_files/boot_thec64-mini-pal_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..." 
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models ..."
			echo " " 
			echo " Starting PCUAE for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi 
	elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thec64-mini-ntsc_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thec64_on_thevic20_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	
	elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thevic20_on_thec64_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_the400_on_thec64_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_the400_on_thevic20_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.1 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thespectrum_on_thevic20_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thespectrum_on_thec64_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thec64_pal_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh	
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thec64_ntsc_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thevic20_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models..."
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh	
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_the400_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..." 
			echo " " 
			echo " Starting PCUAE $pcuaevers for THE400..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.2 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE for THE400 Version $pcuaevers ..." 
			echo " " 
			echo " Starting PCUAE $pcuaevers for THE400..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thespectrum_enabled ]
	then
		if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " Yes...Restore Toolkit v2.2 is Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE Restore Toolkit v2.2..." 
			echo " " 
			echo " Starting PCUAE $pcuaevers for THESpectrum..."
			sleep 1
			/mnt2/.options/boot/pcuae-ch
		else
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " YES... PCUAE Autoboot Mode is Activated... :-)"
			echo " "
			echo " No...Restore Toolkit v2.1 is Not Activated..."
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE for THE400 Version $pcuaevers ..." 
			echo " " 
			echo " Starting PCUAE for THE400..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		fi
	else
		if [ -e /mnt2/.options/boot/autobootfirmware_ch.sh ]
		then
			echo "#----------------------------------------------------------#"
			echo " Looking for First boot at start up for setting up PCUAE..."
			echo "#----------------------------------------------------------#"
			echo " No...Restore Toolkit v2.2 is Not Activated..."	
			echo " Starting PCUAE Selector..." 
			echo " PCUAE Running..." 
			echo " "
			echo " Loading PCUAE $pcuaevers THEC64 Models Version $pcuaevers ..." 
			echo " " 
			echo " Starting PCUAE $pcuaevers for THEC64 Models..."
			/mnt2/.options/boot/autobootfirmware_ch.sh		
		else
			# If there's no USB drive available quit immediately
			if [ ! -e /dev/sda1 ]
			then
				echo " NO..."
				echo " USB Drive is not plugged in"
				echo " Loading from the firmware now."
				mount -o remount,ro /
				if [ -e /usr/share/amiberry/kickstarts ]
				then
					echo " Starting THEA500 Carousel from the firmware."
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					killall -9 amiberry
					exit 0
				
				elif [ -e /usr/bin/colleen ]
				then
					echo " Starting THE400 Carousel from the firmware."
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					exit 0
				else
					echo " Starting THEC64/VIC20 Carousel from the firmware."
					umount /etc/init.d/S99redquark
					#/etc/init.d/S99redquark start
					killall the64
					killall the64
					exit 0
				fi
			
			elif [ ! -e /tmp/usbdrive/sda1 ]
			then
				echo " NO..."
				echo " USB Drive is not plugged in"
				echo " Loading from the firmware now."
				mount -o remount,ro /
				if [ -e /usr/share/amiberry/kickstarts ]
				then
					echo " Starting THEA500 Carousel from the firmware."
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					killall -9 amiberry
					exit 0
				
				elif [ -e /usr/bin/colleen ]
				then
					echo " Starting THE400 Carousel from the firmware."
					umount /etc/init.d/S99skyline
					#/etc/init.d/S99skyline start
					killall skyline
					killall manhattan
					exit 0
				else
					echo " Starting THEC64/VIC20 Carousel from the firmware."
					umount /etc/init.d/S99redquark
					#/etc/init.d/S99redquark start
					killall the64
					killall the64
					exit 0
				fi
			fi
		fi
	fi

elif [ -e /usr/bin/colleen ]
then
    if [ ! -e /usr/bin/thespeccy ]
	then
		if [ -e /mnt2/.options/pcuae_option_flag_files/boot_thec64_on_the400_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..." 
				echo " " 
				echo " Starting PCUAE $pcuaevers for THE400..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THE400 Version $pcuaevers ..." 
				echo " " 
				echo " Starting PCUAE $pcuaevers for THE400..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi 
		
		elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thevic20_on_the400_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..." 
				echo " " 
				echo " Starting PCUAE $pcuaevers for THE400..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...THE400 On THEC64 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE for THE400 Version $pcuaevers ..." 
				echo " " 
				echo " Starting PCUAE for THE400..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thespectrum_on_the400_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..." 
				echo " " 
				echo " Starting PCUAE for THE400..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...THE400 On THEC64 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE for THE400 Version $pcuaevers ..." 
				echo " " 
				echo " Starting PCUAE for THE400..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_the400_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.1 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.1..." 
				echo " " 
				echo " Starting PCUAE for THE400..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.1 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE for THE400 Version $pcuaevers ..." 
				echo " " 
				echo " Starting PCUAE for THE400..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thec64_pal_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.1 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.1..."
				echo " " 
				echo " Starting PCUAE for THEC64 Models..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...THE400 On THEC64 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE THEC64 Models Version $pcuaevers ..."
				echo " " 
				echo " Starting PCUAE for THEC64 Models..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thec64_ntsc_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE for THEC64 Models..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...THE400 On THEC64 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THEC64 Models..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thevic20_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THEC64 Models Version $pcuaevers ..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thespectrum_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THEC64 Models Version $pcuaevers ..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		else
			if [ -e /mnt2/.options/boot/autobootfirmware_ch.sh ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THE400..." 
				echo " " 
				echo " Starting PCUAE $pcuaevers for THE400..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			else
				# If there's no USB drive available quit immediately
				if [ ! -e /dev/sda1 ]
				then
					echo " NO..."
					echo " USB Drive is not plugged in"
					echo " Loading from the firmware now."
					mount -o remount,ro /
					if [ -e /usr/share/amiberry/kickstarts ]
					then
						echo " Starting THEA500 Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						killall -9 amiberry
						exit 0
					
					elif [ -e /usr/bin/colleen ]
					then
						echo " Starting THE400 Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						exit 0
					else
						echo " Starting THEC64/VIC20 Carousel from the firmware."
						umount /etc/init.d/S99redquark
						#/etc/init.d/S99redquark start
						killall the64
						killall the64
						exit 0
					fi
				
				elif [ ! -e /tmp/usbdrive/sda1 ]
				then
					echo " NO..."
					echo " USB Drive is not plugged in"
					echo " Loading from the firmware now."
					mount -o remount,ro /
					if [ -e /usr/share/amiberry/kickstarts ]
					then
						echo " Starting THEA500 Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						killall -9 amiberry
						exit 0
					
					elif [ -e /usr/bin/colleen ]
					then
						echo " Starting THE400 Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						exit 0
					else
						echo " Starting THEC64/VIC20 Carousel from the firmware."
						umount /etc/init.d/S99redquark
						#/etc/init.d/S99redquark start
						killall the64
						killall the64
						exit 0
					fi
				fi
			fi
		fi
	else
	    if [ -e /mnt2/.options/pcuae_option_flag_files/restore_thespectrum_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.1 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THESpectrum Version $pcuaevers ..."
				echo " " 
				echo " Starting PCUAE $pcuaeversfor THESpectrum..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_the400_on_thespectrum_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.1 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THESpectrum..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thevic20_on_thespectrum_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THESpectrum..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/boot_thec64_on_thespectrum_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THESpectrum..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thec64_pal_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...THE400 On THEC64 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THEC64 Models Version $pcuaevers ..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thec64_ntsc_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...THE400 On THEC64 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE THEC64 Models Version $pcuaevers ..."
				echo " " 
				echo " Starting PCUAE for THEC64 Models..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_thevic20_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...THE400 On THEC64 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THEC64 Models..."
				echo " " 
				echo " Starting PCUAE $pcuaevers for THEC64 Models..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
		elif [ -e /mnt2/.options/pcuae_option_flag_files/restore_the400_enabled ]
		then
			if [ -e /mnt2/.options/mode_option_flag_files/boot_pcuae_enabled ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " Yes...Restore Toolkit v2.2 is Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE Restore Toolkit v2.2..." 
				echo " " 
				echo " Starting PCUAE $pcuaevers for THE400..."
				sleep 1
				/mnt2/.options/boot/pcuae-ch
			else
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " YES... PCUAE Autoboot Mode is Activated... :-)"
				echo " "
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers for THE400 Version $pcuaevers ..." 
				echo " " 
				echo " Starting PCUAE $pcuaevers for THE400..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			fi
	    else
			if [ -e /mnt2/.options/boot/autobootfirmware_ch.sh ]
			then
				echo "#----------------------------------------------------------#"
				echo " Looking for First boot at start up for setting up PCUAE..."
				echo "#----------------------------------------------------------#"
				echo " No...Restore Toolkit v2.2 is Not Activated..."
				echo " Starting PCUAE Selector..." 
				echo " PCUAE Running..." 
				echo " "
				echo " Loading PCUAE $pcuaevers THESpectrum Version $pcuaevers ..." 
				echo " " 
				echo " Starting PCUAE $pcuaevers for THESpectrum..."
				/mnt2/.options/boot/autobootfirmware_ch.sh		
			else
				# If there's no USB drive available quit immediately
				if [ ! -e /dev/sda1 ]
				then
					echo " NO..."
					echo " USB Drive is not plugged in"
					echo " Loading from the firmware now."
					mount -o remount,ro /
					if [ -e /usr/share/amiberry/kickstarts ]
					then
						echo " Starting THEA500 Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						killall -9 amiberry
						exit 0
					
					elif [ -e /usr/bin/colleen ]
					then
						echo " Starting THESpectrum Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						exit 0
					else
						echo " Starting THEC64/VIC20 Carousel from the firmware."
						umount /etc/init.d/S99redquark
						#/etc/init.d/S99redquark start
						killall the64
						killall the64
						exit 0
					fi
				
				elif [ ! -e /tmp/usbdrive/sda1 ]
				then
					echo " NO..."
					echo " USB Drive is not plugged in"
					echo " Loading from the firmware now."
					mount -o remount,ro /
					if [ -e /usr/share/amiberry/kickstarts ]
					then
						echo " Starting THEA500 Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						killall -9 amiberry
						exit 0
					
					elif [ -e /usr/bin/colleen ]
					then
						echo " Starting THESpectrum Carousel from the firmware."
						umount /etc/init.d/S99skyline
						#/etc/init.d/S99skyline start
						killall skyline
						killall manhattan
						exit 0
					else
						echo " Starting THEC64/VIC20 Carousel from the firmware."
						umount /etc/init.d/S99redquark
						#/etc/init.d/S99redquark start
						killall the64
						killall the64
						exit 0
					fi
				fi
			fi
		fi
	fi
fi

;;

esac
#-------------------------------------------------------------------------------------------------------------------
# END OF LINE... :) TRON...  FLINN: Then One Day....I GOT IN... :) RETROnuts Spannernick
#-------------------------------------------------------------------------------------------------------------------