-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·129 lines (111 loc) · 4.24 KB
/
entrypoint.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
#!/bin/sh
# set -x
set -e
apk add jq
NODE_MONIKER="${NODE_MONIKER:-my-first-dfinance-node}"
# LOG_LEVEL="${LOG_LEVEL:-info}"
CHAIN_ID="${CHAIN_ID}"
# GENESIS_RPC_ENDPOINT="${GENESIS_RPC_ENDPOINT:-https://rpc.dfinance.co/genesis}"
ALLOW_DUPLICATE_IP="${ALLOW_DUPLICATE_IP:-false}"
VM_ADDRESS="${VM_ADDRESS:-dvm:50051}"
VM_DATA_LISTEN="${VM_DATA_LISTEN:-0.0.0.0:50052}"
RPC_LISTEN_ADDRESS="${RPC_LISTEN_ADDRESS:-0.0.0.0}"
function iprintf {
echo -e "\033[0;32m$(date +"%Y.%m.%d %H:%M:%S")\t$@\033[0m"
}
_node_path='/root/.dstation'
_priv_validator_state_file="${_node_path}/data/priv_validator_state.json"
_node_config_path="${_node_path}/config"
_genesis_file="${_node_config_path}/genesis.json"
_app_file="${_node_config_path}/app.toml"
_config_file="${_node_config_path}/config.toml"
_client_file="${_node_config_path}/client.toml"
_vm_file="${_node_config_path}/vm.toml"
_node_key_file="${_node_config_path}/node_key.json"
_priv_validator_key_file="${_node_config_path}/priv_validator_key.json"
mkdir -p ${_node_config_path} ${_node_path}/data
# check if first run
if [[ ! -f "${_node_key_file}" || ! -f "${_priv_validator_key_file}" ]]; then
iprintf "Not found 'node_key.json' or/and 'priv_validator_key.json'"
# iprintf "Remove old configs"
# rm -rf ${_node_config_path}/*
if [[ ! -z "$(ls ${_node_config_path})" ]]; then
_old_folder_path="${_node_config_path}/old_$(date +'%Y.%m.%d_%H%M%S')"
mkdir -p ${_old_folder_path}
iprintf "Copy old files to path: ${_old_folder_path##*/}"
cp ${_node_config_path}/*.{json,toml} ${_old_folder_path}
fi
iprintf "Generate new configs"
./dstation init ${NODE_MONIKER} --chain-id ${CHAIN_ID}
./dstation set-genesis-defaults
fi
if [[ ! -f "${_priv_validator_state_file}" ]]; then
iprintf "Create priv_validator_state.json"
mkdir -p ${_node_path}/data
cat << EOF > ${_priv_validator_state_file}
{
"height": "0",
"round": 0,
"step": 0
}
EOF
fi
if [ ! -z "${GENESIS_RPC_ENDPOINT}" ]; then
iprintf "Download actual genesis.json file from ${GENESIS_RPC_ENDPOINT}"
wget -q ${GENESIS_RPC_ENDPOINT} -O - | jq -r '.result.genesis' > ${_genesis_file}
else
iprintf "Copy local genesis.json file"
if [ "${CHAIN_ID}" == "dn-alpha-mainnet-v1-1-0" ]; then
cp /tmp/genesis/genesis-mainnet.json ${_genesis_file}
elif [ "${CHAIN_ID}" == "dn-testnet-v2" ]; then
cp /tmp/genesis/genesis-testnet.json ${_genesis_file}
fi
fi
# if [ -z "${NODE_SEEDS}" ]; then
# NODE_SEEDS=$(jq -r '
# [
# .app_state.genutil.gentxs[]
# | .value.memo
# ] | join(",")
# ' ${_genesis_file})
# iprintf "Use the following NODE_SEEDS: ${NODE_SEEDS}"
# fi
iprintf "Configure vm.toml from variables"
if [[ ! -z "${VM_ADDRESS}" ]]; then
sed -i "s|vm_address =.*|vm_address = \"${VM_ADDRESS}\"|g" "${_vm_file}"
fi
if [[ ! -z "${VM_DATA_LISTEN}" ]]; then
sed -i "s|vm_data_listen =.*|vm_data_listen = \"${VM_DATA_LISTEN}\"|g" "${_vm_file}"
fi
iprintf "Configure client.toml from variables"
if [[ ! -z "${CHAIN_ID}" ]]; then
sed -i "s|chain-id =.*|chain-id = \"${CHAIN_ID}\"|g" "${_client_file}"
fi
iprintf "Configure config.toml from variables"
if [ ! -z "${EXTERNAL_ADDRESS}" ]; then
sed -i "s|external_address =.*|external_address = \"${EXTERNAL_ADDRESS}\"|g" "${_config_file}"
fi
if [[ ! -z "${ALLOW_DUPLICATE_IP}" ]]; then
sed -i "s|allow_duplicate_ip =.*|allow_duplicate_ip = \"${ALLOW_DUPLICATE_IP}\"|g" "${_config_file}"
fi
if [[ ! -z "${NODE_MONIKER}" ]]; then
sed -i "s|moniker =.*|moniker = \"${NODE_MONIKER}\"|g" "${_config_file}"
fi
if [[ ! -z "${LOG_LEVEL}" ]]; then
sed -i "s|log_level =.*|log_level = \"${LOG_LEVEL}\"|g" "${_config_file}"
fi
if [[ ! -z "${NODE_SEEDS}" ]]; then
sed -i "s|seeds =.*|seeds = \"${NODE_SEEDS}\"|g" "${_config_file}"
fi
if [[ ! -z "${PERSISTENT_PEERS}" ]]; then
sed -i "s|persistent_peers =.*|persistent_peers = \"${PERSISTENT_PEERS}\"|g" "${_config_file}"
fi
if [[ ! -z "${SEED_MODE}" ]]; then
sed -i "s|seed_mode =.*|seed_mode = \"${SEED_MODE}\"|g" "${_config_file}"
fi
if [[ ! -z "${RPC_LISTEN_ADDRESS}" ]]; then
iprintf "Change RPC laddr from 'tcp://.*:26657' to 'tcp://${RPC_LISTEN_ADDRESS}:26657'"
sed -i "s|^laddr =.*:26657.*|laddr = \"tcp://${RPC_LISTEN_ADDRESS}:26657\"|g" "${_config_file}"
fi
iprintf "Start node"
exec "$@"