Skip to content

Commit

Permalink
chore: localnet recreate script can use defaults (#5338)
Browse files Browse the repository at this point in the history
  • Loading branch information
j4m1ef0rd authored and dandanlen committed Oct 30, 2024
1 parent 69480d6 commit f3c802b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
6 changes: 3 additions & 3 deletions localnet/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
## Usage ./localnet/create.sh -b <BINARY_ROOT_PATH> -n <NODE_COUNT> -t <START_TRACKER>
## Example ./localnet/create.sh -b ./target/debug -n 1 -s y

source ./localnet/common.sh

# Parse command-line arguments
while getopts "b:n:t:h" opt; do
case $opt in
b) BINARY_ROOT_PATH=$OPTARG ;;
n) NODE_COUNT=$OPTARG ;;
t) START_TRACKER=$OPTARG ;;
h) echo "Usage: ./localnet/create.sh -b <BINARY_ROOT_PATH> -n <NODE_COUNT> -t <START_TRACKER>"; exit 0 ;;
\?) echo "Invalid option -$OPTARG" >&2 ;;
\?) echo "Invalid option -$OPTARG" >&2 ; exit 0 ;;
esac
done
if [[ -n "$NODE_COUNT" && "$NODE_COUNT" != "1" && "$NODE_COUNT" != "3" ]]; then
Expand All @@ -26,6 +24,8 @@ if [[ -n "$START_TRACKER" && "$START_TRACKER" != "y" && "$START_TRACKER" != "" ]
exit 1
fi

source ./localnet/common.sh

# Set default values if not provided
export BINARY_ROOT_PATH=${BINARY_ROOT_PATH:-"./target/debug"}
export NODE_COUNT=${NODE_COUNT:-"1-node"}
Expand Down
35 changes: 29 additions & 6 deletions localnet/recreate.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
#!/bin/bash
## Stops the existing localnet and starts a new one using the same settings.
## The settings are saved in the settings.sh file in the tmp directory.
## Stops the existing localnet (if running) and starts a new one using the same settings.
## The settings are saved in the settings.sh file in the tmp directory on creation of a localnet.
## Use the -d flag to use default values if no settings file is found.

# Parse arguments
USE_DEFAULTS=false
while getopts "dh" opt; do
case $opt in
d) USE_DEFAULTS=true;;
h) echo "Use -d to create with deafult values if no settings file is found"; exit 0;;
\?) echo "Invalid option -$OPTARG" >&2 ; exit 0 ;;
esac
done

source ./localnet/common.sh

# Load the env vars that the last network used
# Load the env vars that the last localnet used
load_settings

# Use default values or error if no settings file was found
if [ -z "$NODE_COUNT" ] || [ -z "$BINARY_ROOT_PATH" ]; then
echo "❌ Error: no existing network to recreate. Please run the manage script first to build a network."
exit 1
if [ "$USE_DEFAULTS" = true ]; then
export BINARY_ROOT_PATH="./target/debug"
export NODE_COUNT="1-node"
export START_TRACKER="NO"
echo "No settings file found. Using default values:"
echo "BINARY_ROOT_PATH: $BINARY_ROOT_PATH"
echo "NODE_COUNT: $NODE_COUNT"
echo "START_TRACKER: $START_TRACKER"
else
echo "❌ Error: no settings file found. Use -d to create one with defaults, or you can create one using the create/manage scripts."
exit 1
fi
fi

# Destroy and start a new network
# Destroy and start a new localnet
destroy
sleep 5
build-localnet

0 comments on commit f3c802b

Please sign in to comment.