#!/usr/bin/env sh

# launch or install UltimMC offline minecraft launcher if not installed
# launcher will download minecraft from mojang directly
# prerequisite OpenJDK Java runtime environment will also be installed

APP='UltimMC'
PREREQS='default-jre'
DL_URL='https://nightly.link/UltimMC/Launcher/workflows/main/develop/mmc-cracked-lin64.zip'
INSTALL_DIR="$HOME/.local/opt"

mkdir -p "$INSTALL_DIR"
[ ! -d "$INSTALL_DIR/$APP" ] && {
	TEMP="$XDG_RUNTIME_DIR/$APP.zip"
	user-confirm "Download and install $APP?" || exit 1
	wget -O- "$DL_URL" > "$TEMP"
	unzip "$TEMP" -d "$INSTALL_DIR"
	rm -rf "$TEMP"
	chmod 755 "$INSTALL_DIR/$APP/$APP"
}

is-installed $PREREQS | xargs -r sudo apt-get -y install || exit 1

"$INSTALL_DIR/$APP/$APP"