#!/bin/bash

function delete_java_install() {
	declare -a paths=(
		"/Library/Java/JavaVirtualMachines/jdk-9.jdk/" 
		"/Library/Java/JavaVirtualMachines/jdk-9.*.*.jdk/"
		"/Library/Java/JavaVirtualMachines/jdk-1{0..9}.jdk/"
		"/Library/Java/JavaVirtualMachines/jdk-1{0..9}.*.*.jdk/"
		"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"
		"/Library/PreferencePanes/JavaControlPanel.prefPane"
	)
	for path in "${paths[@]}" ; do
		echo "Currently deleting: $path"
		rm -rf "$path"
	done
}

function get_answer() {
	read -e -p "Do you wish to continue executing this script?[Y/N]: " answer
	echo "Your answer was: $answer"
	if [[ "$answer" == "Y" ]] || [[ "$answer" == "y" ]] || [[ "$answer" == "YES" ]] || [[ "$answer" == "YEs" ]] || [[ "$answer" == "Yes" ]] || [[ "$answer" == "yes" ]] ; then
		echo ''
		echo ''
		delete_java_install
		echo 'Finished uninstalling. Please check the output for errors and report them if present.'
		exit
	elif [[ "$answer" == "N" ]] || [[ "$answer" == "n" ]] || [[ "$answer" == "NO" ]] || [[ "$answer" == "No" ]] || [[ "$answer" == "no" ]] ; then
		exit #exit because they said no
	else
		get_answer #keep asking until they provide a valid answer
	fi
}
echo 'If you did not download this script from uskarian.net then cease execution of this script immediately! The validity of the script cannot be assured.'
echo 'Report any issues related to this script to support@uskarian.net'
echo ''
echo 'Description of script:'
echo 'This script will find and delete all files related to the installation of Java 9+.'
echo ''
echo ''
echo 'Liability:'
echo 'This script is provided "as is", without warranty of any kind, expressed or implied. You cannot hold us accountable for any claim, damages, or other liability, under any circumstance.'
echo ''
echo 'By agreeing to continue the execution of this script. You are agreeing to not hold us accountable for any sort of damages or issues that arise from the use of this script'
get_answer