-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDBC-baby-init.sh
executable file
·120 lines (105 loc) · 3.05 KB
/
DBC-baby-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
# runs initial safe commands to start a clean network
# create a master wallet to hold genesis DBC
set_env_vars () {
#export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" # Already the default
export RUST_LOG=sn_node=info # This filters the output for stdout/files, not OTLP
#export RUST_LOG_OTLP=sn_node=trace # This filters what is sent to OTLP endpoint
export SAFE_ROOT=$HOME/.safe
export SAFE_BIN=/usr/local/bin
export TESTNET_NAME=baby-fleming
export WALLET_DATA=$SAFE_ROOT/testcreds.txt
export ACCTS=$SAFE_ROOT/accounts/
}
intro () {
echo ""
echo ""
echo "This script will remove all previous data from .safe/nodes/"
echo "and check for and install trash-cli and jq packages"
echo ""
echo ""
echo ""
echo ""
echo ""
}
check_packages () {
packages=("trash-cli" "jq" )
not_installed=()
for package in "${packages[@]}"; do
if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q "ok installed"; then
echo "$package is already installed"
else
not_installed+=($package)
fi
done
if [ ${#not_installed[@]} -ne 0 ]; then
echo "Installing ${not_installed[*]}"
sudo apt-get install -y ${not_installed[*]}
else
echo "All packages already installed"
fi
}
get_nodes_qty () {
while :; do
read -p "How many nodes [20]?: " NODES_QTY
NODES_QTY=${NODES_QTY:-20}
[[ $NODES_QTY =~ ^[0-9]+$ ]] || { echo "Enter a valid number"; continue; }
if ((NODES_QTY >= 11 && NODES_QTY <= 50)); then
echo "OK"
break
else
echo "Choose between 11 and 50 nodes"
fi
done
}
clean_up () {
#clean up from any previous run
$SAFE_BIN/safe node killall > /dev/null
[ -f "$WALLET_DATA " ] && rm -v $WALLET_DATA #make sure this is cleared
echo ""
echo ""
sleep 1
cd $SAFE_ROOT/node
trash-put -r -v ./baby* ./local*
}
init_network () {
echo "============================================"
echo ""
echo "Allow time for all "$NODES_QTY" nodes to be started"
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
$SAFE_BIN/safe node run-baby-fleming --nodes $NODES_QTY
echo ""
echo "============================================================="
}
check_network () {
$SAFE_BIN/safe networks switch $TESTNET_NAME
$SAFE_BIN/safe networks
$SAFE_BIN/safe networks check
$SAFE_BIN/safe networks sections
}
init_stash () {
$SAFE_BIN/safe keys create --for-cli #--json
STASH=$($SAFE_BIN/safe wallet create |echo $(grep -oP '(?<=Wallet created at:).*')|awk '{gsub(/^"|"$/, "", $0); print $0}')
echo $STASH > $WALLET_DATA
echo ""
echo ""
echo "The master wallet is at address: "$STASH
$SAFE_BIN/safe wallet deposit --dbc ~/.safe/node/baby-fleming-nodes/sn-node-genesis/genesis_dbc $STASH
echo "============================================"
ls -l $WALLET_DATA
}
set_env_vars
intro
check_packages
get_nodes_qty
clean_up
init_network
check_network
sleep 2
init_stash
exit 0