-
Notifications
You must be signed in to change notification settings - Fork 28
/
config_node_param.sh
127 lines (113 loc) · 3.9 KB
/
config_node_param.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
121
122
123
124
125
126
127
#!/bin/bash
function usage() {
printf "\n"
printf "Usage: bash config_node_param.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [get|add|remove] <Param> [<Value>]\n"
printf "Example: bash config_node_param.sh dev get DEV_CLIENT_API_IP_WHITELIST\n"
printf "Example: bash config_node_param.sh dev add DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n"
printf "Example: bash config_node_param.sh dev add DEV_CLIENT_API_IP_WHITELIST '*'\n"
printf "Example: bash config_node_param.sh dev remove DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n"
printf "Example: bash config_node_param.sh dev set DEV_CLIENT_API_IP_WHITELIST '*'\n"
printf "Example: bash config_node_param.sh dev get CORS_WHITELIST\n"
printf "\n"
exit
}
if [[ $# -lt 3 ]] || [[ $# -gt 4 ]]; then
usage
fi
printf "\n[[[[[ config_node_param.sh ]]]]]\n\n"
if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then
SEASON="$1"
else
printf "Invalid <Project/Season> argument: $1\n"
usage
fi
printf "SEASON=$SEASON\n"
if [[ "$2" = 'get' ]]; then
COMMAND="$2"
PARAM="$3"
VALUE="$4"
if [[ ! "$VALUE" = "" ]]; then
printf "\nInvalid argument: $VALUE\n"
usage
fi
elif [[ "$2" = 'add' ]] || [[ "$2" = 'remove' ]] || [[ "$2" = 'set' ]]; then
COMMAND="$2"
PARAM="$3"
VALUE="$4"
if [[ "$PARAM" = "" ]]; then
printf "\nInvalid <Param> argument: $PARAM\n"
usage
fi
if [[ "$VALUE" = "" ]]; then
printf "\nInvalid <Value> argument: $VALUE\n"
usage
fi
else
printf "Invalid <Command> argument: $2\n"
usage
fi
printf "COMMAND=$COMMAND\n"
printf "PARAM=$PARAM\n"
printf "VALUE=$VALUE\n"
# Get confirmation.
if [[ "$SEASON" = "mainnet" ]]; then
printf "\n"
printf "Do you want to proceed for $SEASON? Enter [mainnet]: "
read CONFIRM
printf "\n\n"
if [[ ! $CONFIRM = "mainnet" ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
else
printf "\n"
read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r
printf "\n\n"
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
fi
# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt
# Get keystore password
printf "Enter keystore password: "
read -s KEYSTORE_PW
printf "\n\n"
if [[ $SEASON = "mainnet" ]]; then
CHAIN_ID="1"
KEYSTORE_DIR="mainnet_prod_keys"
elif [[ $SEASON = "spring" ]] || [[ $SEASON = "summer" ]]; then
CHAIN_ID="0"
KEYSTORE_DIR="testnet_prod_keys"
else
CHAIN_ID="0"
KEYSTORE_DIR="testnet_dev_staging_keys"
fi
if [[ $COMMAND = "add" ]]; then
COMMAND_NODE_JS_FILE="addToWhitelistNodeParam.js"
elif [[ $COMMAND = "remove" ]]; then
COMMAND_NODE_JS_FILE="removeFromWhitelistNodeParam.js"
elif [[ $COMMAND = "set" ]]; then
COMMAND_NODE_JS_FILE="setNodeParam.js"
else
COMMAND_NODE_JS_FILE="getNodeParam.js"
fi
printf "CHAIN_ID=$CHAIN_ID\n"
printf "KEYSTORE_DIR=$KEYSTORE_DIR\n"
printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n"
function config_node() {
local node_index="$1"
local node_url=${NODE_URL_LIST[${node_index}]}
printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n"
KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json"
CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM"
if [[ ! $COMMAND = "get" ]]; then
CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$VALUE'"
fi
printf "\n"
printf "CONFIG_NODE_CMD=$CONFIG_NODE_CMD\n\n"
eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD"
}
for j in `seq $(( 0 )) $(( 9 ))`; do
config_node "$j"
done