Skip to content

Commit c1d4ef8

Browse files
committed
feat: allow invoking localnet.sh from anywhere
1 parent f073f03 commit c1d4ef8

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

scripts/localnet.sh

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,66 @@
11
#!/bin/bash
22

3+
# Determine the directory this script resides in. This allows invoking it from any location.
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
5+
6+
# The base directory of the subtensor project
7+
BASE_DIR="$SCRIPT_DIR/.."
8+
39
: "${CHAIN:=local}"
410
: "${BUILD_BINARY:=1}"
5-
: "${SPEC_PATH:=specs/}"
611
: "${FEATURES:=pow-faucet}"
712

13+
SPEC_PATH="${SCRIPT_DIR}/specs/"
814
FULL_PATH="$SPEC_PATH$CHAIN.json"
915

1016
if [ ! -d "$SPEC_PATH" ]; then
11-
echo "*** Creating directory ${SPEC_PATH}..."
12-
mkdir $SPEC_PATH
17+
echo "*** Creating directory ${SPEC_PATH}..."
18+
mkdir $SPEC_PATH
1319
fi
1420

1521
if [[ $BUILD_BINARY == "1" ]]; then
16-
echo "*** Building substrate binary..."
17-
cargo build --release --features "$FEATURES"
18-
echo "*** Binary compiled"
22+
echo "*** Building substrate binary..."
23+
cargo build --release --features "$FEATURES" --manifest-path "$BASE_DIR/node/Cargo.toml"
24+
echo "*** Binary compiled"
1925
fi
2026

2127
echo "*** Building chainspec..."
22-
./target/release/node-subtensor build-spec --disable-default-bootnode --raw --chain $CHAIN > $FULL_PATH
28+
"$BASE_DIR/target/release/node-subtensor" build-spec --disable-default-bootnode --raw --chain $CHAIN >$FULL_PATH
2329
echo "*** Chainspec built and output to file"
2430

2531
echo "*** Purging previous state..."
26-
./target/release/node-subtensor purge-chain -y --base-path /tmp/bob --chain="$FULL_PATH" >/dev/null 2>&1
27-
./target/release/node-subtensor purge-chain -y --base-path /tmp/alice --chain="$FULL_PATH" >/dev/null 2>&1
32+
"$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/bob --chain="$FULL_PATH" >/dev/null 2>&1
33+
"$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/alice --chain="$FULL_PATH" >/dev/null 2>&1
2834
echo "*** Previous chainstate purged"
2935

3036
echo "*** Starting localnet nodes..."
3137
alice_start=(
32-
./target/release/node-subtensor
33-
--base-path /tmp/alice
34-
--chain="$FULL_PATH"
35-
--alice
36-
--port 30334
37-
--rpc-port 9946
38-
--validator
39-
--rpc-cors=all
40-
--allow-private-ipv4
41-
--discover-local
38+
"$BASE_DIR/target/release/node-subtensor"
39+
--base-path /tmp/alice
40+
--chain="$FULL_PATH"
41+
--alice
42+
--port 30334
43+
--rpc-port 9946
44+
--validator
45+
--rpc-cors=all
46+
--allow-private-ipv4
47+
--discover-local
4248
)
4349

4450
bob_start=(
45-
./target/release/node-subtensor
46-
--base-path /tmp/bob
47-
--chain="$FULL_PATH"
48-
--bob
49-
--port 30335
50-
--rpc-port 9945
51-
--validator
52-
--allow-private-ipv4
53-
--discover-local
51+
"$BASE_DIR"/target/release/node-subtensor
52+
--base-path /tmp/bob
53+
--chain="$FULL_PATH"
54+
--bob
55+
--port 30335
56+
--rpc-port 9945
57+
--validator
58+
--allow-private-ipv4
59+
--discover-local
5460
)
5561

56-
(trap 'kill 0' SIGINT; ("${alice_start[@]}" 2>&1) & ("${bob_start[@]}" 2>&1))
62+
(
63+
trap 'kill 0' SIGINT
64+
("${alice_start[@]}" 2>&1) &
65+
("${bob_start[@]}" 2>&1)
66+
)

0 commit comments

Comments
 (0)