-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathLinux_Install.sh
131 lines (108 loc) · 3.35 KB
/
Linux_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
#!/usr/bin/env bash
set -e
# Name of application to install
AppName="YourApplicationName"
# Set your project's install directory name here
InstallDir="YourApplicationFolder"
# Dependencies installed by Conda
# Comment out the next line if no Conda dependencies
CondaDeps="numpy scipy scikit-learn pandas"
# Install the package from PyPi
# Comment out next line if installing locally
PyPiPackage="mypackage"
# Local packages to install
# Useful if your application is not in PyPi
# Distribute this with a .tar.gz and use this variable
# Comment out the next line if no local package to install
LocalPackage="mypackage.tar.gz"
# Entry points to add to the path
# Comment out the next line of no entry point
# (Though not sure why this script would be useful otherwise)
EntryPoint="YourApplicationName"
echo
echo "Installing $AppName"
echo
echo "Installing into: $(pwd)/$InstallDir"
echo
# Miniconda doesn't work for directory structures with spaces
if [[ $(pwd) == *" "* ]]
then
echo "ERROR: Cannot install into a directory with a space in its path" >&2
echo "Exiting..."
echo
exit 1
fi
# Test if new directory is empty. Exit if it's not
if [ -d $(pwd)/$InstallDir ]; then
if [ "$(ls -A $(pwd)/$InstallDir)" ]; then
echo "ERROR: Directory is not empty" >&2
echo "If you want to install into $(pwd)/$InstallDir, "
echo "clear the directory first and run this script again."
echo "Exiting..."
echo
exit 1
fi
fi
# Download and install Miniconda
set +e
curl "https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh" -o Miniconda_Install.sh
if [ $? -ne 0 ]; then
curl "http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh" -o Miniconda_Install.sh
fi
set -e
bash Miniconda_Install.sh -b -f -p $InstallDir
# Activate the new environment
PATH="$(pwd)/$InstallDir/bin":$PATH
# Make the new python environment completely independent
# Modify the site.py file so that USER_SITE is not imported
python -s << END
import site
site_file = site.__file__.replace(".pyc", ".py");
with open(site_file) as fin:
lines = fin.readlines();
for i,line in enumerate(lines):
if(line.find("ENABLE_USER_SITE = None") > -1):
user_site_line = i;
break;
lines[user_site_line] = "ENABLE_USER_SITE = False\n"
with open(site_file,'w') as fout:
fout.writelines(lines)
END
# Install Conda Dependencies
if [[ $CondaDeps ]]; then
conda install $CondaDeps -y
fi
# Install Package from PyPi
if [[ $PyPiPackage ]]; then
pip install $PyPiPackage -q
fi
# Install Local Package
if [[ $LocalPackage ]]; then
pip install $LocalPackage -q
fi
# Cleanup
rm Miniconda_Install.sh
conda clean -iltp --yes
# Add Entry Point to the path
if [[ $EntryPoint ]]; then
cd $InstallDir
mkdir Scripts
ln -s ../bin/$EntryPoint Scripts/$EntryPoint
echo "$EntryPoint script installed to $(pwd)/Scripts"
echo
echo "Add folder to path by appending to .bashrc?"
read -p "[y/n] >>> " -r
echo
if [[ ($REPLY == "yes") || ($REPLY == "Yes") || ($REPLY == "YES") ||
($REPLY == "y") || ($REPLY == "Y")]]
then
echo "export PATH=\"$(pwd)/Scripts\":\$PATH" >> ~/.bashrc
echo "Your PATH was updated."
echo "Restart the terminal for the change to take effect"
else
echo "Your PATH was not modified."
fi
cd ..
fi
echo
echo "$AppName Install Successfully"