-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker.script.sh
executable file
·117 lines (100 loc) · 2.89 KB
/
docker.script.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
#!/usr/bin/env sh
# shellcheck disable=SC2039
VOLUME="data"
usage()
{
cat << EOF
usage: docker run [--start-bootnode] | [--bootnode bootnode_address] [--chain-spec chain_spec_file]
--start-bootnode Starts a bootnode, which you can refer to in other nodes to form a network
--bootnode Bootnode Address
eg - "/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWGAGSn6y9vR4eDQWmX2WndeN4PYtodasXLqPALMeCZtr1"
--chain-spec Location of the raw chain spec file on the local system
EOF
}
main() {
if [ "${#}" -eq 0 ]; then
usage
exit 1
fi
local is_bootnode="false"
local bootnode
local chain_spec_file
while [ "${#}" -gt 0 ]; do
case $1 in
--start-bootnode)
is_bootnode="true"
shift 1
;;
--bootnode)
bootnode="$2"
if [ -z "$bootnode" ]; then
echo "Error: Missing bootnode address"
usage
exit 1
fi
shift 2
;;
--chain-spec)
chain_spec_file="$2"
if [ -z "$chain_spec_file" ]; then
echo "Error: Missing Chain Spec Location"
usage
exit 1
fi
if [ ! -f "$chain_spec_file" ]; then
echo "Error: $chain_spec_file does not exist"
exit 1
fi
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
usage "Error: Unknown parameter passed: $1"
exit 1
;;
esac
done
# This is so, testing is easier on local systems
local supra_executable="supra"
if ! command -v supra >/dev/null; then
supra_executable="target/release/supra"
fi
if [ ! -d "$VOLUME" ]; then
mkdir -p "$VOLUME" || echo "$VOLUME could not be created"
fi
if [ "$is_bootnode" = "true" ]; then
./scripts/create-bootnode.sh "$supra_executable" "$VOLUME"
elif [ -z "$bootnode" ] || [ -z "$chain_spec_file" ]; then
echo "Both --bootnode and --chain-spec details must be provided"
usage
exit 1
else
local auth_node_file="$VOLUME/auth_node.key"
subkey generate --scheme sr25519 > "$auth_node_file"
local node_key
node_key=$(sed -n 3p "$auth_node_file" | cut -f2 -d : | xargs)
node_key=${node_key##0x}
echo >> "$auth_node_file"
echo "owner: AccountId: 0x$node_key" >> "$auth_node_file"
local peer_id
peer_id="$($supra_executable decode-public-key $node_key | sed -n 3p | cut -f2 -d : | xargs)"
echo "node: PeerId: 0x$peer_id" >> "$auth_node_file"
rm -rf /tmp/auth && "$supra_executable" \
--base-path /tmp/auth \
--chain "$chain_spec_file" \
--port 30333 \
--ws-port 9944 \
--rpc-port 9933 \
--no-prometheus --no-telemetry \
--rpc-methods Unsafe \
--rpc-cors all \
--validator \
--name auth \
--node-key "$node_key" \
--bootnodes "$bootnode"
fi
}
main "$@"