forked from jvasilakes/nltk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
122 lines (105 loc) · 2.37 KB
/
install.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /bin/bash
# Installs the current version of NLTK to
# the current python virtual environment.
# Requires virtualenvwrapper. Run from within
# the desired virtual environment.
function usage {
bold=$(tput bold)
normal=$(tput sgr0)
echo 'Usage: install.sh [-f] [-h] [NLTK_BASE_DIR ${PWD}]'
echo -e " ${bold}-f${normal}\tForce. Automatically install to current venv."
echo -e " ${bold}-h${normal}\tHelp. Print this message."
echo -e " ${bold}NLTK_BASE_DIR${normal}\tNLTK directory containing setup.py."
echo -e " If setup.py is not found, installation will abort. Default: cwd."
echo
exit 1
}
function doublecheck {
echo "Install to virtual environment '$(basename ${VIRTUAL_ENV})'? (y/n)"
read -n 1 ANS
if [[ ${ANS} == "n" ]]
then
echo -e "\rInstallation aborted"
exit 1
fi
}
if [ $(uname) == 'Darwin' ]
then
if which gstat > /dev/null 2>&1
then
STAT=gstat
else
echo "I need GNU stat (gstat). Please install it."
exit 1
fi
else
STAT=stat
fi
HELP=false
SAFE=true
while getopts ":fh" opt
do
case ${opt} in
f)
SAFE=false
;;
h)
HELP=true
;;
\?)
echo "Invalid option -${OPTARG}" >&2
;;
esac
done
shift $((OPTIND - 1))
if [ ${HELP} = true ]
then
usage
fi
if [ $# -gt 1 ]
then
usage
fi
if [ $# -eq 1 ]
then
NLTK_BASE_DIR=$1
else
NLTK_BASE_DIR=${PWD}
fi
if [ ! -x ${NLTK_BASE_DIR}/setup.py ]
then
echo "Can't find an executable ${NLTK_BASE_DIR}/setup.py. Aborting..."
exit 1
fi
if [ ${SAFE} = true ]
then
doublecheck
fi
echo -e "\rCreating required directories"
INSTALLDIR=${VIRTUAL_ENV}/lib/python2.7/site-packages
TEMPDIR=${HOME}/Software/nltk
mkdir -p ${INSTALLDIR}/nltk
mkdir -p ${TEMPDIR}
if [ -e ${INSTALLDIR}/nltk*.egg ]
then
OLDCTIME=$(${STAT} -c %Y ${INSTALLDIR}/nltk*.egg)
else
OLDCTIME=0
fi
echo "Copying source to temp directory '${TEMPDIR}'"
cp -r ${NLTK_BASE_DIR}/* ${TEMPDIR}
cd ${TEMPDIR}
echo "Building NLTK"
sudo python setup.py install > /dev/null 2>&1
echo "Installing NLTK"
cp -r ${TEMPDIR}/build/lib/nltk/* ${INSTALLDIR}/nltk
NEWCTIME=$(${STAT} -c %Y ${INSTALLDIR}/nltk*.egg)
SUCCESS=false
if $(python -c 'import nltk')
then
if [ ${OLDCTIME} -ne ${NEWCTIME} ]
then
SUCCESS=true
fi
fi
echo "Installed: ${SUCCESS}"