forked from nihongodera/limelight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_mecab_php-mecab.sh
executable file
·48 lines (34 loc) · 1.24 KB
/
install_mecab_php-mecab.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
set -e
GREEN="\033[0;32m"
BLUE="\033[1;34m"
RED="\033[0;31m"
NC="\033[0m"
START=$PWD
HASMECAB=$(php -r 'echo extension_loaded("mecab");')
OUTPUT=$(php --version)
LONGVERSION=$(echo $OUTPUT | cut -d ' ' -f2 | cut -d '-' -f1)
SHORTVERSION=${LONGVERSION%.*}
echo $SHORTVERSION
echo "${GREEN}Installing dependencies...${NC}"
sudo apt-get install mecab mecab-ipadic-utf8 mecab-utils libmecab-dev unzip build-essential php${SHORTVERSION}-dev
if [ $HASMECAB ] ; then
echo "${BLUE}php-mecab is already installed.${NC}"
elif [ -d /etc/php/$SHORTVERSION/mods-available ] ; then
echo "${GREEN}Installing php-mecab...${NC}"
wget https://github.com/nihongodera/php-mecab/archive/master.zip
unzip master.zip
cd php-mecab-master/mecab && phpize && ./configure --with-php-config=/usr/bin/php-config --with-mecab-config=/usr/bin/mecab-config && make && sudo make install
cd /etc/php/$SHORTVERSION/mods-available
sudo touch mecab.ini
echo "extension=mecab.so" | sudo tee -a mecab.ini
sudo phpenmod -v $SHORTVERSION mecab
echo "${BLUE}Cleaning up...${NC}"
cd $START
rm master.zip
rm -rf "php-mecab-master"
else
echo "${RED}Unable to install php-mecab.${NC}"
exit 1
fi
echo "${GREEN}Install complete.${NC}"