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

cd $HOME
rm -r ~/tmp &>/dev/null
mkdir -p ~/tmp
cd tmp || error "Failed to enter $HOME/tmp directory!"
wget https://fontsdata.com/zipdown-segoeuiemoji-132714.htm || error "Failed to download Segoe UI Emoji font!"
wget https://noto-website.storage.googleapis.com/pkgs/NotoColorEmoji-unhinted.zip || error "Failed to download Noto Color Emoji font!"
mv zipdown-segoeuiemoji-132714.htm segoeuiemoji.zip
unzip segoeuiemoji.zip || error "Failed to extract Segoe UI Emoji font!"
unzip NotoColorEmoji-unhinted.zip || error "Failed to extract Noto Color Emoji font!"
rm "$HOME/.fonts/Segoe UI.ttf" "$HOME/.fonts/Noto Color Emoji.ttf" &>/dev/null
mkdir -p ~/.fonts &>/dev/null
mv seguiemj.ttf "$HOME/.fonts/Segoe UI.ttf" || error "Failed to move Segoe UI font to .fonts folder!"
mv NotoColorEmoji.ttf "$HOME/.fonts/Noto Color Emoji.ttf" || error "Failed to move Noto Color Emoji font to .fonts folder!"
fc-cache -f -v &>/dev/null
rm -r ~/tmp
