#!/bin/bash
scriptPath=$0;
scriptDir=$(readlink -f  "$(dirname "$scriptPath")")

echo
echo "This script will now copy the content of the directory"
echo "  ->  $scriptDir"
echo "into  /opt/bananaplusdev"

echo "***************************"
echo "CONTINUE AT YOUR OWN RISK"

if [ -d /opt/bananaplusdev ]; then
echo 
echo "The current content of /opt/bananaplusdev will be completely erased"
fi

echo 
echo "if you feel unsure, prefer the .AppImage package downloadable from our website."
echo "https://www.banana.ch"
echo
echo "Are you sure you want to continue? (type yes to continue)"
read varInput
echo
if [ "$varInput" != "yes" ] ; then
echo "Installation aborted... Exiting."
exit
fi

echo "Proceeding with installation"

#Create dir under /opt
if [ -d /opt/bananaplusdev ]; then
sudo rm -r /opt/bananaplusdev
fi
sudo mkdir /opt/bananaplusdev
sudo mv $scriptDir/* /opt/bananaplusdev/
cd /opt/bananaplusdev

#Create a launcher
sudo sed -i 's:Exec=bananaplusdev:Exec=/opt/bananaplusdev/bananaplusdev:g' /opt/bananaplusdev/bananaplusdev.desktop
sudo chmod +x bananaplusdev.desktop

#register Banana in the applications
sudo cp bananaplusdev.desktop /usr/share/applications
sudo cp bananaplusdev.svg /usr/share/icons/hicolor/scalable/apps
sudo gtk-update-icon-cache /usr/share/icons/hicolor

#associate the .ac2 extension with Banana
sudo cp usr/share/mime-ac2.xml /usr/share/mime/packages
sudo update-mime-database /usr/share/mime

#update application list
sudo update-desktop-database /usr/share/applications

echo "Installation of bananaplusdev finished"
