#!/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"

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

	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"
	else
		graphics_comment "Obsidian Directory Will Be Created"
		mkdir -p $obsidianInstallDir
	fi	
	
	
	cp $obsidianExecutable $obsidianInstallDir/obsidian.AppImage
	rm $OBSIDIAN_SCRIPT_DIR/$obsidianExecutable
		
	cd $obsidianInstallDir
	graphics_comment "Markdown repertoire : $obsidianRep"
	git clone $obsidianRep

	if [[ -d "$obsidianInstallDir/infoVault" ]]
	then 
		graphics_comment "Info Vault already here not replacing. don't forget update the git"
	fi

	graphics_install_prompt "Obsidian installation complete"
	cd $MAIN_DIR

}
