#!/bin/bash

# Check if `fontcustom` is already installed.
if hash fontcustom 2>/dev/null; then
  # Exit if we already have it
  exit 0
fi

# Install dependencies
if [ "$(uname)" == "Darwin" ]; then
  # Use brew to install dependencies on macOS
  brew tap bramstein/webfonttools
  brew update
  brew install woff2
  brew install fontforge --with-python
  brew install eot-utils
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
  # Use apt and git/make to install dependencies on Ubuntu (Jenkins)
  sudo apt-get install zlib1g-dev fontforge -y
  git clone https://github.com/bramstein/sfnt2woff-zopfli.git sfnt2woff-zopfli && cd sfnt2woff-zopfli && make && mv sfnt2woff-zopfli /usr/local/bin/sfnt2woff
  git clone --recursive https://github.com/google/woff2.git && cd woff2 && make clean all && sudo mv woff2_compress /usr/local/bin/ && sudo mv woff2_decompress /usr/local/bin/
fi

# Install FontCustom
gem install fontcustom
