#!/bin/bash -li
# Makes the shell login and interactive

echo "
Are you ready to install po-util?
Please be sure to follow any prompts or instructions
during the installation process."

read -rp "ENTER / CTRL-C: "

echo "
Continuing installation...
"

if [[ "$USER" != "${USER/ /}" ]]; then
  echo "$(tput setaf 1)$(tput bold)WARNING: Your username contains space(s), something which is not compatible for po.$(tput sgr0)"
  exit
fi

if alias po &>/dev/null ; then
  echo "$(tput setaf 1)$(tput bold)WARNING: You have an alias named 'po'. Use 'unalias po' to remove the alias.$(tput sgr0)"
  exit
fi

if [[ $(uname -s) == "Darwin" ]]; then
  if hash brew 2>/dev/null;
  then
    echo "Homebrew is installed. Continuing..."
  else
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  fi

  brew update
  brew tap nrobinson2000/NewPo
  brew install NewPo
  po install
fi

if [[ $(uname -s) == "Linux" ]]; then
  sudo curl -fsSLo /usr/local/share/po-common https://raw.githubusercontent.com/nrobinson2000/po/master/share/po-common
  sudo curl -fsSLo /usr/local/share/po-linux https://raw.githubusercontent.com/nrobinson2000/po/master/share/po-linux
  sudo curl -fsSLo /usr/local/bin/po https://raw.githubusercontent.com/nrobinson2000/po/master/bin/po
  sudo chmod +x /usr/local/bin/po
  po install
fi

echo "po-util has been installed on your system.
If you are unsure about how to start with po-util
please check out the quickstart guide:
https://docs.po-util.com/quick-start.html
"