Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: localnet recreate script can use defaults #5338

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading