forked from WhenLamboMoon/docker-zen-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·233 lines (201 loc) · 6.92 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
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
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
print_status() {
echo
echo "## $1"
echo
}
if [[ $# -lt 4 ]]; then
echo "Execution format ./install.sh stakeaddr email fqdn region (eu, na or sea) [shieldaddrkey]"
exit
fi
# Installation variables
stakeaddr=${1}
email=${2}
fqdn=${3}
region=${4}
shieldaddrkey=$5
testnet=0
rpcpassword=$(head -c 32 /dev/urandom | base64)
print_status "Installing the ZenCash node..."
echo "#########################"
echo "fqdn: $fqdn"
echo "email: $email"
echo "stakeaddr: $stakeaddr"
echo "#########################"
# Create swapfile if less then 4GB memory
totalmem=$(free -m | awk '/^Mem:/{print $2}')
totalswp=$(free -m | awk '/^Swap:/{print $2}')
totalm=$(($totalmem + $totalswp))
if [ $totalm -lt 4000 ]; then
print_status "Server memory is less than 4GB..."
if ! grep -q '/swapfile' /etc/fstab ; then
print_status "Creating a 4GB swapfile..."
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
fi
fi
# Populating Cache
print_status "Populating apt-get cache..."
apt-get update
print_status "Installing packages required for setup..."
apt-get install -y docker.io apt-transport-https lsb-release curl fail2ban unattended-upgrades ufw > /dev/null 2>&1
systemctl enable docker
systemctl start docker
print_status "Creating the docker mount directories..."
mkdir -p /mnt/zen/{config,data,zcash-params,certs}
print_status "Installing acme container service..."
cat <<EOF > /etc/systemd/system/acme-sh.service
[Unit]
Description=acme.sh container
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=10m
Restart=always
ExecStartPre=-/usr/bin/docker stop acme-sh
ExecStartPre=-/usr/bin/docker rm acme-sh
# Always pull the latest docker image
ExecStartPre=/usr/bin/docker pull neilpang/acme.sh
ExecStart=/usr/bin/docker run --rm --net=host -v /mnt/zen/certs:/acme.sh --name acme-sh neilpang/acme.sh daemon
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable acme-sh
systemctl restart acme-sh
print_status "Waiting for acme-sh to come up..."
until docker exec -it acme-sh --list
do
echo ".."
sleep 15
done
print_status "Issusing cert for $fqdn..."
docker exec acme-sh --issue -d $fqdn --standalone
# Note: error code 2 means cert already isssued
if [ $? -eq 1 ]; then
print_status "Error provisioning certificate for domain.. exiting"
exit 1
fi
print_status "Creating the zen configuration."
cat <<EOF > /mnt/zen/config/zen.conf
rpcport=18231
rpcallowip=127.0.0.0/24
server=1
# Docker doesn't run as daemon
daemon=0
listen=1
#txindex=1
logtimestamps=1
### testnet config
testnet=$testnet
rpcuser=user
rpcpassword=$rpcpassword
tlscertpath=/mnt/zen/certs/$fqdn/$fqdn.cer
tlskeypath=/mnt/zen/certs/$fqdn/$fqdn.key
EOF
print_status "Creating the secnode config..."
mkdir -p /mnt/zen/secnode/
echo -n $email > /mnt/zen/secnode/email
echo -n $fqdn > /mnt/zen/secnode/fqdn
echo -n '127.0.0.1' > /mnt/zen/secnode/rpcallowip
echo -n '127.0.0.1' > /mnt/zen/secnode/rpcbind
echo -n '18231' > /mnt/zen/secnode/rpcport
echo -n 'user' > /mnt/zen/secnode/rpcuser
echo -n $rpcpassword > /mnt/zen/secnode/rpcpassword
echo -n 'ts1.eu,ts1.na,ts1.sea' > /mnt/zen/secnode/servers
echo -n "ts1.$region" > /mnt/zen/secnode/home
echo -n $region > /mnt/zen/secnode/region
echo -n 'http://devtracksys.secnodes.com' > /mnt/zen/secnode/serverurl
echo -n $stakeaddr > /mnt/zen/secnode/stakeaddr
echo -n '4' > /mnt/zen/secnode/ipv
print_status "Installing zend service..."
cat <<EOF > /etc/systemd/system/zen-node.service
[Unit]
Description=Zen Daemon Container
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=10m
Restart=always
ExecStartPre=-/usr/bin/docker stop zen-node
ExecStartPre=-/usr/bin/docker rm zen-node
# Always pull the latest docker image
ExecStartPre=/usr/bin/docker pull whenlambomoon/zend:latest
ExecStart=/usr/bin/docker run --rm --net=host -p 9033:9033 -p 18231:18231 -v /mnt/zen:/mnt/zen --name zen-node whenlambomoon/zend:latest
[Install]
WantedBy=multi-user.target
EOF
print_status "Installing secnodetracker service..."
cat <<EOF > /etc/systemd/system/zen-secnodetracker.service
[Unit]
Description=Zen Secnodetracker Container
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=10m
Restart=always
ExecStartPre=-/usr/bin/docker stop zen-secnodetracker
ExecStartPre=-/usr/bin/docker rm zen-secnodetracker
# Always pull the latest docker image
ExecStartPre=/usr/bin/docker pull whenlambomoon/secnodetracker:latest
#ExecStart=/usr/bin/docker run --init --rm --net=host -v /mnt/zen:/mnt/zen --name zen-secnodetracker whenlambomoon/secnodetracker:latest
ExecStart=/usr/bin/docker run --rm --net=host -v /mnt/zen:/mnt/zen --name zen-secnodetracker whenlambomoon/secnodetracker:latest
[Install]
WantedBy=multi-user.target
EOF
print_status "Enabling and starting container services..."
systemctl daemon-reload
systemctl enable zen-node
systemctl restart zen-node
systemctl enable zen-secnodetracker
systemctl restart zen-secnodetracker
print_status "Enabling basic firewall services..."
ufw default allow outgoing
ufw default deny incoming
#ufw allow ssh/tcp
#ufw limit ssh/tcp
#ufw allow http/tcp
#ufw allow https/tcp
ufw allow 9033/tcp
#ufw allow 19033/tcp
ufw --force enable
print_status "Enabling fail2ban services..."
systemctl enable fail2ban
systemctl start fail2ban
print_status "Waiting for node to fetch params ..."
until docker exec -it zen-node /usr/local/bin/gosu user zen-cli getinfo
do
echo ".."
sleep 30
done
if [[ $(docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_listaddresses | wc -l) -eq 2 ]]; then
if [[ -n $shieldaddrkey ]]; then
print_status "Importing Z address private key (this may take several minutes!)"
docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_importkey $shieldaddrkey
print_status "Done. The available Z address is"
docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_listaddresses
print_status "With balance:"
docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_gettotalbalance
else
print_status "Generating shield address for node... you will need to send 4x 0.025 ZEN to this address:"
zaddr=`docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_getnewaddress`
echo $zaddr
print_status "Private key is:"
docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_exportkey $zaddr
fi
print_status "Restarting secnodetracker"
systemctl restart zen-secnodetracker
else
print_status "Node already has shield address(es)..."
docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_listaddresses
print_status "With total balance:"
docker exec -it zen-node /usr/local/bin/gosu user zen-cli z_gettotalbalance
print_status "You may want to send multiple small transactions to make up 0.1 ZEN to the above address."
fi
print_status "Install Finished"
echo "Please wait until the blocks are up to date..."
## TODO: Post the shield address back to our API