-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstory_node_tool.sh
350 lines (271 loc) · 9.92 KB
/
story_node_tool.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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
GO_VERSION="1.22.7"
STORY_VERSION="v0.11.0"
GETH_VERSION="v0.9.4"
NETWORK="iliad"
USERNAME=$(whoami)
SEEDS="6a07e2f396519b55ea05f195bac7800b451983c0@story-seed.mandragora.io:26656,51ff395354c13fab493a03268249a74860b5f9cc@story-testnet-seed.itrocket.net:26656,[email protected]:26656"
PEERS="2f372238bf86835e8ad68c0db12351833c40e8ad@story-testnet-rpc.itrocket.net:26656,d5519e378247dfb61dfe90652d1fe3e2b3005a5b@story-testnet.rpc.kjnodes.com:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:27136,[email protected]:26656,[email protected]:47656,[email protected]:16756,[email protected]:42656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:33556,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656"
MAX_INBOUND_PEERS=300
MAX_OUTBOUND_PEERS=200
STORY_PORT=266
if [ "$USERNAME" == "root" ]; then
STORY_HOME="/root/.story/story"
GETH_HOME="/root/.story/geth"
BIN_PATH="/root/go/bin/"
else
STORY_HOME="/home/$USERNAME/.story/story"
GETH_HOME="/home/$USERNAME/.story/geth"
BIN_PATH="/home/$USERNAME/go/bin/"
fi
menu() {
echo "Story Relaxed Automation"
echo "1. Install Node"
echo "2. Check Story Version"
echo "3. Check Geth Version"
echo "4. Check Sync Status"
echo "5. Check Story Logs"
echo "6. Check Geth Logs"
echo "7. Restart Geth"
echo "8. Restart Story"
echo "9. Restart all"
echo "10. Quit"
echo ""
echo -n "Please enter your choice: "
}
install_node() {
ask_install_versions
update_system
install_dependencies
install_go
build_story
build_geth
init_network
update_config
create_story_systemd
create_geth_systemd
load_genesis
load_addrbook
echo "Enable Universal Firewall with Story and SSH exceptions? Y/n"
read -r ENABLE_FIREWALL
if [ "$ENABLE_FIREWALL" == "Y" ]; then
enable_ufw
fi
download_apply_snapshot
start_story
start_geth
}
ask_install_versions() {
echo "Please enter Story version to install (blank for ${STORY_VERSION}):"
read -r TEMP_VERSION
if [ ! -z "${TEMP_VERSION}" ]; then
STORY_VERSION=$TEMP_VERSION
fi
echo "Please enter Story version to install (blank for ${GETH_VERSION}):"
read -r TEMP_VERSION
if [ ! -z "${TEMP_VERSION}" ]; then
GETH_VERSION=$TEMP_VERSION
fi
}
update_system() {
echo "Updating the system"
sudo apt update && sudo apt upgrade -y
}
install_dependencies() {
echo "Install other dependencies"
sudo apt install curl tar wget clang pkg-config libssl-dev libleveldb-dev jq build-essential git make ncdu screen unzip bc fail2ban -y
}
install_go() {
echo "Install Go"
cd $HOME
wget "https://go.dev/dl/go$GO_VERSION.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go$GO_VERSION.linux-amd64.tar.gz"
rm "go$GO_VERSION.linux-amd64.tar.gz"
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
}
build_story() {
echo "Build Story"
rm -rf $HOME/story
git clone https://github.com/piplabs/story
cd $HOME/story
git checkout $STORY_VERSION
go build -o story ./client
cp ./story $HOME/go/bin/
cd $HOME
}
build_geth() {
echo "Build Geth"
rm -rf $HOME/story-geth
git clone https://github.com/piplabs/story-geth story-geth
cd $HOME/story-geth
git checkout $GETH_VERSION
make geth
cp ./build/bin/geth $HOME/go/bin/
cd $HOME
}
init_network() {
echo "Init ${NETWORK}"
$HOME/go/bin/story init --network $NETWORK
}
update_config() {
echo "Please enter the moniker:"
read -r MONIKER
sed -i -e "s|moniker = \"[^\"]*\"|moniker = \"$MONIKER\"|g" $STORY_HOME/config/config.toml
echo "Please enter the first 3 number for protocol port (default 266 if blank):"
read -r STORY_PORT
sed -i "s%:26658%:${STORY_PORT}58%g" $STORY_HOME/config/config.toml
sed -i "s%:26657%:${STORY_PORT}57%g" $STORY_HOME/config/config.toml
sed -i "s%:26656%:${STORY_PORT}56%g" $STORY_HOME/config/config.toml
sed -i "s%:26660%:${STORY_PORT}60%g" $STORY_HOME/config/config.toml
sed -i -e "s/^seeds *=.*/seeds = \"$SEEDS\"/" $STORY_HOME/config/config.toml
sed -i -e "s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $STORY_HOME/config/config.toml
sed -i -e "s|max_num_inbound_peers = [^\"]*|max_num_inbound_peers = $MAX_INBOUND_PEERS|g" $STORY_HOME/config/config.toml
sed -i -e "s|max_num_outbound_peers = [^\"]*|max_num_outbound_peers = $MAX_OUTBOUND_PEERS|g" $STORY_HOME/config/config.toml
sed -i -e "s|indexer = \"[^\"]*\"|indexer = \"null\"|g" $STORY_HOME/config/config.toml
sed -i -e "s|prometheus = false|prometheus = true|g" $STORY_HOME/config/config.toml
sed -i -e "s|namespace = \"[^\"]*\"|namespace = \"tendermint\"|g" $STORY_HOME/config/config.toml
sed -i "s%:1317%:${STORY_PORT}17%g" $STORY_HOME/config/story.toml
sed -i "s%:8551%:${STORY_PORT}51%g" $STORY_HOME/config/story.toml
}
enable_ufw() {
echo "Enable UFW"
SSH_PORT=$(echo ${SSH_CLIENT##* })
sudo ufw allow $SSH_PORT
sudo ufw allow ${STORY_PORT}45/tcp
sudo ufw allow ${STORY_PORT}46/tcp
sudo ufw allow ${STORY_PORT}03/tcp
sudo ufw allow ${STORY_PORT}03/udp
sudo ufw allow ${STORY_PORT}56/tcp
sudo ufw allow ${STORY_PORT}60/tcp
sudo ufw enable
}
create_story_systemd() {
echo "Create Story service"
sudo tee /etc/systemd/system/story.service > /dev/null <<EOF
[Unit]
Description=Story Service
After=network.target
[Service]
User=$USERNAME
ExecStart=$BIN_PATH/story run
Restart=on-failure
RestartSec=3
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable story.service
}
# Create Geth systemd
create_geth_systemd() {
echo "Create Story service"
sudo tee /etc/systemd/system/story-geth.service > /dev/null <<EOF
[Unit]
Description=Story Geth Client
After=network.target
[Service]
User=$USERNAME
ExecStart=$BIN_PATH/story-geth --iliad --syncmode full --authrpc.port ${STORY_PORT}51 --port ${STORY_PORT}03 --discovery.port ${STORY_PORT}03 --metrics --pprof
Restart=on-failure
RestartSec=3
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable story.service
}
load_genesis() {
echo "Load Genesis"
wget -O $STORY_HOME/config/genesis.json https://snapshots.polkachu.com/testnet-genesis/story/genesis.json
}
load_addrbook() {
echo "Load addrbook"
wget -O $STORY_HOME/config/addrbook.json https://snapshots.polkachu.com/testnet-addrbook/story/addrbook.json
}
download_apply_snapshot() {
echo "Apply Snapshots"
sudo rm -rf $GETH_HOME/iliad/geth/chaindata
sudo rm -rf $STORY_HOME/data
wget -O geth_snapshot.lz4 https://snapshots2.mandragora.io/story/geth_snapshot.lz4
wget -O story_snapshot.lz4 https://snapshots2.mandragora.io/story/story_snapshot.lz4
lz4 -c -d geth_snapshot.lz4 | tar -xv -C $GETH_HOME/iliad/geth
lz4 -c -d story_snapshot.lz4 | tar -xv -C $STORY_HOME
sudo rm -v geth_snapshot.lz4
sudo rm -v story_snapshot.lz4
}
start_story() {
echo "Start Story"
sudo systemctl start story
}
start_geth() {
echo "Start Geth"
sudo systemctl start story-geth
}
check_sync_status() {
RPC_PORT=$(grep '^laddr.*57"$' $STORY_HOME/config/config.toml | sed -E 's/^.*(.{5})"$/\1/')
local_height=$(curl -s localhost:${RPC_PORT}/status | jq -r '.result.sync_info.latest_block_height')
local_time=$(curl -s localhost:${RPC_PORT}/status | jq -r '.result.sync_info.latest_block_height')
network_height=$(curl -s https://story-testnet-rpc.polkachu.com/status | jq -r '.result.sync_info.latest_block_height')
network_time=$(curl -s https://story-testnet-rpc.polkachu.com/status | jq -r '.result.sync_info.latest_block_time')
difference=$((network_height - local_height))
printf "%-20s %-20s %-20s %-30s %-20s\n" "Local Height" "Local Time" "Network Height" "Network Time" "Blocks Difference"
printf "%-20s %-20s %-20s %-30s %-20s\n" "$local_height" "$local_time" "$network_height" "$network_time" "$difference"
read
}
check_story_version() {
story version
echo -e "\nPress the Enter key to continue."
read
}
check_geth_version() {
geth version
echo -e "\nPress the Enter key to continue."
read
}
check_story_logs() {
sudo journalctl -u story -f -o cat
}
check_geth_logs() {
sudo journalctl -u story-geth -f -o cat
}
restart_geth() {
echo "Restart geth"
sudo systemctl restart story-geth
read
}
restart_story() {
echo "Restart story"
sudo systemctl restart story
read
}
restart_all() {
echo "Stop Geth"
sudo systemctl stop story-geth
echo "Stop Story"
sudo systemctl stop story
echo "Start Geth"
sudo systemctl start story-geth
echo "Start Story"
sudo systemctl start story
}
#Main
while true; do
menu
read choice
case $choice in
1) install_node ;;
2) check_story_version ;;
3) check_geth_version ;;
4) check_sync_status ;;
5) check_story_logs ;;
6) check_geth_logs ;;
7) restart geth ;;
8) restart story ;;
9) restart all ;;
10) exit 0 ;;
*) ;;
esac
done