setup.sh can now be more picky about the kind of config it creates

This commit is contained in:
Michael Vines
2018-07-02 08:08:14 -07:00
committed by Grimes
parent c0f9e452f2
commit 5716898216
4 changed files with 65 additions and 19 deletions

View File

@@ -11,7 +11,9 @@ if [[ -d "$SNAP" ]]; then
fi fi
[[ -f "$SOLANA_CONFIG_DIR"/leader.json ]] || { [[ -f "$SOLANA_CONFIG_DIR"/leader.json ]] || {
echo "$SOLANA_CONFIG_DIR/leader.json not found, run ${here}/setup.sh first" echo "$SOLANA_CONFIG_DIR/leader.json not found, create it by running:"
echo
echo " ${here}/setup.sh -t leader"
exit 1 exit 1
} }

View File

@@ -5,8 +5,13 @@ here=$(dirname "$0")
source "$here"/common.sh source "$here"/common.sh
usage () { usage () {
exitcode=0
if [[ -n "$1" ]]; then
exitcode=1
echo "Error: $*"
fi
cat <<EOF cat <<EOF
usage: $0 [-n num_tokens] [-l] [-p] usage: $0 [-n num_tokens] [-l] [-p] [-t node_type]
Creates a fullnode configuration Creates a fullnode configuration
@@ -14,12 +19,19 @@ Creates a fullnode configuration
-l - Detect network address from local machine configuration, which -l - Detect network address from local machine configuration, which
may be a private IP address unaccessible on the Intenet (default) may be a private IP address unaccessible on the Intenet (default)
-p - Detect public address using public Internet servers -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
EOF EOF
exit $exitcode
} }
ip_address_arg=-l ip_address_arg=-l
num_tokens=1000000000 num_tokens=1000000000
while getopts "h?n:lp" opt; do node_type_leader=true
node_type_validator=true
while getopts "h?n:lpt:" opt; do
case $opt in case $opt in
h|\?) h|\?)
usage usage
@@ -34,6 +46,25 @@ while getopts "h?n:lp" opt; do
n) n)
num_tokens="$OPTARG" 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"
;;
esac esac
done done
@@ -44,11 +75,13 @@ validator_address_args=("$ip_address_arg" -b 9000)
set -e set -e
echo "Cleaning $SOLANA_CONFIG_DIR" echo "Cleaning $SOLANA_CONFIG_DIR"
( rm -rvf "$SOLANA_CONFIG_DIR"
set -x mkdir -p "$SOLANA_CONFIG_DIR"
rm -rvf "$SOLANA_CONFIG_DIR"{,-private}
mkdir -p "$SOLANA_CONFIG_DIR"{,-private}
) if $node_type_leader; then
rm -rvf "$SOLANA_CONFIG_DIR"-private
mkdir -p "$SOLANA_CONFIG_DIR"-private
echo "Creating $SOLANA_CONFIG_DIR/mint.json with $num_tokens tokens" echo "Creating $SOLANA_CONFIG_DIR/mint.json with $num_tokens tokens"
$solana_mint <<<"$num_tokens" > "$SOLANA_CONFIG_DIR"-private/mint.json $solana_mint <<<"$num_tokens" > "$SOLANA_CONFIG_DIR"-private/mint.json
@@ -58,8 +91,15 @@ $solana_genesis < "$SOLANA_CONFIG_DIR"-private/mint.json > "$SOLANA_CONFIG_DIR"/
echo "Creating $SOLANA_CONFIG_DIR/leader.json" echo "Creating $SOLANA_CONFIG_DIR/leader.json"
$solana_fullnode_config "${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json $solana_fullnode_config "${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json
fi
if $node_type_validator; then
echo "Creating $SOLANA_CONFIG_DIR/validator.json" echo "Creating $SOLANA_CONFIG_DIR/validator.json"
$solana_fullnode_config "${validator_address_args[@]}" > "$SOLANA_CONFIG_DIR"/validator.json $solana_fullnode_config "${validator_address_args[@]}" > "$SOLANA_CONFIG_DIR"/validator.json
fi
ls -lh "$SOLANA_CONFIG_DIR/" ls -lh "$SOLANA_CONFIG_DIR"/
if $node_type_leader; then
ls -lh "$SOLANA_CONFIG_DIR"-private/
fi

View File

@@ -57,7 +57,9 @@ fi
[[ -f "$SOLANA_CONFIG_DIR"/validator.json ]] || { [[ -f "$SOLANA_CONFIG_DIR"/validator.json ]] || {
echo "$SOLANA_CONFIG_DIR/validator.json not found, run ${here}/setup.sh first" echo "$SOLANA_CONFIG_DIR/validator.json not found, create it by running:"
echo
echo " ${here}/setup.sh -t validator"
exit 1 exit 1
} }

View File

@@ -12,17 +12,19 @@ fi
ip_address_arg=-p # Use public IP address (TODO: make this configurable?) ip_address_arg=-p # Use public IP address (TODO: make this configurable?)
num_tokens="$(snapctl get num-tokens)" num_tokens="$(snapctl get num-tokens)"
$SNAP/bin/setup.sh ${num_tokens:+-n $num_tokens} ${ip_address_arg}
case $mode in case $mode in
leader+drone) leader+drone)
$SNAP/bin/setup.sh ${num_tokens:+-n $num_tokens} ${ip_address_arg} -t leader
snapctl start --enable solana.daemon-leader snapctl start --enable solana.daemon-leader
snapctl start --enable solana.daemon-drone snapctl start --enable solana.daemon-drone
;; ;;
leader) leader)
$SNAP/bin/setup.sh ${num_tokens:+-n $num_tokens} ${ip_address_arg} -t leader
snapctl start --enable solana.daemon-leader snapctl start --enable solana.daemon-leader
;; ;;
validator) validator)
$SNAP/bin/setup.sh ${ip_address_arg} -t validator
snapctl start --enable solana.daemon-validator snapctl start --enable solana.daemon-validator
;; ;;
*) *)