-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshift-wizard.sh
117 lines (96 loc) · 4.88 KB
/
shift-wizard.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
#!/bin/bash
# PORT SHIFTER for app.toml and config.toml files.
# https://github.com/zenodeapp/port-shifter
# ZENODE (https://zenode.app)
# This wizard can either increment all ports by a common value or
# let the user customize each port individually. If you do not trust
# this wizard or prefer a simpler variant, use quick-shift.sh instead.
# Check if the correct number of arguments is provided
if [ "$#" -lt 1 ]; then
echo "Usage: sh $0 <path_to_config_dir>"
echo "Example: sh $0 $HOME/.gaia/config"
echo ""
exit 1
fi
CONFIG_PATH=$(eval echo "$1" | sed 's/\/$//') # expand tilde and remove trailing slash
# Check if CONFIG_PATH is empty
if [ -z "$CONFIG_PATH" ]; then
echo "Error: The path to the config files cannot be empty."
exit 1
fi
# Check if config files exist
if [ ! -f "$CONFIG_PATH/config.toml" ] || [ ! -f "$CONFIG_PATH/app.toml" ]; then
echo "Error: One or both of the config files ($CONFIG_PATH/config.toml or $CONFIG_PATH/app.toml) not found."
exit 1
fi
read -p "Do you want to customize each port individually? (y/N): " CUSTOM
CUSTOM=$(echo "$CUSTOM" | tr 'A-Z' 'a-z') # Convert to lowercase
if [ "$CUSTOM" != "y" ]; then
read -p "Enter the increment value for all ports: " INCREMENT
# Check if common_increment is a number using grep
if echo "$INCREMENT" | grep -q "^[0-9]\+$" && [ "$INCREMENT" -ne 0 ]; then
echo "Incrementing all ports by $INCREMENT..."
else
INCREMENT=0
echo "Resetting all ports to default values..."
fi
fi
echo ""
# Helper function to prompt for port value
prompt_for_port() {
local PORT_NAME="$1"
local DEFAULT_VALUE="$2"
read -p "Enter value for $PORT_NAME (default: $DEFAULT_VALUE): " USER_INPUT
echo "${USER_INPUT:-$DEFAULT_VALUE}"
}
# backup
cp $CONFIG_PATH/config.toml $CONFIG_PATH/config.toml.bak
cp $CONFIG_PATH/app.toml $CONFIG_PATH/app.toml.bak
# Config.toml default ports
PROXY_APP=26658
RPC_LADDR=26657
PPROF_LADDR=6060
P2P_LADDR=26656
PROMETHEUS_LISTEN_ADDR=26660
# Ask for each port value if CUSTOM is "y"
if [ "$CUSTOM" = "y" ]; then
PROXY_APP=$(prompt_for_port "proxy_app" $PROXY_APP)
RPC_LADDR=$(prompt_for_port "[rpc] laddr" $RPC_LADDR)
PPROF_LADDR=$(prompt_for_port "pprof_laddr" $PPROF_LADDR)
P2P_LADDR=$(prompt_for_port "[p2p] laddr" $P2P_LADDR)
PROMETHEUS_LISTEN_ADDR=$(prompt_for_port "prometheus_listen_addr" $PROMETHEUS_LISTEN_ADDR)
fi
sed -i "/^proxy_app/ s/\(proxy_app = \".*\):\([0-9]*\)/\1:$((PROXY_APP + INCREMENT))/" $CONFIG_PATH/config.toml
sed -i "/^\[rpc\]/,/\[.*\]/ s/\(laddr = \".*\):\([0-9]*\)/\1:$((RPC_LADDR + INCREMENT))/" $CONFIG_PATH/config.toml
sed -i "/^pprof_laddr/ s/\(pprof_laddr = \".*\):\([0-9]*\)/\1:$((PPROF_LADDR + INCREMENT))/" $CONFIG_PATH/config.toml
sed -i "/^\[p2p\]/,/\[.*\]/ s/\(laddr = \".*\):\([0-9]*\)/\1:$((P2P_LADDR + INCREMENT))/" $CONFIG_PATH/config.toml
sed -i "/^prometheus_listen_addr/ s/\(prometheus_listen_addr = \".*\):\([0-9]*\)/\1:$((PROMETHEUS_LISTEN_ADDR + INCREMENT))/" $CONFIG_PATH/config.toml
echo "Ports have been replaced in $CONFIG_PATH/config.toml"
echo ""
# App.toml default ports
API_ADDRESS=1317
ROSETTA_ADDRESS=8080
GRPC_ADDRESS=9090
GRPC_WEB_ADDRESS=9091
JSON_RPC_ADDRESS=8545
JSON_RPC_WS_ADDRESS=8546
JSON_RPC_METRICS_ADDRESS=6065
# Ask for each port value if CUSTOM is "y"
if [ "$CUSTOM" = "y" ]; then
API_ADDRESS=$(prompt_for_port "[api] address" $API_ADDRESS)
ROSETTA_ADDRESS=$(prompt_for_port "[rosetta] address" $ROSETTA_ADDRESS)
GRPC_ADDRESS=$(prompt_for_port "[grpc] address" $GRPC_ADDRESS)
GRPC_WEB_ADDRESS=$(prompt_for_port "[grpc-web] address" $GRPC_WEB_ADDRESS)
JSON_RPC_ADDRESS=$(prompt_for_port "[json-rpc] address" $JSON_RPC_ADDRESS)
JSON_RPC_WS_ADDRESS=$(prompt_for_port "[json-rpc] ws-address" $JSON_RPC_WS_ADDRESS)
JSON_RPC_METRICS_ADDRESS=$(prompt_for_port "[json-rpc] metrics-address" $JSON_RPC_METRICS_ADDRESS)
fi
sed -i "/^\[api\]/,/\[.*\]/ s/\(address = \".*\):\([0-9]*\)/\1:$((API_ADDRESS + INCREMENT))/" $CONFIG_PATH/app.toml
sed -i "/^\[rosetta\]/,/\[.*\]/ s/\(address = \".*\):\([0-9]*\)/\1:$((ROSETTA_ADDRESS + INCREMENT))/" $CONFIG_PATH/app.toml
sed -i "/^\[grpc\]/,/\[.*\]/ s/\(address = \".*\):\([0-9]*\)/\1:$((GRPC_ADDRESS + INCREMENT))/" $CONFIG_PATH/app.toml
sed -i "/^\[grpc-web\]/,/\[.*\]/ s/\(address = \".*\):\([0-9]*\)/\1:$((GRPC_WEB_ADDRESS + INCREMENT))/" $CONFIG_PATH/app.toml
# Make sure to run the three below together and do not comment out the last two, since the first will at first overwrite all three.
sed -i "/^\[json-rpc\]/,/\[.*\]/ s/\(address = \".*\):\([0-9]*\)/\1:$((JSON_RPC_ADDRESS + INCREMENT))/" $CONFIG_PATH/app.toml
sed -i "/^\[json-rpc\]/,/\[.*\]/ s/\(ws-address = \".*\):\([0-9]*\)/\1:$((JSON_RPC_WS_ADDRESS + INCREMENT))/" $CONFIG_PATH/app.toml
sed -i "/^\[json-rpc\]/,/\[.*\]/ s/\(metrics-address = \".*\):\([0-9]*\)/\1:$((JSON_RPC_METRICS_ADDRESS + INCREMENT))/" $CONFIG_PATH/app.toml
echo "Ports have been replaced in $CONFIG_PATH/app.toml"