#!/bin/bash
install_packages libsdl2-mixer-2.0-0 libsdl2-ttf-2.0-0 || exit 1

mkdir ~/.fheroes2
cd ~/.fheroes2
# rename existing files to lower case
for i in $( ls | grep [A-Z] ); do mv -f $i `echo $i | tr 'A-Z' 'a-z'`; done
if [ ! -e data ]; then
    echo No game content detected, downloading shareware version
    wget -q --show-progress https://archive.org/download/HeroesofMightandMagicIITheSuccessionWars_1020/h2demo.zip
    unzip h2demo.zip
    rm h2demo.zip
fi
wget -N -q --show-progress https://github.com/dimag0g/fheroes2/releases/download/0.9.1-switch/fheroes2-rpi # || error "failed to download the executable!"
chmod a+x fheroes2-rpi
echo "[Desktop Entry]
Name=Free Heroes 2
Comment=Fheroes2 source port of Heroes of Might and Magic II
Exec=$HOME/.fheroes2/fheroes2-rpi
Icon=$(dirname "$0")/icon-64.png
Terminal=true
Type=Application
Categories=Game;
StartupNotify=false
" > ~/.local/share/applications/fheroes2.desktop || error "Failed to create menu entry!"
exit 0
