-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.bash
284 lines (283 loc) · 10.4 KB
/
install.bash
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#This script is for the installation of the project. It is intended to be copied from the repo and run before downloading said repo
#It will install the following things:
#Software-
# git
# npm
# node.js
# python
# pip3
# flask
# tor
# docker
##If any of these are already installed it will skip installing them
#pip3 packages-
# pysocks
# flask-httpauth
# stem
# cryptography
#BCAI Repository in specified directory, or current directory if none specified
#Onionshare repository in the same directory as the BCAI repository
#npm packages for user (see packages.json in ML/localUser for a complete list)
#npm packages for worker (see packages.json in ML/localWorker for a complete list)
#Initializing time
start=$(date +%s%N | cut -b1-13) #time in milliseconds
#Changing directory
dir=$(pwd | grep -o '[^/]*$')
downloadgit=true
if [ $# -eq 0 ] ;#No argument provided, install here
then
echo -e "\e[93mInstalling here."
else
if [ -d "$1" ] #If directory exists
then
echo -e "\e[93mInstalling at " $1
cd $1
else #Does not exist
echo -e "\e[91mProvided directory not found!"
exit #exit script execution
fi
fi
if [ -d "BCAI" ] ;#if BCAI folder already exists, remove it
then
read -p $'\e[91mBCAI already exists, remove? \e[0m[Y/N] ' remove
case "$remove" in
[yY][eE][sS]|[yY])
rm -rf "BCAI"
echo -e "\e[92mSuccessfully removed previous BCAI."
;;
*)
read -p $'\e[91mDo you just want to install software and npm packages? \e[0m[Y/N] ' remove
case "$remove" in
[yY][eE][sS]|[yY])
echo -e "\e[92mJust installing software and npm packages."
downloadgit=false
;;
*)
echo -e "\e[91mChose not to remove, aborting installation."
exit
;;
esac
;;
esac
fi
###################################Installing Programs###################################
#Install git
if ! git --version > /dev/null 2>&1 ; #git not installed
then
echo -e "\e[93mgit not installed, installing now.\e[0m"
sudo apt update > /dev/null 2>&1
if sudo apt install git --yes --force-yes > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mgit successfully installed."
else #problem installing
echo -e "\e[91mProblem installing git. Aborting installation."
exit
fi
else
echo -e "\e[92mgit already installed."
fi
#Install npm
if ! npm --version > /dev/null 2>&1 ; #npm not installed
then
echo -e "\e[93mnpm not installed, installing now.\e[0m"
sudo apt update > /dev/null 2>&1
if sudo apt install npm --yes --force-yes > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mnpm successfully installed."
else #problem installing
echo -e "\e[91mProblem installing npm. Aborting installation."
exit
fi
else
echo -e "\e[92mnpm already installed."
fi
#Install node
if ! node --version > /dev/null 2>&1 ; #node not installed
then
echo -e "\e[93mnode not installed, installing now.\e[0m"
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt update > /dev/null 2>&1
if sudo apt install nodejs --yes --force-yes > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mnode successfully installed."
else #problem installing
echo -e "\e[91mProblem installing node. Aborting installation."
exit
fi
else
echo -e "\e[92mnode already installed."
fi
#Install python
if ! python3 --version > /dev/null 2>&1 ; #python not installed
then
echo -e "\e[93mpython not installed, installing now.\e[0m"
sudo apt update > /dev/null 2>&1
if sudo apt install python3 --yes --force-yes > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mpython successfully installed."
else #problem installing
echo -e "\e[91mProblem installing python. Aborting installation."
exit
fi
else
echo -e "\e[92mpython already installed."
fi
#Install pip3
if ! pip3 --version > /dev/null 2>&1 ; #pip3 not installed
then
echo -e "\e[93mpip3 not installed, installing now.\e[0m"
sudo apt update > /dev/null 2>&1
if sudo apt install python3-pip --yes --force-yes > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mpip3 successfully installed."
else #problem installing
echo -e "\e[91mProblem installing pip3. Aborting installation."
exit
fi
else
echo -e "\e[92mpip3 already installed."
fi
#Install flask (necessary for onionshare)
if ! flask --version > /dev/null 2>&1 ; #flask not installed
then
echo -e "\e[93mflask not installed, installing now.\e[0m"
sudo apt update > /dev/null 2>&1
if sudo apt install python3-flask --yes --force-yes > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mflask successfully installed."
else #problem installing
echo -e "\e[91mProblem installing flask. Aborting installation."
exit
fi
else
echo -e "\e[92mflask already installed."
fi
#Install tor
if ! tor --version > /dev/null 2>&1 ; #tor not installed
then
echo -e "\e[93mtor not installed, installing now.\e[0m"
sudo apt update > /dev/null 2>&1
if sudo apt install tor --yes --force-yes > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mtor successfully installed."
else #problem installing
echo -e "\e[91mProblem installing tor. Aborting installation."
exit
fi
else
echo -e "\e[92mtor already installed."
fi
#Install docker
if ! docker --version > /dev/null 2>&1 ; #docker not installed
then
echo -e "\e[93mDocker not installed, installing now.\e[0m"
sudo apt-get update > /dev/null 2>&1
if sudo apt-get install docker.io --yes --force-yes > /dev/null 2>&1 ; then #if installed
sudo systemctl start docker > /dev/null 2>&1
sudo systemctl start docker > /dev/null 2>&1
echo -e "\e[92mDocker successfully installed."
else #problem installing
echo -e "\e[91mProblem installing Docker. Aborting installation."
exit
fi
else
echo -e "\e[92mdocker already installed."
fi
#No way to check if pip3 packages are installed without actually running a python script...
#Just assume they aren't, if they are nothing bad happens
#Install PySocks
echo -e "\e[93mInstalling PySocks.\e[0m"
if pip3 install PySocks > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mPySocks successfully installed."
else #problem installing
echo -e "\e[91mProblem installing PySocks. Aborting installation."
exit
fi
#Install flask-httpauth
echo -e "\e[93mInstalling flask-httpauth.\e[0m"
if pip3 install flask-httpauth > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mflask-httpauth successfully installed."
else #problem installing
echo -e "\e[91mProblem installing flask-httpauth. Aborting installation."
exit
fi
#Install stem
echo -e "\e[93mInstalling stem.\e[0m"
if pip3 install stem > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mstem successfully installed."
else #problem installing
echo -e "\e[91mProblem installing stem. Aborting installation."
exit
fi
#Install cryptography
echo -e "\e[93mInstalling cryptography.\e[0m"
if pip3 install cryptography > /dev/null 2>&1 ; then #if installed
echo -e "\e[92mcryptography successfully installed."
else #problem installing
echo -e "\e[91mProblem installing cryptography. Aborting installation."
exit
fi
#Download repo
if [ "$downloadgit" = true ] ; then
echo -e "\e[93m----------------------------Downloading github repo.----------------------------\e[0m"
if git clone https://github.com/PedroGRivera/BCAI.git ; then #if downloaded
echo -e "\e[92mGithub repo successfully downloaded."
else #problem downloading
echo -e "\e[91mProblem downlodding repo. Aborting installation."
exit
fi
fi
#Download onionshare repo
echo -e "\e[93m----------------------------Downloading onionshare repo.----------------------------\e[0m"
if git clone https://github.com/micahflee/onionshare.git ; then #if downloaded
echo -e "\e[92mOnionshare repo successfully downloaded."
else #problem downloading
echo -e "\e[91mProblem downloading onionshare repo. Aborting installation."
exit
fi
###################################Installing npm packages###################################
#Install npm stuff for localuser
cd BCAI/ML/localUser/
echo -e "\e[93m---------------------Installing npm packages for localUser.---------------------\e[0m"
if npm install ; then #if installed
echo -e "\e[92mnpm packages for localUser successfully installed."
else #problem installing
read -p $'\e[91mnpm installation failed without sudo. Try again with sudo? [Y/N]\e[0m ' tryagain
case "$tryagain" in #try again with sudo this time
[yY][eE][sS]|[yY])
if sudo npm install ; then #if installed
echo -e "\e[92mnpm packages for localUser successfully installed."
else
"\e[91mProblem installing npm packages for localUser. Aborting installation."
exit
fi
;;
*)
echo -e "\e[91mChose not to try with sudo, aborting installation."
exit
;;
esac
fi
#Install npm stuff for localworker
cd .. #back up to ML
cd localWorker/
echo -e "\e[93m--------------------Installing npm packages for localWorker.--------------------\e[0m"
if npm install ; then #if installed
echo -e "\e[92mnpm packages for localWorker successfully installed."
else #problem installing
read -p $'\e[91mnpm installation failed without sudo. Try again with sudo? [Y/N]\e[0m ' tryagain
case "$tryagain" in #try again with sudo this time
[yY][eE][sS]|[yY])
if sudo npm install ; then #if installed
echo -e "\e[92mnpm packages for localWorker successfully installed."
else
"\e[91mProblem installing npm packages for localWorker. Aborting installation."
exit
fi
;;
*)
echo -e "\e[91mChose not to try with sudo, aborting installation."
exit
;;
esac
fi
#Finishing up
echo -e "\e[92mInstallation successful. Run startUser.bash or startWorker.bash without sudo to start the program.\e[0m"
end=$(date +%s%N | cut -b1-13) #time in milliseconds
difference=$((end - start)) #time from start to end
diffsec=$((difference / 1000)) #time in seconds
echo -e "\e[93mTotal time taken: $diffsec seconds\e[0m" #display time
exit #finished!