Skip to content

Commit 51e11bb

Browse files
committed
update install script to run local subtensor chain
1 parent 1d427a5 commit 51e11bb

File tree

1 file changed

+79
-61
lines changed

1 file changed

+79
-61
lines changed

scripts/install_staging.sh

+79-61
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,100 @@
11
#!/bin/bash
22

3-
# Update your system packages
4-
install_mac() {
5-
# Ensure Homebrew is installed
6-
which brew > /dev/null
7-
if [ $? -ne 0 ]; then
8-
echo "Installing Homebrew..."
9-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3+
# Section 1: Build/Install
4+
# This section is for first-time setup and installations.
5+
6+
install_dependencies() {
7+
# Function to install packages on macOS
8+
install_mac() {
9+
which brew > /dev/null
10+
if [ $? -ne 0 ]; then
11+
echo "Installing Homebrew..."
12+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
13+
fi
14+
echo "Updating Homebrew packages..."
15+
brew update
16+
echo "Installing required packages..."
17+
brew install make llvm curl libssl protobuf tmux
18+
}
19+
20+
# Function to install packages on Ubuntu/Debian
21+
install_ubuntu() {
22+
echo "Updating system packages..."
23+
sudo apt update
24+
echo "Installing required packages..."
25+
sudo apt install --assume-yes make build-essential git clang curl libssl-dev llvm libudev-dev protobuf-compiler tmux
26+
}
27+
28+
# Detect OS and call the appropriate function
29+
if [[ "$OSTYPE" == "darwin"* ]]; then
30+
install_mac
31+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
32+
install_ubuntu
33+
else
34+
echo "Unsupported operating system."
35+
exit 1
1036
fi
1137

12-
echo "Updating Homebrew packages..."
13-
brew update
38+
# Install rust and cargo
39+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
1440

15-
echo "Installing required packages..."
16-
brew install make llvm curl libssl protobuf tmux
41+
# Update your shell's source to include Cargo's path
42+
source "$HOME/.cargo/env"
1743
}
1844

19-
# Function to install packages on Ubuntu/Debian
20-
install_ubuntu() {
21-
echo "Updating system packages..."
22-
sudo apt update
23-
24-
echo "Installing required packages..."
25-
sudo apt install --assume-yes make build-essential git clang curl libssl-dev llvm libudev-dev protobuf-compiler tmux
26-
}
27-
28-
# Detect OS and call the appropriate function
29-
if [[ "$OSTYPE" == "darwin"* ]]; then
30-
install_mac
31-
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
32-
install_ubuntu
33-
else
34-
echo "Unsupported operating system."
35-
fi
36-
37-
# Install rust and cargo
38-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
39-
40-
# Update your shell's source to include Cargo's path
41-
source "$HOME/.cargo/env"
42-
43-
# Clone subtensor and enter the directory
44-
cd ../
45-
if [ ! -d "subtensor" ]; then
46-
git clone https://github.com/opentensor/subtensor.git
45+
# Call install_dependencies only if it's the first time running the script
46+
if [ ! -f ".dependencies_installed" ]; then
47+
install_dependencies
48+
touch .dependencies_installed
4749
fi
48-
cd subtensor
49-
git pull
50-
51-
# Update to the nightly version of rust
52-
./scripts/init.sh
5350

54-
# Navigate to your project directory
55-
cd ../bittensor-subnet-template
5651

57-
# Install the bittensor-subnet-template python package
58-
python -m pip install -e .
52+
# Section 2: Test/Run
53+
# This section is for running and testing the setup.
5954

6055
# Create a coldkey for the owner role
6156
wallet=${1:-owner}
6257

63-
btcli wallet new_coldkey --wallet.name $wallet --no_password --no_prompt
64-
65-
# Set up the miner's wallets
66-
btcli wallet new_coldkey --wallet.name miner --no_password --no_prompt
67-
btcli wallet new_hotkey --wallet.name miner --wallet.hotkey default --no_prompt
58+
# Logic for setting up and running the environment
59+
setup_environment() {
60+
# Clone subtensor and enter the directory
61+
if [ ! -d "subtensor" ]; then
62+
git clone https://github.com/opentensor/subtensor.git
63+
fi
64+
cd subtensor
65+
git pull
66+
67+
# Update to the nightly version of rust
68+
./scripts/init.sh
69+
70+
cd ../bittensor-subnet-template
71+
72+
# Install the bittensor-subnet-template python package
73+
python -m pip install -e .
74+
75+
# Create and set up wallets
76+
# This section can be skipped if wallets are already set up
77+
if [ ! -f ".wallets_setup" ]; then
78+
btcli wallet new_coldkey --wallet.name $wallet --no_password --no_prompt
79+
btcli wallet new_coldkey --wallet.name miner --no_password --no_prompt
80+
btcli wallet new_hotkey --wallet.name miner --wallet.hotkey default --no_prompt
81+
btcli wallet new_coldkey --wallet.name validator --no_password --no_prompt
82+
btcli wallet new_hotkey --wallet.name validator --wallet.hotkey default --no_prompt
83+
touch .wallets_setup
84+
fi
6885

69-
# Set up the validator's wallets
70-
btcli wallet new_coldkey --wallet.name validator --no_password --no_prompt
71-
btcli wallet new_hotkey --wallet.name validator --wallet.hotkey default --no_prompt
86+
}
7287

88+
# Call setup_environment every time
89+
setup_environment
7390

7491
## Setup localnet
92+
# assumes we are in the bittensor-subnet-template/ directory
7593
# Initialize your local subtensor chain in development mode. This command will set up and run a local subtensor network.
7694
cd ../subtensor
7795

7896
# Start a new tmux session and create a new pane, but do not switch to it
79-
echo "FEATURES='pow-faucet runtime-benchmarks' BT_DEFAULT_TOKEN_WALLET=$(cat ~/.bittensor/wallets/owner/coldkeypub.txt | grep -oP '"ss58Address": "\K[^"]+') bash scripts/localnet.sh" >> setup_and_run.sh
97+
echo "FEATURES='pow-faucet runtime-benchmarks' BT_DEFAULT_TOKEN_WALLET=$(cat ~/.bittensor/wallets/$wallet/coldkeypub.txt | grep -oP '"ss58Address": "\K[^"]+') bash scripts/localnet.sh" >> setup_and_run.sh
8098
chmod +x setup_and_run.sh
8199
tmux new-session -d -s localnet -n 'localnet'
82100
tmux send-keys -t localnet 'bash ../subtensor/setup_and_run.sh' C-m
@@ -85,15 +103,15 @@ tmux send-keys -t localnet 'bash ../subtensor/setup_and_run.sh' C-m
85103
echo ">> localnet.sh is running in a detached tmux session named 'localnet'"
86104
echo ">> You can attach to this session with: tmux attach-session -t localnet"
87105

88-
# Register a subnet
89-
btcli subnet create --wallet.name owner --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946 --no_prompt
106+
# Register a subnet (this needs to be run each time we start a new local chain)
107+
btcli subnet create --wallet.name $wallet --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946 --no_prompt
90108

91109
# Transfer tokens to miner and validator coldkeys
92110
export BT_MINER_TOKEN_WALLET=$(cat ~/.bittensor/wallets/miner/coldkeypub.txt | grep -oP '"ss58Address": "\K[^"]+')
93111
export BT_VALIDATOR_TOKEN_WALLET=$(cat ~/.bittensor/wallets/validator/coldkeypub.txt | grep -oP '"ss58Address": "\K[^"]+')
94112

95-
btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name owner --dest $BT_MINER_TOKEN_WALLET --amount 1000 --no_prompt
96-
btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name owner --dest $BT_VALIDATOR_TOKEN_WALLET --amount 10000 --no_prompt
113+
btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name $wallet --dest $BT_MINER_TOKEN_WALLET --amount 1000 --no_prompt
114+
btcli wallet transfer --subtensor.network ws://127.0.0.1:9946 --wallet.name $wallet --dest $BT_VALIDATOR_TOKEN_WALLET --amount 10000 --no_prompt
97115

98116
# Register wallet hotkeys to subnet
99117
btcli subnet register --wallet.name miner --netuid 1 --wallet.hotkey default --subtensor.chain_endpoint ws://127.0.0.1:9946 --no_prompt

0 commit comments

Comments
 (0)