#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

rm -rf ~/eDEX-UI-RPi &>/dev/null
mkdir ~/eDEX-UI-RPi
wget -O ~/eDEX-UI-RPi/eDEX-UI-Linux-arm64_2.2.7.AppImage https://github.com/GitSquared/edex-ui/releases/download/v2.2.7/eDEX-UI-Linux-arm64.AppImage || error 'Failed to download 2.2.6 appimage!'
chmod +x ~/eDEX-UI-RPi/eDEX-UI-Linux-arm64_2.2.7.AppImage || error 'Failed to make the appimage executable!'

echo "[Desktop Entry]
Name=eDEX-UI 2.2.7
Comment=eDEX-UI sci-fi interface
Exec=bash -c "\""sudo modprobe fuse; $HOME/eDEX-UI-RPi/eDEX-UI-Linux-arm64_2.2.7.AppImage"\"" %U
Terminal=false
Type=Application
Icon=$(dirname "$0")/icon-64.png
StartupWMClass=eDEX-UI
X-AppImage-Version=2.2.7
Categories=System;
X-Desktop-File-Install-Version=0.23
X-AppImage-Comment=Generated by /tmp/.mount_eDEX-UDQYwse/AppRun" > ~/.local/share/applications/appimagekit-edex-ui.desktop
