-
Notifications
You must be signed in to change notification settings - Fork 37
/
install.sh
executable file
·134 lines (117 loc) · 3.84 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
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
download_miniconda() {
echo "Downloading Miniconda for Python dependencies..."
OS_BIT_TYPE="$(uname -m)"
OS_ARCHITECTURE="$(uname -s)"
if [ $OS_BIT_TYPE == "i686" ]; then
OS_BIT_TYPE="x86"
fi
if [ $OS_ARCHITECTURE == "Darwin" ]; then
OS_ARCHITECTURE="MacOSX"
fi
MINICONDA_INSTALL_FILE="Miniconda2-latest-$OS_ARCHITECTURE-$OS_BIT_TYPE.sh"
MINICONDA_DOWNLOAD_URL="https://repo.continuum.io/miniconda/$MINICONDA_INSTALL_FILE"
$(curl -O $MINICONDA_DOWNLOAD_URL)
$(chmod +x $MINICONDA_INSTALL_FILE)
}
install_miniconda() {
echo "Installing Miniconda..."
echo "$(./$MINICONDA_INSTALL_FILE -b -p $HOME/miniconda)"
echo "$(rm $MINICONDA_INSTALL_FILE)"
}
confirm_miniconda_installed() {
if hash conda 2>/dev/null; then
echo "Miniconda installed!"
else
echo "Failed to install Miniconda. Please visit http://conda.pydata.org/docs/install/quick.html to install and then try rerunning this script, making sure that Miniconda is accessible in the PATH"
fi
}
update_script_startup_file() {
echo "if [[ \":\$PATH:\" != *\":\$HOME/miniconda/bin:\"* ]]; then" >> $STARTUP_FILE
echo " export PATH=\"\$PATH:\$HOME/miniconda/bin\"" >> $STARTUP_FILE
echo "fi" >> $STARTUP_FILE
}
add_miniconda_to_path() {
# temporary update to PATH for this script
export PATH="$PATH:$HOME/miniconda/bin"
# permanent update to PATH for user's convenience
if [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then
STARTUP_FILE="$HOME/.bashrc"
update_script_startup_file
elif [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then
STARTUP_FILE="$HOME/.zshrc"
update_script_startup_file
else
echo "Couldn't automatically add Miniconda to the PATH of your preferred terminal. We suggest working from Bash or ZShell."
fi
}
install_conda_if_needed() {
if hash conda 2>/dev/null; then
echo "Miniconda installed!"
else
if ping -c 1 google.com >> /dev/null 2>&1; then
download_miniconda
install_miniconda
add_miniconda_to_path
confirm_miniconda_installed
else
echo "Looks like you're offline! Please address this and then try rerunning this script."
fi
fi
}
create_conda_environment() {
if hash conda 2>/dev/null; then
CONDA_ENVIRONMENTS="$(conda env list)"
if [[ "$CONDA_ENVIRONMENTS" != *"words2map"* ]]; then
conda create --name words2map --yes cython scikit-learn seaborn
conda install --name words2map --yes -c conda-forge hdbscan
fi
fi
}
install_developer_libraries_as_needed() {
OS_ARCHITECTURE="$(uname -s)"
if [ $OS_ARCHITECTURE == "Linux" ]; then
# currently dumb handling of ubuntu v. other linux distros
echo "$(sudo apt-get -y update && sudo apt-get -y install python-dev)"
echo "$(sudo yum update -y && sudo yum install python-devel -y && sudo yum groupinstall "Development Tools" -y)"
fi
}
install_hdbscan() {
git clone https://github.com/lmcinnes/hdbscan.git
}
install_python_dependencies() {
if hash conda 2>/dev/null; then
echo 'Installing Python dependencies for words2map...'
source activate words2map
install_developer_libraries_as_needed
pip install pattern semidbm nltk unidecode
pip install gensim==0.13.3
fi
}
prepare_words2map() {
echo "$(tar xzf vectors.tar.gz)"
echo "$(python -m nltk.downloader punkt stopwords)"
GREEN="\033[0;32m"
NOCOLOR="\033[0m"
echo ""
echo "Everything installed!"
echo ""
echo -e "Activate the words2map virtual machine by typing ${GREEN}source activate words2map${NOCOLOR}"
echo ""
}
refresh_user_shell() {
if [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then
exec bash
elif [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then
exec zsh
fi
}
install_words2map_if_space_available() {
install_conda_if_needed
create_conda_environment
install_python_dependencies
prepare_words2map
refresh_user_shell
}
install_words2map_if_space_available
# create and remove swap file if RAM is not large enough for installation, as shown here: http://stackoverflow.com/a/18335151/1241952