-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·210 lines (179 loc) · 6.9 KB
/
install.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/sh
# Check for required environment variables
required_vars="NAME RPC_URL CHAIN_ID GENESIS"
for var in $required_vars; do
# If any required variable is not set, print an error message and exit
if [ -z "$(eval echo \$$var)" ]; then
echo "Error: Environment variable $var is not set." >&2
exit 1
fi
done
# Assign environment variables to local variables for easier use
name=$NAME
rpc_url=$RPC_URL
chain_id=$CHAIN_ID
genesis=$GENESIS
network_logo=$NETWORK_LOGO
network_logo_dark=$NETWORK_LOGO_DARK
network_icon=$NETWORK_ICON
# Check if EXPLORER_URL is set, if not, create it using rpc_url
if [ -z "$EXPLORER_URL" ]; then
explorer_url="explorer.$rpc_url"
else
explorer_url=$EXPLORER_URL
fi
# Generate a random secret key
secret_key_base=$(openssl rand -hex 32)
# Assign optional environment variables to local variables
favicon_generator_api_key=$FAVICON_GENERATOR_API_KEY
wallet_connect_project_id=$NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID
currency_symbol=$CURRENCY_SYMBOL
if [ -z "$network" ]; then
network="mainnet"
fi
blockscout_port=$BLOCKSCOUT_PORT
if [ -z "$blockscout_port" ]; then
# Ensure it is empty
blockscout_port="80"
fi
postgres_port=$POSTGRES_PORT
if [ -z "$postgres_port" ]; then
# Ensure it is empty
postgres_port="7432"
fi
stats_service_port=$STATS_SERVICE_PORT
if [ -z "$stats_service_port" ]; then
# Ensure it is empty
stats_service_port="8080"
fi
stats_api_host=$STATS_API_HOST
if [ -z "$stats_api_host" ]; then
stats_api_host="$explorer_url:$stats_service_port"
fi
visualizer_service_port=$VISUALIZER_SERVICE_PORT
if [ -z "$visualizer_service_port" ]; then
# Ensure it is empty
visualizer_service_port="8081"
fi
visualizer_api_host=$VISUALIZER_API_HOST
if [ -z "$visualizer_api_host" ]; then
visualizer_api_host="$explorer_url:$visualizer_service_port"
fi
smart_contract_verifier_service_port=$SMART_CONTRACT_VERIFIER_SERVICE_PORT
if [ -z "$smart_contract_verifier_service_port" ]; then
smart_contract_verifier_service_port="8050"
fi
verifier_type=$VERIFIER_TYPE
if [ -z "$verifier_type" ]; then
verifier_type="eth_bytecode_db"
fi
if [ "$verifier_type" = "eth_bytecode_db" ]; then
verifier_url="https:\/\/eth-bytecode-db.services.blockscout.com\/"
smart_contract_verifier_restart_policy="no"
smart_contract_verifier_disabled="command: [\"true\"]"
smart_contract_verifier_port_mapping=""
else
verifier_url="http:\/\/smart-contract-verifier:8050\/"
smart_contract_verifier_restart_policy="always"
smart_contract_verifier_disabled=""
smart_contract_verifier_port_mapping="- \"$smart_contract_verifier_service_port:8050\""
fi
containers_prefix=$CONTAINERS_PREFIX
if [ -z "$containers_prefix" ]; then
# Ensure it is empty
containers_prefix=""
else
[[ "$containers_prefix" != *- ]] && containers_prefix="${containers_prefix}-"
fi
blockscout_protocol=$BLOCKSCOUT_PROTOCOL
if [ "$blockscout_protocol" = "secured" ]; then
blockscout_http_protocol="https"
blockscout_ws_protocol="wss"
else
blockscout_http_protocol="http"
blockscout_ws_protocol="ws"
fi
rpc_protocol=$RPC_PROTOCOL
if [ "$rpc_protocol" = "secured" ]; then
rpc_http_protocol="https"
rpc_ws_protocol="wss"
else
rpc_http_protocol="http"
rpc_ws_protocol="ws"
fi
if [ "$network" = "mainnet" ]; then
is_testnet="false"
else
is_testnet="true"
fi
cpu_limit=$CPU_LIMIT
if [ -z "$cpu_limit" ]; then
cpu_limit="1"
fi
# Define the paths for the Docker Compose template and the actual file
dockercompose_template_file="./config/docker-compose-template.yaml"
dockercompose_file="docker-compose.yaml"
# Replace placeholders in the Docker Compose file with actual values
sed \
-e "s/{name}/$name/g" \
-e "s/{rpc_url}/$rpc_url/g" \
-e "s/{chain_id}/$chain_id/g" \
-e "s/{genesis}/$genesis/g" \
-e "s/{secret_key_base}/$secret_key_base/g" \
-e "s/{favicon_generator_api_key}/$favicon_generator_api_key/g" \
-e "s/{wallet_connect_project_id}/$wallet_connect_project_id/g" \
-e "s/{explorer_url}/$explorer_url/g" \
-e "s/{blockscout_port}/$blockscout_port/g" \
-e "s/{postgres_port}/$postgres_port/g" \
-e "s/{stats_service_port}/$stats_service_port/g" \
-e "s/{stats_api_host}/$stats_api_host/g" \
-e "s/{visualizer_service_port}/$visualizer_service_port/g" \
-e "s/{visualizer_api_host}/$visualizer_api_host/g" \
-e "s/{smart_contract_verifier_service_port}/$smart_contract_verifier_service_port/g" \
-e "s/{containers_prefix}/$containers_prefix/g" \
-e "s/{blockscout_http_protocol}/$blockscout_http_protocol/g" \
-e "s/{blockscout_ws_protocol}/$blockscout_ws_protocol/g" \
-e "s/{rpc_http_protocol}/$rpc_http_protocol/g" \
-e "s/{rpc_ws_protocol}/$rpc_ws_protocol/g" \
-e "s/{currency_symbol}/$currency_symbol/g" \
-e "s/{verifier_type}/$verifier_type/g" \
-e "s/{smart_contract_verifier_restart_policy}/$smart_contract_verifier_restart_policy/g" \
-e "s/{smart_contract_verifier_disabled}/$smart_contract_verifier_disabled/g" \
-e "s/{verifier_url}/$verifier_url/g" \
-e "s/{is_testnet}/$is_testnet/g" \
-e "s/{cpu_limit}/$cpu_limit/g" \
-e "s/{network}/$network/g" \
-e "s|{network_logo}|$network_logo|g" \
-e "s|{network_logo_dark}|$network_logo_dark|g" \
-e "s|{network_icon}|$network_icon|g" \
-e "s/{smart_contract_verifier_port_mapping}/$smart_contract_verifier_port_mapping/g" \
$dockercompose_template_file > $dockercompose_file
# Define the paths for the proxy configuration template and the actual file
proxy_template_file="./config/proxy/default.conf.template"
proxy_file="./data/proxy/default.conf.template"
# Create the directory for the proxy configuration file if it doesn't exist
mkdir -p "$(dirname "$proxy_file")"
# Replace placeholder in the proxy configuration file with actual value
sed \
-e "s/{explorer_url}/$explorer_url/g" \
-e "s/{containers_prefix}/$containers_prefix/g" \
-e "s/{blockscout_port}/$blockscout_port/g" \
-e "s/{blockscout_http_protocol}/$blockscout_http_protocol/g" \
-e "s/{stats_service_port}/$stats_service_port/g" \
-e "s/{visualizer_service_port}/$visualizer_service_port/g" \
-e "s/{smart_contract_verifier_service_port}/$smart_contract_verifier_service_port/g" \
$proxy_template_file > $proxy_file
proxy_host_template_file="./config/proxy/host.conf.template"
proxy_host_file="./data/host_proxy/host.conf"
mkdir -p "$(dirname "$proxy_host_file")"
sed \
-e "s/{explorer_url}/$explorer_url/g" \
-e "s/{containers_prefix}/$containers_prefix/g" \
-e "s/{blockscout_port}/$blockscout_port/g" \
-e "s/{stats_service_port}/$stats_service_port/g" \
-e "s/{visualizer_service_port}/$visualizer_service_port/g" \
-e "s/{smart_contract_verifier_service_port}/$smart_contract_verifier_service_port/g" \
-e "s/{ssl_certificate}/$ssl_certificate/g" \
-e "s/{ssl_certificate_key}/$ssl_certificate_key/g" \
$proxy_host_template_file > $proxy_host_file
/bin/bash ./download.sh