#!/bin/bash

readonly Script_Title="Mount DevX SFS"

LH64_602_B2_DevX_Mountpoint="/media/DevX"


readonly Fillepath____Quickly_Toggle_SFS_Mount="/root/APSK-VBSK VirtualBox Setup Kit/Quickly Toggle SFS Mount/Caution - Running this multiple times too quickly can crash the entire system!/quickly_toggle_sfs_mount"



if [ -d "$LH64_602_B2_DevX_Mountpoint" ]
then
	# 18:25:03 01/08/2018.  For this to work, the DevX ISO must be mounted at /media/DevX.

	search_results=$(find /media/DevX -type f -iname *devx*.sfs | head -n 1)

	if [ ! -z "$search_results" ]
	then
		Fillepath____DevX="$search_results"
	fi
	
	bash "$Fillepath____Quickly_Toggle_SFS_Mount" "$Fillepath____DevX"
	
	#sfs_load "/media/DevX/Devx-L64_602.sfs"
	
	exit 0
fi


# 20:40:46 01/09/2018.  If this isn't LH64_602_B2, then we search sr1, sr2, and sr3
# for DevX .sfs files, until we finally find it.

Fillepath____DevX=""
Temp_Fillepath____DevX_Location="/tmp/DevX_Location.txt"


discdrive_num=0

while [ "$discdrive_num" -lt 4 ]
do
	let "discdrive_num++"
	
	search_results=$(find /mnt/sr$discdrive_num -type f -iname *devx*.sfs | head -n 1)
	
	if [ ! -z "$search_results" ]
	then
		Fillepath____DevX="$search_results"
	fi
done


echo "$Fillepath____DevX" > "$Temp_Fillepath____DevX_Location"


#sfs_load "$Fillepath____DevX"

bash "$Fillepath____Quickly_Toggle_SFS_Mount" "$Fillepath____DevX"