2018-06-18 15:23:56 -07:00
|
|
|
#!/bin/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 () {
|
2018-07-02 08:08:14 -07:00
|
|
|
exitcode=0
|
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
exitcode=1
|
|
|
|
echo "Error: $*"
|
|
|
|
fi
|
2018-06-28 16:08:59 -07:00
|
|
|
cat <<EOF
|
2018-07-02 08:08:14 -07:00
|
|
|
usage: $0 [-n num_tokens] [-l] [-p] [-t node_type]
|
2018-06-28 16:08:59 -07:00
|
|
|
|
|
|
|
Creates a fullnode configuration
|
|
|
|
|
2018-06-29 16:49:23 -07:00
|
|
|
-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
|
2018-07-02 08:08:14 -07:00
|
|
|
-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
|
2018-07-02 08:08:14 -07:00
|
|
|
exit $exitcode
|
2018-06-28 16:08:59 -07:00
|
|
|
}
|
|
|
|
|
2018-06-29 16:49:23 -07:00
|
|
|
ip_address_arg=-l
|
|
|
|
num_tokens=1000000000
|
2018-07-02 08:08:14 -07:00
|
|
|
node_type_leader=true
|
|
|
|
node_type_validator=true
|
2018-09-13 17:58:33 -07:00
|
|
|
node_type_client=true
|
2018-07-02 08:08:14 -07:00
|
|
|
while getopts "h?n:lpt:" opt; do
|
2018-06-28 16:08:59 -07:00
|
|
|
case $opt in
|
|
|
|
h|\?)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2018-06-29 16:49:23 -07:00
|
|
|
l)
|
|
|
|
ip_address_arg=-l
|
|
|
|
;;
|
2018-06-28 16:08:59 -07:00
|
|
|
p)
|
2018-06-29 16:49:23 -07:00
|
|
|
ip_address_arg=-p
|
2018-06-28 16:08:59 -07:00
|
|
|
;;
|
|
|
|
n)
|
|
|
|
num_tokens="$OPTARG"
|
|
|
|
;;
|
2018-07-02 08:08:14 -07:00
|
|
|
t)
|
|
|
|
node_type="$OPTARG"
|
|
|
|
case $OPTARG in
|
|
|
|
leader)
|
|
|
|
node_type_leader=true
|
|
|
|
node_type_validator=false
|
2018-09-13 17:58:33 -07:00
|
|
|
node_type_client=false
|
2018-07-02 08:08:14 -07:00
|
|
|
;;
|
|
|
|
validator)
|
|
|
|
node_type_leader=false
|
|
|
|
node_type_validator=true
|
2018-09-13 17:58:33 -07:00
|
|
|
node_type_client=false
|
|
|
|
;;
|
|
|
|
client)
|
|
|
|
node_type_leader=false
|
|
|
|
node_type_validator=false
|
|
|
|
node_type_client=true
|
2018-07-02 08:08:14 -07:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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
|
2018-06-18 15:23:56 -07:00
|
|
|
|
2018-09-13 17:58:33 -07:00
|
|
|
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
|
2018-07-02 08:08:14 -07:00
|
|
|
|
2018-09-13 17:58:33 -07:00
|
|
|
if $node_type_client; then
|
|
|
|
client_id_path="$SOLANA_CONFIG_PRIVATE_DIR"/client-id.json
|
|
|
|
$solana_keygen -o "$client_id_path"
|
|
|
|
ls -lhR "$SOLANA_CONFIG_PRIVATE_DIR"/
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $node_type_leader; then
|
2018-09-05 08:28:23 -07:00
|
|
|
leader_address_args=("$ip_address_arg")
|
|
|
|
leader_id_path="$SOLANA_CONFIG_PRIVATE_DIR"/leader-id.json
|
|
|
|
mint_path="$SOLANA_CONFIG_PRIVATE_DIR"/mint.json
|
2018-07-02 08:08:14 -07:00
|
|
|
|
2018-09-05 08:28:23 -07:00
|
|
|
$solana_keygen -o "$leader_id_path"
|
2018-07-02 08:08:14 -07:00
|
|
|
|
2018-07-13 16:26:56 -07:00
|
|
|
echo "Creating $mint_path with $num_tokens tokens"
|
2018-07-12 16:37:19 -07:00
|
|
|
$solana_keygen -o "$mint_path"
|
2018-06-18 15:23:56 -07:00
|
|
|
|
2018-08-03 11:06:06 -07:00
|
|
|
echo "Creating $SOLANA_CONFIG_DIR/ledger"
|
|
|
|
$solana_genesis --tokens="$num_tokens" --ledger "$SOLANA_CONFIG_DIR"/ledger < "$mint_path"
|
2018-06-24 10:10:55 -07:00
|
|
|
|
2018-07-02 08:08:14 -07:00
|
|
|
echo "Creating $SOLANA_CONFIG_DIR/leader.json"
|
2018-07-15 12:25:32 -07:00
|
|
|
$solana_fullnode_config --keypair="$leader_id_path" "${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json
|
2018-09-05 08:28:23 -07:00
|
|
|
|
|
|
|
ls -lhR "$SOLANA_CONFIG_DIR"/
|
|
|
|
ls -lhR "$SOLANA_CONFIG_PRIVATE_DIR"/
|
2018-07-02 08:08:14 -07:00
|
|
|
fi
|
2018-06-24 10:10:55 -07:00
|
|
|
|
2018-06-18 15:23:56 -07:00
|
|
|
|
2018-07-02 08:08:14 -07:00
|
|
|
if $node_type_validator; then
|
2018-09-05 08:28:23 -07:00
|
|
|
validator_address_args=("$ip_address_arg" -b 9000)
|
|
|
|
validator_id_path="$SOLANA_CONFIG_PRIVATE_DIR"/validator-id.json
|
|
|
|
|
|
|
|
$solana_keygen -o "$validator_id_path"
|
|
|
|
|
2018-08-03 13:55:27 -07:00
|
|
|
echo "Creating $SOLANA_CONFIG_VALIDATOR_DIR/validator.json"
|
|
|
|
$solana_fullnode_config --keypair="$validator_id_path" "${validator_address_args[@]}" > "$SOLANA_CONFIG_VALIDATOR_DIR"/validator.json
|
2018-06-22 11:37:42 -07:00
|
|
|
|
2018-09-05 08:28:23 -07:00
|
|
|
ls -lhR "$SOLANA_CONFIG_VALIDATOR_DIR"/
|
2018-07-02 08:08:14 -07:00
|
|
|
fi
|