#!/bin/bash

function head {
  echo -e "- \x1B[01;30m$1\x1B[0m"
}
function suc {
  echo -e "\x1B[32m√ $1\x1B[0m"
}
function fail {
  echo -e "\x1B[31m× $1\x1B[0m\n";
  exit 1
}

echo -e "\n"

head "checking environment..."

if [ ! -n "`which python`" ]; then
  fail "You need 'python' to run this module"
fi

suc "'python'"

if [ ! -n "`which easy_install`" ]; then
  fail "You need 'easy_install' to run this installation"
fi

suc "'easy_install'"

if [ ! -n "`which pip`" ]; then
  head "installing pip"
  easy_install pip
fi

suc "'pip'"


head "removing 'jieba'"

if [ -n "`pip show jieba`" ]; then
  pip uninstall jieba
fi

if [ -n "`pip show jieba`" ]; then
  fail "jieba can not be removed"
else
  suc "jieba is removed"
fi

head "installing 'jieba'"

pip install jieba

head "finished"

echo -e "\n"
