#!/bin/bash

# Check if curl is installed
sudo apt install curl -y

mkdir ~/.backtobeta/
# Download java JRE 1.8 & Extract it
curl -o /tmp/java.tar.gz https://www.krafting.net/0/backtobeta/dl/data/java.tar.gz
tar -xvf /tmp/java.tar.gz 
mv jre1.8.0_261/ ~/.backtobeta/

# Download the launcher itself
curl -o /tmp/LauncherBTB.jar https://www.krafting.net/0/backtobeta/dl/data/LauncherBTB.jar
mv /tmp/LauncherBTB.jar ~/.backtobeta/

# Download the .desktop file & icon and move it on the ~/.local/share/applications/
# curl -o /tmp/icon.png [URL]
# mv /tmp/icon.png ~/.backtobeta/
curl -o /tmp/BackToBeta.desktop https://www.krafting.net/0/backtobeta/dl/data/BTB.desktop
mv /tmp/BackToBeta.desktop ~/.local/share/applications/
echo "~/.backtobeta/jre1.8.0_261/bin/java -jar ~/.backtobeta/LauncherBTB.jar" > ~/.backtobeta/launch.sh
chmod +x ~/.backtobeta/launch.sh
chmod +x ~/.backtobeta/LauncherBTB.jar
chmod +x ~/.local/share/applications/BackToBeta.desktop
echo ""
echo "Back To Beta a été installé avec succès. Lancé le depuis votre menu."
