#!/usr/bin/env bash

mount_device()
{
	  echo "$(grep '\(cdrom\|dvd\|cdrw\|cdwriter\)' /etc/fstab)"
	  #grep cdrom /etc/fstab | sort && grep dvd /etc/fstab | sort
	  echo; echo $bb_mnt_ch1_1
	  echo $bb_mnt_ch1_2
	  echo $bb_mnt_ch1_3
	  echo $bb_mnt_ch1_4
	  echo -n "|> "
	  read BBDEVICE
	  if [[ "${BBDEVICE}" == "" ]]; then
  		echo $bb_mnt_ch1_5
		wait_for_enter
		continue
	  else
  		echo "$bb_mnt_ch1_6${BBDEVICE}..."
		if mount ${BBDEVICE} &> /dev/null; then
			echo "${BBDEVICE}$bb_mnt_ch1_7"
			sleep 2s
			continue
		else
			echo $bb_mnt_ch1_8
			echo $bb_mnt_ch1_9
			echo $bb_mnt_ch1_10
			wait_for_enter
			continue
		fi
	  fi
}

umount_device()
{
	  if [ "$(grep -c '\(cdrom\|dvd\|cdrw\|cdwriter\)' /etc/mtab)" == 0 ]; then
  		echo $bb_mnt_ch2_1
		wait_for_enter
	  else
  		echo "$(grep '\(cdrom\|dvd\|cdrw\|cdwriter\)' /etc/mtab)"
		echo; echo $bb_mnt_ch2_2
		echo -n "|> "
		read BBDEVICE
		if umount ${BBDEVICE} &> /dev/null; then
			echo "${BBDEVICE}$bb_mnt_ch2_3"
			wait_for_enter
			continue
		else
			echo $bb_mnt_ch2_4
			echo $bb_mnt_ch2_5
			wait_for_enter
			continue
		fi
	  fi
}

eject_device()
{
	  echo "$(grep '\(cdrom\|dvd\|cdrw\|cdwriter\)' /etc/fstab)"
	  #grep cdrom /etc/fstab | sort && grep dvd /etc/fstab | sort
	  echo $bb_mnt_ch3_1
	  echo $bb_mnt_ch3_1b
	  echo -n "|> "
	  read BBDEVICE
	  if [[ $BBDEVICE == "" ]]; then
  		echo $bb_mnt_ch3_1c
		wait_for_enter
		continue
	  else
  		if ${BB_EJECT} ${BBDEVICE} &> /dev/null; then
			echo "${BBDEVICE}$bb_mnt_ch3_2"
			wait_for_enter
			continue
		else
  			echo $bb_mnt_ch3_3
			echo $bb_mnt_ch3_4
			wait_for_enter
			continue
		fi
	  fi
}

