-
Notifications
You must be signed in to change notification settings - Fork 3
/
install-storjio
318 lines (268 loc) · 8.83 KB
/
install-storjio
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
# How to use: wget -qO- CLITools.tk/install-storjio>install-storjio && chmod +x install-storjio && ./install-storjio <email:characterstring> <LIVEPATCHTOKEN(optional)>
# You can't directly wget it and run it with bash: wget xy | bash !
# Don't run the script with sudo!
cd ~
res1=$(date +%s.%N)
STORJTOKEN=${1?Format: ./install-storjio <email:characterstring> <LIVEPATCHTOKEN(optional)>}
LPTOKEN=${2:-nul}
while [ "$1" != "" ]; do
case $1 in
-c | --cleanup ) echo cleanup; rm ~/identity_linux_amd64.zip; exit 1
esac
shift
done
echo
echo
echo Version: 0.0.3 - Stable
echo Date: 10.01.2021
echo Author: TechHome/marrobhd
echo Source: info.clitools.tk
echo
echo
sudo apt-get install curl
echo Setting up variables...
echo ----------------------------------------------------------
echo
function pause(){
read -s -n 1 -p "Press any key to continue ..."
echo
}
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
sudo rm /run/shm/error.log
IP=$(hostname -I | cut -d' ' -f1)
PUBLICIP=$(curl ifconfig.me)
USERNAME=$(whoami)
HOMEDIR=$(echo ~)
if [ $LPTOKEN == "nul" ] 2>/run/shm/error.log
then
echo "We will let livepatch uninstalled!"
else
echo "We will install and enable livepach!"
fi
echo storjtoken: $STORJTOKEN
echo lptoken: $LPTOKEN
echo Please verify your details
pause
echo ----------------------------------------------------------
echo Success!
echo
#intall storjo
echo
echo
echo Install required packages to build...
echo ----------------------------------------------------------
if sudo apt-get update && sudo apt-get install snapd unzip openssh-server -y; then
echo
echo
else
echo Trying to fix errors...
sudo dpkg --configure -a || exit 1
sudo apt-get update && apt-get install sudo && sudo apt-get dist-upgrade -y && sudo apt-get install snapd unzip openssh-server -y || exit 1
fi
echo
# Install docker and docker compose via script
wget -qO- https://raw.githubusercontent.com/marrobHD/clitools/master/install-docker | bash
# optional: install and enable livepatch on your system
if [ "$LPTOKEN" != "nul" ]
then
echo
echo
echo Installing and enabling canonical-livepatch on your system...
echo ----------------------------------------------------------
sudo snap install canonical-livepatch && sudo canonical-livepatch enable $LPTOKEN
echo ----------------------------------------------------------
echo
else
echo
fi
echo
echo ----------------------------------------------------------
echo Success!
echo
echo
echo Creating/Importing an identity...
echo ----------------------------------------------------------
echo
mkdir -p ~/.local/share/storj/identity/
echo If you want to import an identity, copy your backed up folder "storagenode" to ~/.local/share/storj/identity/
echo If you did all well the script detects it and skips the creation of a new identity.
echo
echo 1. login to $IP with username $USERNAME and your password
echo 2. go to ~/.local/share/storj/identity/ and paste the directory "storagenode"
echo
echo If you want to create a new identity you can ignore this.
echo
pause
echo
curl -L https://github.com/storj/storj/releases/latest/download/identity_linux_amd64.zip -o identity_linux_amd64.zip || exit 1
unzip -o identity_linux_amd64.zip || exit 1
chmod +x identity || exit 1
sudo mv identity /usr/local/bin/identity || exit 1
echo
if grep -c BEGIN ~/.local/share/storj/identity/storagenode/ca.cert | grep -q '2'; then
echo "already matched"
if grep -c BEGIN ~/.local/share/storj/identity/storagenode/identity.cert | grep -q '3'; then
echo "already matched"
IDENTITYSTATUS=matched
else
echo "mismatched"
fi
else
echo "No existing identity found. Create one?"
fi
if [ "$IDENTITYSTATUS" != "matched" ]; then
while true; do
read -p "Creating an identity can take several hours or days, proceed? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) sudo rm identity_linux_amd64.zip && sudo rm -r /usr/local/bin/identity; exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
if [ "$IDENTITYSTATUS" != "matched" ]; then
identity create storagenode || exit 1
identity authorize storagenode $STORJTOKEN
fi
grep -c BEGIN ~/.local/share/storj/identity/storagenode/ca.cert | grep -q '2' && echo matched || echo mismatched || exit
grep -c BEGIN ~/.local/share/storj/identity/storagenode/identity.cert | grep -q '3' && echo matched || echo mismatched && echo please abort! CTR+C|| exit
echo
echo ----------------------------------------------------------
echo Sucess
echo
echo
echo Backup your identity!
echo ----------------------------------------------------------
echo
echo Backup before you continue, it should be quick!
echo This allows you to restore your Node in case of an unfortunate hardware or OS incident.
echo
echo 1. login to $IP with username $USERNAME and your password
echo 2. go to ~/.local/share/storj/identity/ and back up the directory "storagenode"
echo
while true; do
read -p "I followed the steps and have now saved the storagenode folder. " yn
case $yn in
[Yy]* ) echo && echo Great, lets continue; break;;
[Nn]* ) echo && echo Your own risk! I recommend do this later, lets continue; break;;
* ) echo "Please answer yes or no.";;
esac
done
echo
echo ----------------------------------------------------------
echo Finished!
echo
echo
echo CLI Install via Docker/Compose
echo ----------------------------------------------------------
echo
cd ~
echo "Enter external(port to forward) eg. 28967 and press [ENTER]: "
read STORJPORT1
echo
echo "Enter webdashport(port for web dashboard) eg. 14002 and press [ENTER]: "
read STORJPORT2
echo
echo "Enter myetherwallet.com Wallet ID eg. 0xe5380DBa756Ea63b2bc98769bEB614750DaE0089 and press [ENTER]: "
read WALLET
echo
echo "Enter your email address from your storjtoken and press [ENTER]: "
read EMAIL
echo
echo "Enter your full domain eg. storjio.mydomain.com:$STORJPORT1, which points to $PUBLICIP [ENTER]: "
read FULLDOMAIN
echo
echo "Size of Storage + 10% overhead. If you over-allocate space, you may corrupt your database! ex. 600GB disk, 500GB + 10%=550GB [ENTER]: "
read STORAGE
echo
echo "Enter the path where storjio stores its files. eg. /mnt/storjio or $HOMEDIR/storagenode_files [ENTER]: "
read STORAGEPATH
echo
echo
echo Do your port forwarding: From: Anywhere, Port $STORJPORT1, Forward IP: $IP, Forward Port: $STORJPORT1, Protocol: TCP
echo
pause
echo "
version: \"3.3\"
services:
storagenode:
image: storjlabs/storagenode:latest
container_name: storagenode
volumes:
- type: bind
source: \"$HOMEDIR/.local/share/storj/identity/storagenode\"
target: /app/identity
- type: bind
source: \"$STORAGEPATH\"
target: /app/config
ports:
- $STORJPORT1:28967
- $STORJPORT2:14002
deploy:
restart_policy:
condition: always
environment:
- WALLET=$WALLET
- EMAIL=$EMAIL
- ADDRESS=$FULLDOMAIN
- STORAGE=$STORAGE
watchtower:
image: storjlabs/watchtower:latest
restart: always
container_name: watchtower
command: --interval 21600 --cleanup true --stop-timeout 300s --cleanup
volumes:
- /var/run/docker.sock:/var/run/docker.sock
" | tee docker-compose.yml > /dev/null
echo "
# /etc/systemd/system/storagenode.service
[Unit]
Description=Storagenode
Requires=docker.service
After=docker.service
[Service]
Type=simple
RemainAfterExit=yes
WorkingDirectory=$HOMEDIR
ExecStart=/usr/local/bin/docker-compose up
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0
#Restart=always
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/storagenode.service > /dev/null
sudo mkdir -p $STORAGEPATH
sudo usermod -aG docker $USER
echo
sudo systemctl daemon-reload
echo
sudo systemctl restart storagenode.service
sleep 6
sudo docker logs storagenode
sudo systemctl enable storagenode.service
echo "sudo docker-compose logs --tail=100 -f storagenode">watch.sh && chmod +x watch.sh
echo "sudo docker exec -it storagenode /app/dashboard.sh">dashboard.sh && chmod +x dashboard.sh
sudo docker-compose pull watchtower
sudo docker-compose pull storagenode
sudo docker ps -a
echo
echo ----------------------------------------------------------
echo Finished!
res2=$(date +%s.%N)
dt=$(echo "$res2 - $res1" | bc)
dd=$(echo "$dt/86400" | bc)
dt2=$(echo "$dt-86400*$dd" | bc)
dh=$(echo "$dt2/3600" | bc)
dt3=$(echo "$dt2-3600*$dh" | bc)
dm=$(echo "$dt3/60" | bc)
ds=$(echo "$dt3-60*$dm" | bc)
LC_NUMERIC=C printf "Total runtime: %d:%02d:%02d:%02.4f\n" $dd $dh $dm $ds
echo
echo
echo Now point your browser to $IP:$STORJPORT2 and you will see the beautiful STORJ dashboard. If not check the docker_compose.yml and find issues with watch systemctl status storagenode.service.
echo
echo Tip: Run this script again with var cleanup to delete all files that were needed during installation progress.
exit