forked from akash-network/awesome-akash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
69 lines (61 loc) · 2.51 KB
/
main.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
#!/bin/bash
CONFIG_PATH="/root/.sentinelnode/config.toml"
V2RAY_CONFIG_PATH="/root/.sentinelnode/v2ray.toml"
# Function to check if a variable is set and print an error message if it's not.
check_var() {
local var_name="$1"
local error_message="$2"
local example="$3"
if [[ -z ${!var_name} ]]; then
echo "$error_message"
echo "For example: $example"
sleep infinity
fi
}
update_config() {
local var_name="$1"
local pattern="$2"
local config_path="$3"
if [[ -n ${!var_name} ]]; then
sed -i.bak -e "s|^$pattern *=.*|$pattern = \"${!var_name}\"|;" "$config_path"
fi
}
check_var "LISTEN_PORT" "CHECK YOUR LISTEN_PORT AND REMOTE_PORT IN DEPLOY.YML !" "LISTEN_PORT=3333 REMOTE_PORT=8585"
check_var "IPV4_ADDRESS" "CHECK YOUR IPV4 ADDRESS IN DEPLOY.YML !" "IPV4_ADDRESS=XXX.XXX.XXX.XXX"
sentinelnode config init && sentinelnode v2ray config init
(echo ;echo ;echo ;echo ;echo ;echo ;echo )| openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -x509 -sha256 -days 365 -nodes -out ${HOME}/tls.crt -keyout ${HOME}/tls.key
REMOTE_URL="https://$IPV4_ADDRESS:$REMOTE_PORT"
# Variables to update in the config.toml.
declare -A config_mappings=(
["GAS_ADJUSTMENT"]="gas_adjustment"
["GAS"]="gas"
["GAS_PRICES"]="gas_prices"
["CHAIN"]="id"
["BACKEND"]="backend"
["WALLET_NAME"]="from"
["MONIKER"]="moniker"
["TYPE"]="type"
["RPC_ADDRESS"]="rpc_address"
["SIMULATE_AND_EXECUTE"]="simulate_and_execute"
["PEERS"]="peers"
["INTERVAL_SET_SESSIONS"]="interval_set_sessions"
["INTERVAL_UPDATE_SESSIONS"]="interval_update_sessions"
["INTERVAL_UPDATE_STATUS"]="interval_update_status"
["IPV4_ADDRESS"]="ipv4_address"
["GIGABYTE_PRICES"]="gigabyte_prices"
["HOURLY_PRICES"]="hourly_prices"
["REMOTE_URL"]="remote_url"
)
# Update each variable in config.toml.
for var in "${!config_mappings[@]}"; do
update_config "$var" "${config_mappings[$var]}" "$CONFIG_PATH"
done
update_config "LISTEN_PORT" "listen_port" "$V2RAY_CONFIG_PATH"
update_config "TRANSPORT" "transport" "$V2RAY_CONFIG_PATH"
# Special cases
[[ -z $HANDSHAKE ]] && HANDSHAKE=false && update_config "HANDSHAKE" "enable" "$CONFIG_PATH"
[[ -n $REMOTE_PORT ]] || sed -i.bak -e "s|^listen_on *=.*|listen_on = \"0.0.0.0:$REMOTE_PORT\"|;" "$CONFIG_PATH"
(echo `echo $MNEMONIC_BASE64 | base64 -d`)|sentinelnode keys add --recover
mv ${HOME}/tls.crt ${HOME}/.sentinelnode/tls.crt && mv ${HOME}/tls.key ${HOME}/.sentinelnode/tls.key
PATH=$PATH:/root/v2ray
sentinelnode start