#!/bin/bash
# purge old Minecraft Java dummy deb
apt_lock_wait
sudo apt purge -y pi-apps-c6dfb753

install_packages kmod zip unzip libfuse2 || exit 1

# cleanup any remaing old lunar stuff
sudo rm -rf ~/lwjgl2arm32 ~/lwjgl3arm32 ~/lwjgl3arm64 ~/lwjgl2arm64 /opt/jdk/jdk-17.0.1+12 ~/lunarassets ~/.lunarclient ~/.local/share/applications/minecraftjava.desktop

#Download client and assorted java stuff
echo "Downloading lunarclient.AppImage"
mkdir -p ~/.local/bin || error "Could not make directory"
wget -O ~/.local/bin/lunarclient.AppImage 'https://github.com/gl91306/lunar/releases/download/v2.10.1.bruh/lunarclient-2.10.1-arm64.AppImage' || error 'Failed to download lunarclient.AppImage'
chmod +x ~/.local/bin/lunarclient.AppImage || error 'Failed to make lunarclient.AppImage executable!'

enable_module fuse || exit 1

#Then make menu shortcut
echo "[Desktop Entry]
Version=1.0
Type=Application
Name=Lunar Client
GenericName=Minecraft
Comment=Lunar Client for Rpi made by PiKATchu on Discord.
Icon=$(dirname "$0")/icon-64.png
Exec=$HOME/.local/bin/lunarclient.AppImage --no-sandbox
StartupNotify=true
Categories=Game;" > "$HOME/.local/share/applications/Lunar-Client.desktop"


echo "This fork of Lunar Client is made by the devs at Pi-Ware, an alternative to Pi-Apps with a focus on games and multi-os support (Arch and Manjaro).
You can find more about Pi-Ware at https://github.com/piware14/pi-ware
You should also contact them for support if a issue arises with the launcher. You can also try the 'Minecraft Java MultiMC5' app in the games section instead.

To run: Menu -> Games -> Lunar Client"
