2018-01-29 21:26:27 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
configure_client() {
|
|
|
|
|
|
|
|
local client_config="$HOME/.tezos-client/config"
|
|
|
|
mkdir -p "$client_dir" "$HOME/.tezos-client"
|
|
|
|
|
|
|
|
if [ ! -f "$client_config" ]; then
|
|
|
|
"$client" --base-dir "$client_dir" \
|
2018-03-07 14:31:42 +04:00
|
|
|
--addr "$NODE_HOST" --port "$NODE_RPC_PORT" \
|
2018-01-29 21:26:27 +04:00
|
|
|
config init --output "$client_config" >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
"$client" --base-dir "$client_dir" \
|
2018-03-07 14:31:42 +04:00
|
|
|
--addr "$NODE_HOST" --port "$NODE_RPC_PORT" \
|
2018-01-29 21:26:27 +04:00
|
|
|
config update >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_for_the_node_to_be_ready() {
|
|
|
|
local count=0
|
2018-04-16 02:44:24 +04:00
|
|
|
if "$client" rpc get /chains/main/blocks/head/hash >/dev/null 2>&1; then return; fi
|
2018-01-29 21:26:27 +04:00
|
|
|
printf "Waiting for the node to initialize..."
|
|
|
|
sleep 1
|
2018-04-16 02:44:24 +04:00
|
|
|
while ! "$client" rpc get /chains/main/blocks/head/hash >/dev/null 2>&1
|
2018-01-29 21:26:27 +04:00
|
|
|
do
|
|
|
|
count=$((count+1))
|
|
|
|
if [ "$count" -ge 30 ]; then
|
|
|
|
echo " timeout."
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
printf "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo " done."
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_for_the_node_to_be_bootstraped() {
|
|
|
|
wait_for_the_node_to_be_ready
|
|
|
|
echo "Waiting for the node to synchronize with the network..."
|
|
|
|
"$client" bootstrapped
|
|
|
|
}
|
|
|
|
|
|
|
|
launch_node() {
|
|
|
|
|
2018-06-19 07:29:34 +04:00
|
|
|
mkdir -p "$node_dir"
|
2018-01-29 21:26:27 +04:00
|
|
|
|
|
|
|
# Check if we have to reset the chain because the image we want to
|
|
|
|
# run has a incompatible version with the blockchain we have stored
|
|
|
|
# locally on disk
|
|
|
|
|
|
|
|
local image_version="$(cat "/usr/local/share/tezos/alphanet_version")"
|
|
|
|
echo "Current public chain: $image_version."
|
2018-04-20 20:41:01 +04:00
|
|
|
local local_data_version=""
|
|
|
|
if [ -f "$node_dir/alphanet_version" ]; then
|
|
|
|
local_data_version="$(cat "$node_dir/alphanet_version")"
|
2018-01-29 21:26:27 +04:00
|
|
|
echo "Local chain data: $local_data_version."
|
2018-04-20 20:41:01 +04:00
|
|
|
fi
|
|
|
|
if [ "$local_data_version" != "$image_version" ]; then
|
|
|
|
echo "Removing outdated chain data..."
|
2019-02-26 21:34:30 +04:00
|
|
|
if [ -f "$node_data_dir/identity.json" ]; then \
|
|
|
|
mv "$node_data_dir/identity.json" /tmp
|
2018-04-20 20:41:01 +04:00
|
|
|
fi
|
2018-06-19 07:29:34 +04:00
|
|
|
rm -rf "$node_data_dir"
|
2018-06-18 22:38:20 +04:00
|
|
|
rm -rf "$client_dir/blocks"
|
2018-06-18 18:50:23 +04:00
|
|
|
rm -rf "$client_dir/nonces"
|
|
|
|
rm -rf "$client_dir/endorsements"
|
2019-02-26 21:34:30 +04:00
|
|
|
if [ -f "/tmp/identity.json" ]; then \
|
|
|
|
mkdir -p "$node_data_dir"
|
|
|
|
mv /tmp/identity.json "$node_data_dir/"
|
2018-01-29 21:26:27 +04:00
|
|
|
fi
|
2018-04-20 20:41:01 +04:00
|
|
|
cp "/usr/local/share/tezos/alphanet_version" \
|
|
|
|
"$node_dir/alphanet_version"
|
2018-01-29 21:26:27 +04:00
|
|
|
fi
|
|
|
|
|
2018-06-19 07:29:34 +04:00
|
|
|
mkdir -p "$node_data_dir"
|
|
|
|
|
|
|
|
if [ ! -f "$node_data_dir/config.json" ]; then
|
|
|
|
echo "Configuring the node..."
|
|
|
|
"$node" config init \
|
|
|
|
--data-dir "$node_data_dir" \
|
|
|
|
--rpc-addr ":$NODE_RPC_PORT" \
|
|
|
|
"$@"
|
|
|
|
else
|
|
|
|
echo "Updating the node configuration..."
|
|
|
|
"$node" config update \
|
|
|
|
--data-dir "$node_data_dir" \
|
|
|
|
--rpc-addr ":$NODE_RPC_PORT" \
|
|
|
|
"$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in "$@"; do
|
|
|
|
if [ "$i" = "--help" ] ; then exit 0; fi
|
|
|
|
done
|
2018-04-20 20:41:01 +04:00
|
|
|
|
2018-01-29 21:26:27 +04:00
|
|
|
# Generate a new identity if not present
|
|
|
|
|
2018-06-18 18:50:23 +04:00
|
|
|
if [ ! -f "$node_data_dir/identity.json" ]; then
|
2018-01-29 21:26:27 +04:00
|
|
|
echo "Generating a new node identity..."
|
2018-07-13 02:06:35 +04:00
|
|
|
"$node" identity generate "${IDENTITY_POW:-26}". \
|
2018-06-18 18:50:23 +04:00
|
|
|
--data-dir "$node_data_dir"
|
2018-01-29 21:26:27 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
configure_client
|
|
|
|
|
|
|
|
# Launching the node
|
|
|
|
|
2018-06-18 18:50:23 +04:00
|
|
|
exec "$node" run --data-dir "$node_data_dir"
|
2018-01-29 21:26:27 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
launch_baker() {
|
|
|
|
configure_client
|
|
|
|
wait_for_the_node_to_be_bootstraped
|
2018-06-18 18:50:23 +04:00
|
|
|
exec "$baker" --base-dir "$client_dir" \
|
|
|
|
--addr "$NODE_HOST" --port "$NODE_RPC_PORT" \
|
2019-03-05 13:24:04 +04:00
|
|
|
run with local node "$node_data_dir" "$@"
|
2018-01-29 21:26:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
launch_endorser() {
|
|
|
|
configure_client
|
|
|
|
wait_for_the_node_to_be_bootstraped
|
2018-06-18 18:50:23 +04:00
|
|
|
exec "$endorser" --base-dir "$client_dir" \
|
|
|
|
--addr "$NODE_HOST" --port "$NODE_RPC_PORT" \
|
2019-03-05 13:24:04 +04:00
|
|
|
run "$@"
|
2018-01-29 21:26:27 +04:00
|
|
|
}
|
2018-06-25 19:39:36 +04:00
|
|
|
|
|
|
|
launch_accuser() {
|
|
|
|
configure_client
|
|
|
|
wait_for_the_node_to_be_bootstraped
|
|
|
|
exec "$accuser" --base-dir "$client_dir" \
|
|
|
|
--addr "$NODE_HOST" --port "$NODE_RPC_PORT" \
|
2019-03-05 13:24:04 +04:00
|
|
|
run "$@"
|
2018-06-25 19:39:36 +04:00
|
|
|
}
|