#!/bin/bash

FONTS_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

sourceCodePro="https://github.com/adobe-fonts/source-code-pro"
awsomeFont6="https://use.fontawesome.com/releases/v6.2.1/fontawesome-free-6.2.1-desktop.zip"
awsomeFont5="https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-desktop.zip"

fonts_intro()
{
	graphics_install_prompt "Following Fonts Will be installed"
	graphics_install_prompt "$sourceCodePro"
	graphics_install_prompt "$awsomeFont6"
	graphics_install_prompt "$awsomeFont5"
	
	if [[ -d "$FONTS_DIR" ]]
	then
		graphics_comment "$FONTS_DIR Exists"
	else 
		graphics_comment "$FONTS_DIR Will be created"
		sudo mkdir -p $FONTS_DIR
	fi
}

fonts_outro()
{
	graphics_install_prompt "fonts installation complete"
	cd $MAIN_DIR
}

install_fonts()
{
	fonts_intro
	
	cd $FONTS_SCRIPT_DIR
	
	graphics_install_prompt "Installing Source Code Pro"
	git clone $sourceCodePro
	
	if [[ -d "$FONTS_DIR/source-code-pro" ]]
	then
		graphics_comment "A version of source-code-pro exits and will be repacled"
		sudo rm -r $FONTS_DIR/source-code-pro
	else
		graphics_comment "Creating $FONTS_DIR/source-code-pro directory" 
	fi
	
	sudo cp -r source-code-pro $FONTS_DIR
	sudo chmod -R 555 $FONTS_DIR/source-code-pro
	sudo rm -r source-code-pro

		
	graphics_install_prompt "Installing Awsome Fonts Version 6"
	wget $awsomeFont6 
	unzip -q *.zip
	rm *.zip

	fontDir=$(find . -mindepth 1 -maxdepth 1 -type d)

	if [[ -d "$FONTS_DIR/$fontDir" ]]
	then
		graphics_comment "A version of $fontDir exits and will be repacled"
		sudo rm -r $FONTS_DIR/$fontDir
	else
		graphics_comment "Creating $FONTS_DIR/$fontDir directory" 
	fi

	sudo cp -r $fontDir $FONTS_DIR/
	sudo chmod -R 555 $FONTS_DIR/
	rm -r $fontDir



	graphics_install_prompt "Installing Awsome Fonts Version 5"
	wget $awsomeFont5 
	unzip -q *.zip
	rm *.zip

	fontDir=$(find . -mindepth 1 -maxdepth 1 -type d)

	if [[ -d "$FONTS_DIR/$fontDir" ]]
	then
		graphics_comment "A version of $fontDir exits and will be repacled"
		sudo rm -r $FONTS_DIR/$fontDir
	else
		graphics_comment "Creating $FONTS_DIR/$fontDir directory" 
	fi

	sudo cp -r $fontDir $FONTS_DIR/
	sudo chmod -R 555 $FONTS_DIR/
	rm -r $fontDir

	fc-cache -f -v
	fonts_outro
}
