#!/bin/bash

readonly Script_Title="Install Official VirtualBox Guest Additions"


LH64_602_B2_Guest_Additions_Mountpoint="/media/VBOXADDITIONS_4.3.22_98236/"

if [ -d "$LH64_602_B2_Guest_Additions_Mountpoint" ]
then
	cd "$LH64_602_B2_Guest_Additions_Mountpoint"
	
	./VBoxLinuxAdditions.run
	result_code="$?"
	exit "$result_code"
fi

# 22:07:45 01/09/2018.  If this isn't LH64_602_B2, then we search sr1, sr2, and sr3
# for the VBoxLinuxAdditions.run file, until we finally find it.

Fillepath____Guest_Additions=""


discdrive_num=0

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


#echo | bash "$Fillepath____Guest_Additions"
# 15:40:01 06/03/2018.  Didn't work - the above was an attempt to
# simulate a press of the Enter key to make the Guest Additions window
# disappear automatically.

bash "$Fillepath____Guest_Additions"