#!/bin/bash

OBSIDIAN_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
obsidianSource="https://github.com/obsidianmd/obsidian-releases/releases/download/v1.1.9/Obsidian-1.1.9.AppImage"
obsidianInstallDir="/home/$USER/obsidian"
obsidianRep="https://git.keydev.me/kerem/infoVault"

intro()
{
	graphics_install_prompt "Obsidian Will be installed"
	graphics_install_prompt "Source : $obsidianSource"
}

outro()
{
	graphics_install_prompt "Obsidian installation complete"
	cd $MAIN_DIR
}


install_obsidian()
{
	intro

	cd $OBSIDIAN_SCRIPT_DIR
	wget $obsidianSource
	obsidianExecutable=$(ls | grep -oP '.*AppImage')
	chmod ug+x $obsidianExecutable

	if [[ -d "$obsidianInstallDir" ]]
	then
		graphics_comment "Obsidian Already Exists only the app will be changed"
		cp $obsidianExecutable $obsidianInstallDir/obsidian.AppImage
	else
		graphics_comment "Obsidian Directory Will Be Created"
		mkdir $obsidianInstallDir
		cp $obsidianExecutable $obsidianInstallDir/obsidian.AppImage
	fi	
		cd $obsidianInstallDir
		graphics_comment "Markdown repertoire : $obsidianRep"
		git clone $obsidianRep

	cd $OBSIDIAN_SCRIPT_DIR
	rm -r $obsidianExecutable

	outro
}
