-
Notifications
You must be signed in to change notification settings - Fork 0
/
statesync
executable file
·96 lines (83 loc) · 3.2 KB
/
statesync
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
#!/bin/bash
startup_check() {
# Ensure root user is not running the script
if [ "$EUID" = 0 ]; then
clear
cat << EOF
*** You are attempting to run this script as root user ***
This is poor practice,
please try again as a created user with sudo privledges
EOF
exit
fi
# Ensure needed programs are installed
if ! command -v jq &> /dev/null; then
clear
echo "jq is not installed, please refer to README for dependency list"
exit
elif ! command -v curl &> /dev/null; then
clear
echo "curl is not installed, please refer to README for dependency list"
exit
elif ! command -v wget &> /dev/null; then
clear
echo "wget is not installed, please refer to README for dependency list"
exit
elif ! command -v xxd &> /dev/null; then
clear
echo "xxd is not installed, please refer to README for dependency list"
exit
fi
}
backup(){
clear
echo -e "Backup ${HOME}/.und_mainchain to ${HOME}/.und_mainchain.bak?\n"
echo -e "You need atleast $(du -sh $HOME/.und_mainchain | awk '{print $1}') available this operation\n"
while true
do
read -p "Yes or No [y/n] > " -n 1 key
case $key in
y)
cp -r $HOME/.und_mainchain $HOME/.und_mainchain.bak
clear
echo -e "${HOME}.und_mainchain.bak created\n"
break
;;
n)
clear
break
;;
*)
clear
backup
;;
esac
done
}
startup_check
# backup
echo "Starting..."
sleep 5
sudo systemctl stop und
mv $HOME/.und_mainchain/data/priv_validator_state.json $HOME/.und_mainchain/priv_validator_state.json
rm -rf $HOME/.und_mainchain/data/*
rm -rf $HOME/.und_mainchain/config/addrbook.json
mv $HOME/.und_mainchain/priv_validator_state.json $HOME/.und_mainchain/data/priv_validator_state.json
SEEDS=0c2b65bc604a18a490f5f55bb7b4140cfb512ced@seed1.unification.io:26656,[email protected]:26656
HANDH_URL=https://rest.unification.io/cosmos/base/tendermint/v1beta1/blocks
HANDH=$(curl -s "$HANDH_URL/latest")
HEIGHT=$(echo $HANDH | jq -r '.block.header.height')
HEIGHT=$((HEIGHT - 5000))
HANDH=$(curl -s "$HANDH_URL/$HEIGHT")
# Decode Base64, then re-encode to HEX
HASH=$(echo $HANDH | jq -r '.block_id.hash' | base64 -d | xxd -p -u -c 100)
RPC="https://rpc1.unification.io:443,https://rpc.unification.chainmasters.ninja:443"
sed -i "s/enable.*/enable = true/" $HOME/.und_mainchain/config/config.toml
sed -i "s/trust_height.*/trust_height = $HEIGHT/" $HOME/.und_mainchain/config/config.toml
sed -i 's/trust_hash.*/trust_hash = "'$HASH'"/' $HOME/.und_mainchain/config/config.toml
sed -i 's|rpc_servers.*|rpc_servers = "'$RPC'"|' $HOME/.und_mainchain/config/config.toml
sed -i 's/discovery_time.*/discovery_time = "30s"/' $HOME/.und_mainchain/config/config.toml
sed -i 's/chunk_request_timeout.*/chunk_request_timeout = "60s"/' $HOME/.und_mainchain/config/config.toml
sed -i 's/seeds.*/seeds = "'$SEEDS'"/' $HOME/.und_mainchain/config/config.toml
sudo systemctl restart und
sudo journalctl -u und -f -o cat