solana/multinode-demo/setup.sh

123 lines
2.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2018-08-27 09:13:53 -07:00
#
# Creates a fullnode configuration
#
2018-06-24 10:10:55 -07:00
2018-06-23 11:52:12 -07:00
here=$(dirname "$0")
2018-06-24 10:10:55 -07:00
# shellcheck source=multinode-demo/common.sh
source "$here"/common.sh
2018-06-23 11:52:12 -07:00
2018-06-28 16:08:59 -07:00
usage () {
exitcode=0
if [[ -n "$1" ]]; then
exitcode=1
echo "Error: $*"
fi
2018-06-28 16:08:59 -07:00
cat <<EOF
usage: $0 [-n num_tokens] [-l] [-p] [-t node_type]
2018-06-28 16:08:59 -07:00
Creates a fullnode configuration
-n num_tokens - Number of tokens to create
-l - Detect network address from local machine configuration, which
may be a private IP address unaccessible on the Intenet (default)
-p - Detect public address using public Internet servers
-t node_type - Create configuration files only for this kind of node. Valid
options are validator or leader. Creates configuration files
for both by default
2018-06-28 16:08:59 -07:00
EOF
exit $exitcode
2018-06-28 16:08:59 -07:00
}
ip_address_arg=-l
num_tokens=1000000000
node_type_leader=true
node_type_validator=true
while getopts "h?n:lpt:" opt; do
2018-06-28 16:08:59 -07:00
case $opt in
h|\?)
usage
exit 0
;;
l)
ip_address_arg=-l
;;
2018-06-28 16:08:59 -07:00
p)
ip_address_arg=-p
2018-06-28 16:08:59 -07:00
;;
n)
num_tokens="$OPTARG"
;;
t)
node_type="$OPTARG"
case $OPTARG in
leader)
node_type_leader=true
node_type_validator=false
;;
validator)
node_type_leader=false
node_type_validator=true
;;
*)
usage "Error: unknown node type: $node_type"
;;
esac
;;
*)
usage "Error: unhandled option: $opt"
;;
2018-06-28 16:08:59 -07:00
esac
done
2018-06-24 10:10:55 -07:00
set -e
for i in "$SOLANA_CONFIG_DIR" "$SOLANA_CONFIG_VALIDATOR_DIR" "$SOLANA_CONFIG_PRIVATE_DIR"; do
echo "Cleaning $i"
rm -rvf "$i"
mkdir -p "$i"
done
if $node_type_leader; then
leader_address_args=("$ip_address_arg")
leader_id_path="$SOLANA_CONFIG_PRIVATE_DIR"/leader-id.json
mint_id_path="$SOLANA_CONFIG_PRIVATE_DIR"/mint-id.json
$solana_keygen -o "$leader_id_path"
echo "Creating $mint_id_path with $num_tokens tokens"
$solana_keygen -o "$mint_id_path"
echo "Creating $SOLANA_CONFIG_DIR/leader.json"
2018-12-06 13:00:56 -08:00
$solana_fullnode_config \
--keypair="$leader_id_path" \
"${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json
echo "Creating $SOLANA_CONFIG_DIR/ledger"
2018-12-06 13:00:56 -08:00
$solana_genesis \
--num_tokens "$num_tokens" \
--mint "$mint_id_path" \
--bootstrap-leader-keypair "$leader_id_path" \
2018-12-06 13:00:56 -08:00
--ledger "$SOLANA_CONFIG_DIR"/ledger \
ls -lhR "$SOLANA_CONFIG_DIR"/
ls -lhR "$SOLANA_CONFIG_PRIVATE_DIR"/
fi
2018-06-24 10:10:55 -07:00
if $node_type_validator; then
validator_address_args=("$ip_address_arg" -b 9000)
validator_id_path="$SOLANA_CONFIG_PRIVATE_DIR"/validator-id.json
$solana_keygen -o "$validator_id_path"
echo "Creating $SOLANA_CONFIG_VALIDATOR_DIR/validator.json"
2018-12-06 13:00:56 -08:00
$solana_fullnode_config \
--keypair="$validator_id_path" \
"${validator_address_args[@]}" > "$SOLANA_CONFIG_VALIDATOR_DIR"/validator.json
ls -lhR "$SOLANA_CONFIG_VALIDATOR_DIR"/
fi