#!/bin/bash

# Versions: 
# Install script: 1.1
# Launcher: 2019.0

# 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 
if [ -d ~/.backtobeta/jre1.8.0_261 ]; then
    rm -rvf ~/.backtobeta/jre1.8.0_261/
fi
mv -fvu 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 -fv /tmp/LauncherBTB.jar ~/.backtobeta/

# Download the .desktop file & icon and move it on the ~/.local/share/applications/
curl -o /tmp/icon.png https://www.krafting.net/0/backtobeta/dl/data/logo.png
mv -fv /tmp/icon.png ~/.backtobeta/
curl -o /tmp/BackToBeta.desktop https://www.krafting.net/0/backtobeta/dl/data/BTB.desktop
mv -fv /tmp/BackToBeta.desktop ~/.local/share/applications/

# Create the launch script for better control of the .desktop
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."
