#!/bin/bash

if [[ -f "/usr/bin/apt" ]]
then
    sudo apt install kmod
fi
if [[ -f "/usr/bin/pacman" ]]
then
    sudo pacman -S kmod
fi
sudo modprobe fuse

mkdir $HOME/.local
cd $HOME/.local

echo "Downloading split files"
wget https://github.com/gl91306/lunar/raw/master/lunarclient-3.0.3-arm64.AppImage.1
wget https://github.com/gl91306/lunar/raw/master/lunarclient-3.0.3-arm64.AppImage.2

echo "Combining split files"
cat lunarclient-3.0.3-arm64.AppImage.* > lunarclient-3.0.3-arm64.AppImage
rm -rf lunarclient-3.0.3-arm64.AppImage.*
mkdir ~/.local/lunarassets

chmod +x $HOME/.local/lunarclient-3.0.3-arm64.AppImage

cd lunarassets
wget https://github.com/gl91306/lunar/raw/master/lunarclient.png

echo "Creating a desktop entry for Lunar Client..."
echo "[Desktop Entry]
Name=Lunar Client
Comment=Lunar Client for ARM64 made by PiKATchu
Exec=$HOME/.local/lunarclient-3.0.3-arm64.AppImage --no-sandbox
Icon=$HOME/.local/lunarassets/lunarclient.png
Categories=Game;
Type=Application
Terminal=false" > "$HOME/.local/share/applications/Lunar-Client.desktop"

echo "Installation complete"