-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-only
179 lines (144 loc) · 3.57 KB
/
config-only
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
#### config ####
## install directory -- default: ${HOME}
DIR="/opt"
## max inbound connections -- default: 8
MAXINBOUND=50
## BIP37 (boolean)
BIP="true"
## HTTP-HOST -- default: 127.0.0.1
HTTPHOST="0.0.0.0"
## Nameserver
NSHOST="0.0.0.0"
NSPORT=5349
## Recursive server
RSHOST="0.0.0.0"
RSPORT=5350
## Log options
LOGLEVEL="info"
## Node api key
APIKEY="<key>"
#### script ####
if [ ! -f "/etc/debian_version" ]; then
echo "Install script only for Ubuntu/Debian!"
exit 1
fi
B="\e[1m"
G="\e[32m"
R="\e[31m"
E="\e[0m"
NL='
'
function check_hsd {
if pgrep -x "hsd-worker" >/dev/null 2>&1; then
HSDVERSION="$(hsd-cli info|jq -r .version)"
HSDRUNNING="true"
else
HSDRUNNING="false"
fi
}
function initialsetup {
sudo timedatectl set-timezone UTC
sudo apt-get update && apt-get upgrade -y
NODE="$(which node)"
if [ ! "$NODE" ]; then
echo -e "${R}Node not (properly) installed!${E}"
exit 1
fi
}
function install_hsd {
cd ${DIR}/hsd
}
function service_hsd {
HSDSVCFILE="/lib/systemd/system/hsd.service"
HSDSVCTXT=$(echo -e "[Unit]
Description=hsd
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
Environment=HSD_PREFIX=${DIR}/.hsd
ExecStart=${NODE} ${DIR}/hsd/bin/hsd
[Install]
WantedBy=multi-user.target
")
echo "$HSDSVCTXT" | sudo tee $HSDSVCFILE > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable hsd.service
}
function config_hsd {
MYIP=$(dig @resolver4.opendns.com myip.opendns.com +short)
HSDCFGFILE="/opt/.hsd/hsd.conf"
HSDCFGTXT=$(echo -e "log-level: ${LOGLEVEL}
listen: true
bip37: $BIP
public-host: $MYIP
http-host: $HTTPHOST
max-inbound: $MAXINBOUND
ns-host: $NSHOST
ns-port: $NSPORT
rs-host: $RSHOST
rs-port: $RSPORT
api-key: $APIKEY
")
mkdir -p ${DIR}/.hsd
echo "$HSDCFGTXT" >$HSDCFGFILE
}
function start_hsd {
sudo systemctl start hsd
sleep 5s
if [ "$(systemctl is-active hsd)" = "active" ]; then
HSDVERSION="$(hsd-cli info|jq -r .version)"
echo -e "${NL}${G}###${E}"
echo -e "${NL}${G}hsd $HSDVERSION successfully started as service!${E}"
else
echo -e "${NL}${R}hsd service not started!${E}"
exit 1
fi
}
function show_config {
echo -e "
${B}Current hsd config file${E} ($HSDCFGFILE):
###
$(cat $HSDCFGFILE)
###
Syncing the chain may take few hours (depending on hardware/env.)
Currently hsd is set as non-listening node.
Some Commands:
hsd service status: ${B}systemctl status hsd${E}
hsd service restart: ${B}sudo systemctl restart hsd${E}
"
if [ "$LISTEN" = "true" ]; then
echo -e "${G}After the chain is 100% synced${E} please ${G}restart hsd${E} or even reboot
your system to change hsd to a listening public full node with $MAXINBOUND
allowed inbound connections. This is great support for Handshake!"
fi
}
function show_block {
echo -e "${NL}hsd is running as a service, you can stop this script at any time (Ctrl-C)${NL}"
while true; do
HSDINFO="$(hsd-cli info)"
BLOCK="$(echo "$HSDINFO"|jq .chain.height)"
PROGESS="$(echo "$HSDINFO"|jq .chain.progress)"
PROGRESS=$(awk "BEGIN {printf \"%.1f\n\", ${PROGESS}*100}")
echo -n -e "\r${G}hsd $HSDVERSION is syncing${E} - current block height: ${G}$BLOCK (${PROGRESS%\.*}%)${E}"
for i in {1..10}; do
sleep 1s
printf '.'
done
done
}
# Main
check_hsd
if [ "$HSDRUNNING" = "false" ]; then
initialsetup
install_hsd
service_hsd
config_hsd false
start_hsd
show_config
config_hsd $LISTEN
fi
show_block
exit