#!/bin/bash
version=3.5.2
version2=1.15.0

case $(get_codename) in
buster|bionic)
  error "Godot ARM64 precompiled binaries do not support Debian Buster. Canceling the install." ;;
esac

rm -rf ~/Godot
mkdir -p ~/Godot
cd ~/Godot || error "Could not change to directory"
wget -O godot.zip https://github.com/hiulit/Unofficial-Godot-Engine-Raspberry-Pi/releases/download/v${version2}/godot_${version}-stable_rpi4_64.zip || error "failed to download!"
unzip godot.zip
rm -f godot.zip
# IMPORTANT: 32bit arm is packaged differently than 64bit arm and contains a subfolder with the binaries. Check this whenever bumping releases
echo "[Desktop Entry]
Name=Godot Engine
Comment=Best Opensource Game Engine
Path=$HOME/Godot
Exec=env MESA_GL_VERSION_OVERRIDE=3.3 $HOME/Godot/godot_${version}-stable_rpi4_editor.arm64
Icon=$(dirname $0)/icon-64.png
Terminal=false
Type=Application
Categories=Development;
StartupNotify=true" > ~/.local/share/applications/godot-engine.desktop
