#! /bin/bash # # Copyright 2019 Team KoNLPy # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Set mecab related variable(s) mecab_dicdir="/usr/local/lib/mecab/dic/mecab-ko-dic" # Exit as soon as we fail set -e # Determine OS os=$(uname) if [[ ! $os == "Linux" ]] && [[ ! $os == "Darwin" ]]; then echo "This script does not support this OS." echo "Try consulting https://github.com/konlpy/konlpy/blob/master/scripts/mecab.sh" exit 0 fi # Determine sudo if hash "sudo" &>/dev/null; then sudo="sudo" else sudo="" fi # Determine python # TODO: Prefer python3 and Respect pyenv python="python3" if hash "pyenv" &>/dev/null; then python="python" fi # Determine python site location are writable. check_python_site_location_is_writable(){ $python - < /usr/local/etc/mecabrc' $sudo make install } install_mecab_python(){ pushd /tmp if [[ ! -d "mecab-python-0.996" ]]; then git clone https://bitbucket.org/eunjeon/mecab-python-0.996.git fi popd if [[ "$os" == "Darwin" ]]; then CFLAGS=-stdlib=libc++ $python -m pip install $at_user_site /tmp/mecab-python-0.996 else # the gcc compiler has no such commandline option as -stdilb, so let's not use it. See discussion on #391. $python -m pip install $at_user_site /tmp/mecab-python-0.996 fi } if ! hash "automake" &>/dev/null; then echo "Installing automake (A dependency for mecab-ko)" install_automake fi if hash "mecab" &>/dev/null; then echo "mecab-ko is already installed" else echo "Install mecab-ko" install_mecab_ko fi if [[ -d $mecab_dicdir ]]; then echo "mecab-ko-dic is already installed" else echo "Install mecab-ko-dic" install_mecab_ko_dic fi if [[ $($python -c 'import pkgutil; print(1 if pkgutil.find_loader("MeCab") else 0)') == "1" ]]; then echo "mecab-python is already installed" else echo "Install mecab-python" install_mecab_python fi echo "Done."