forked from getumbrel/umbrel
/
configure
executable file
·310 lines (261 loc) · 12.1 KB
/
configure
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/env bash
set -euo pipefail
##########################################################
################## Check dependencies ####################
##########################################################
check_dependencies () {
for cmd in "$@"; do
if ! command -v $cmd >/dev/null 2>&1; then
echo "This script requires \"${cmd}\" to be installed"
exit 1
fi
done
}
if [ ! "$(uname -s)" == "Linux" ]; then
echo "Sorry, Umbrel only supports Linux-based systems at this point."
echo
echo "You may work around this by modifying the configuration script yourself, but it's highly experimental."
echo "If you get it working, we hope you consider making a PR. :)"
exit 1
fi
check_dependencies docker docker-compose dirname readlink
# Switch to Umbrel's root directory
UMBREL_ROOT="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")"/..)"
if [[ ! -d "$UMBREL_ROOT" ]]; then
echo "Root dir does not exist '$UMBREL_ROOT'"
exit 1
fi
cd "$UMBREL_ROOT"
# Make sure we use the status dir from the real Umbrel installation if this is
# an OTA update.
STATUS_DIR="${UMBREL_ROOT}/statuses"
if [[ -f "${UMBREL_ROOT}/../.umbrel" ]]; then
STATUS_DIR="${UMBREL_ROOT}/../statuses"
fi
# Configure for mainnet or testnet or regtest depending
# upon the user-supplied value of $NETWORK
BITCOIN_NETWORK="${NETWORK:-mainnet}"
if [ "$BITCOIN_NETWORK" != "mainnet" ] && [ "$BITCOIN_NETWORK" != "testnet" ] && [ "$BITCOIN_NETWORK" != "regtest" ]; then
echo "Error: Umbrel can only be configured for mainnet (default), testnet or regtest"
exit 1
fi
# Get current Umbrel version
UMBREL_VERSION="$(cat ${UMBREL_ROOT}/info.json | jq -r .version)"
echo
echo "======================================"
if [[ -f "${STATUS_DIR}/configured" ]]; then
echo "=========== RECONFIGURING ============"
else
echo "============ CONFIGURING ============="
fi
echo "========= UMBREL (${BITCOIN_NETWORK}) ==========="
echo "======================================"
echo
##########################################################
############### Setup configuration files ###############
##########################################################
# Store paths to intermediary config files
NGINX_CONF_FILE="./templates/nginx.conf"
BITCOIN_CONF_FILE="./templates/bitcoin.conf"
LND_CONF_FILE="./templates/lnd.conf"
TOR_CONF_FILE="./templates/torrc"
ELECTRS_CONF_FILE="./templates/electrs.toml"
ENV_FILE="./templates/.env"
# Remove intermediary files if they exist from any
# previous unclean configuration run
[[ -f "$NGINX_CONF_FILE" ]] && rm -f "$NGINX_CONF_FILE"
[[ -f "$BITCOIN_CONF_FILE" ]] && rm -f "$BITCOIN_CONF_FILE"
[[ -f "$LND_CONF_FILE" ]] && rm -f "$LND_CONF_FILE"
[[ -f "$TOR_CONF_FILE" ]] && rm -f "$TOR_CONF_FILE"
[[ -f "$ELECTRS_CONF_FILE" ]] && rm -f "$ELECTRS_CONF_FILE"
[[ -f "$ENV_FILE" ]] && rm -f "$ENV_FILE"
# Copy template configs to intermediary configs
[[ -f "./templates/nginx-sample.conf" ]] && cp "./templates/nginx-sample.conf" "$NGINX_CONF_FILE"
[[ -f "./templates/bitcoin-sample.conf" ]] && cp "./templates/bitcoin-sample.conf" "$BITCOIN_CONF_FILE"
[[ -f "./templates/lnd-sample.conf" ]] && cp "./templates/lnd-sample.conf" "$LND_CONF_FILE"
[[ -f "./templates/torrc-sample" ]] && cp "./templates/torrc-sample" "$TOR_CONF_FILE"
[[ -f "./templates/electrs-sample.toml" ]] && cp "./templates/electrs-sample.toml" "$ELECTRS_CONF_FILE"
[[ -f "./templates/.env-sample" ]] && cp "./templates/.env-sample" "$ENV_FILE"
##########################################################
############ Generate configuration variables ############
##########################################################
# Load existing credentials if we have some
[[ -f "./.env" ]] && source "./.env"
[[ ! -z ${PREV_ENV_FILE+x} ]] && [[ -f "${PREV_ENV_FILE}" ]] && source "${PREV_ENV_FILE}"
# Umbrel
GATEWAY_IP="10.0.0.1"
NGINX_IP="10.0.0.2"
DASHBOARD_IP="10.0.0.3"
MANAGER_IP="10.0.0.4"
MIDDLEWARE_IP="10.0.0.5"
NEUTRINO_SWITCHER_IP="10.0.0.6"
FRONTAIL_IP="10.0.0.7"
BITCOIN_IP="10.0.0.8"
BITCOIN_RPC_PORT="8332"
BITCOIN_P2P_PORT="8333"
LND_IP="10.0.0.9"
LND_GRPC_PORT="10009"
LND_REST_PORT="8080"
ELECTRUM_IP="10.0.0.10"
ELECTRUM_PORT="50001"
TOR_PROXY_IP="10.0.0.11"
TOR_PROXY_PORT="9050"
# Apps
APP_BTC_RPC_EXPLORER_IP="10.0.1.0"
APP_BTC_RPC_EXPLORER_PORT="3002"
APP_THUNDERHUB_IP="10.0.1.1"
APP_THUNDERHUB_PORT="3000"
APP_SPHINX_RELAY_IP="10.0.1.2"
APP_SPHINX_RELAY_PORT="3300"
APP_RIDE_THE_LIGHTNING_IP="10.0.1.3"
APP_RIDE_THE_LIGHTNING_PORT="3001"
# Generate RPC credentials
if [[ -z ${BITCOIN_RPC_USER+x} ]] || [[ -z ${BITCOIN_RPC_PASS+x} ]] || [[ -z ${BITCOIN_RPC_AUTH+x} ]]; then
echo "Generating auth credentials"
echo
BITCOIN_RPC_USER="umbrel"
BITCOIN_RPC_DETAILS=$("./scripts/rpcauth.py" "$BITCOIN_RPC_USER")
BITCOIN_RPC_PASS=$(echo "$BITCOIN_RPC_DETAILS" | tail -1)
BITCOIN_RPC_AUTH=$(echo "$BITCOIN_RPC_DETAILS" | head -2 | tail -1 | sed -e "s/^rpcauth=//")
fi
# Pull Tor image and generate Tor password
if [[ -z ${TOR_PASSWORD+x} ]] || [[ -z ${TOR_HASHED_PASSWORD+x} ]]; then
echo "Generating Tor password"
echo
TOR_PASSWORD=$("./scripts/rpcauth.py" "itdoesntmatter" | tail -1)
TOR_HASHED_PASSWORD=$(docker run --rm getumbrel/tor:v0.4.1.9 --quiet --hash-password "$TOR_PASSWORD")
fi
##########################################################
### Update config files with configuration variables #####
##########################################################
if [ "$BITCOIN_NETWORK" == "testnet" ]; then
# Set testnet ports
BITCOIN_RPC_PORT=18332
BITCOIN_P2P_PORT=18333
# Switch Bitcoin Core to testnet
sed -i '1s/^/testnet=1\n[test]\n\n/' "$BITCOIN_CONF_FILE"
# Switch LND to testnet
sed -i "s/bitcoin.mainnet=1/bitcoin.testnet=1/g;" "$LND_CONF_FILE"
# Uncomment testnet neutrino block and peers
sed -i "s/\# \[neutrino\]/\[neutrino\]/g;" "$LND_CONF_FILE"
sed -i "s/\# neutrino.addpeer=testnet1-btcd.zaphq.io/neutrino.addpeer=testnet1-btcd.zaphq.io/g;" "$LND_CONF_FILE"
sed -i "s/\# neutrino.addpeer=testnet2-btcd.zaphq.io/neutrino.addpeer=testnet2-btcd.zaphq.io/g;" "$LND_CONF_FILE"
# Set electrs to testnet
sed -i "s/network = \"bitcoin\"/network = \"testnet\"/g;" "$ELECTRS_CONF_FILE"
fi
if [ "$BITCOIN_NETWORK" == "regtest" ]; then
# Set regtest ports
BITCOIN_RPC_PORT=18443
BITCOIN_P2P_PORT=18444
# Switch Bitcoin Core to regtest
sed -i '1s/^/regtest=1\n[regtest]\n\n/' "$BITCOIN_CONF_FILE"
# Switch LND to regtest
sed -i "s/bitcoin.mainnet=1/bitcoin.regtest=1/g;" "$LND_CONF_FILE"
# Use bitcoind as the node
sed -i "s/bitcoin.node=neutrino/bitcoin.node=bitcoind/g;" "$LND_CONF_FILE"
# Set electrs to regtest
sed -i "s/network = \"bitcoin\"/network = \"regtest\"/g;" "$ELECTRS_CONF_FILE"
fi
# Update RPC and P2P Ports
sed -i "s/rpcport=<port>/rpcport=$BITCOIN_RPC_PORT/g;" "$BITCOIN_CONF_FILE"
sed -i "s/port=<port>/port=$BITCOIN_P2P_PORT/g;" "$BITCOIN_CONF_FILE"
sed -i "s/<bitcoin-rpc-port>/$BITCOIN_RPC_PORT/g;" "$TOR_CONF_FILE"
sed -i "s/<bitcoin-p2p-port>/$BITCOIN_P2P_PORT/g;" "$TOR_CONF_FILE"
sed -i "/daemon_rpc_addr/s/<port>/$BITCOIN_RPC_PORT/g;" "$ELECTRS_CONF_FILE"
sed -i "s/BITCOIN_RPC_PORT=<port>/BITCOIN_RPC_PORT=$BITCOIN_RPC_PORT/g;" "$ENV_FILE"
sed -i "s/BITCOIN_P2P_PORT=<port>/BITCOIN_P2P_PORT=$BITCOIN_P2P_PORT/g;" "$ENV_FILE"
# Add rpcauth
sed -i "s/rpcauth=<rpcauth>/rpcauth=$BITCOIN_RPC_AUTH/g;" "$BITCOIN_CONF_FILE"
sed -i "s/BITCOIN_RPC_AUTH=<rpcauth>/BITCOIN_RPC_AUTH='$BITCOIN_RPC_AUTH'/g;" "$ENV_FILE"
# Add RPC credentials to lnd.conf
sed -i "s/bitcoind.rpcuser=<username>/bitcoind.rpcuser=$BITCOIN_RPC_USER/g;" "$LND_CONF_FILE"
sed -i "s/bitcoind.rpcpass=<password>/bitcoind.rpcpass=$BITCOIN_RPC_PASS/g;" "$LND_CONF_FILE"
# Add RPC credentials to env file
sed -i "s/BITCOIN_RPC_USER=<username>/BITCOIN_RPC_USER=$BITCOIN_RPC_USER/g;" "$ENV_FILE"
sed -i "s/BITCOIN_RPC_PASS=<password>/BITCOIN_RPC_PASS=$BITCOIN_RPC_PASS/g;" "$ENV_FILE"
# Add chain to env file
sed -i "s/BITCOIN_NETWORK=<network>/BITCOIN_NETWORK=$BITCOIN_NETWORK/g;" "$ENV_FILE"
# Add Tor password
sed -i "s/HashedControlPassword <password>/HashedControlPassword $TOR_HASHED_PASSWORD/g;" "$TOR_CONF_FILE"
sed -i "s/torpassword=<password>/torpassword=$TOR_PASSWORD/g;" "$BITCOIN_CONF_FILE"
sed -i "s/tor.password=<password>/tor.password=$TOR_PASSWORD/g;" "$LND_CONF_FILE"
sed -i "s/TOR_PASSWORD=<password>/TOR_PASSWORD=$TOR_PASSWORD/g;" "$ENV_FILE"
sed -i "s/TOR_HASHED_PASSWORD=<password>/TOR_HASHED_PASSWORD=$TOR_HASHED_PASSWORD/g;" "$ENV_FILE"
# Store docker binary path
DOCKER_BINARY=$(readlink -f "$(which docker)")
sed -i "s#DOCKER_BINARY=<path>#DOCKER_BINARY=$DOCKER_BINARY#g;" "$ENV_FILE"
# Set Umbrel version in electrs banner
sed -i "/server_banner/s/<version>/$UMBREL_VERSION/g;" "$ELECTRS_CONF_FILE"
# Add hostname to lnd.conf for TLS certificate
DEVICE_HOSTNAME="$(hostname)"
sed -i "s/tlsextradomain=<hostname>/tlsextradomain=$DEVICE_HOSTNAME.local/g;" "$LND_CONF_FILE"
# If node is already synced, do not reset to neutrino
if [[ -f "${STATUS_DIR}/node-status-bitcoind-ready" ]]; then
sed -i "s/bitcoin.node=.*/bitcoin.node=bitcoind/g;" "$LND_CONF_FILE"
fi
# TODO: Update all the above code to use this simpler logic
for template in "${NGINX_CONF_FILE}" "${BITCOIN_CONF_FILE}" "${LND_CONF_FILE}" "${TOR_CONF_FILE}" "${ELECTRS_CONF_FILE}" "${ENV_FILE}"; do
# Umbrel
sed -i "s/<gateway-ip>/${GATEWAY_IP}/g" "${template}"
sed -i "s/<nginx-ip>/${NGINX_IP}/g" "${template}"
sed -i "s/<dashboard-ip>/${DASHBOARD_IP}/g" "${template}"
sed -i "s/<manager-ip>/${MANAGER_IP}/g" "${template}"
sed -i "s/<middleware-ip>/${MIDDLEWARE_IP}/g" "${template}"
sed -i "s/<neutrino-switcher-ip>/${NEUTRINO_SWITCHER_IP}/g" "${template}"
sed -i "s/<frontail-ip>/${FRONTAIL_IP}/g" "${template}"
sed -i "s/<bitcoin-ip>/${BITCOIN_IP}/g" "${template}"
sed -i "s/<lnd-ip>/${LND_IP}/g" "${template}"
sed -i "s/<lnd-grpc-port>/${LND_GRPC_PORT}/g" "${template}"
sed -i "s/<lnd-rest-port>/${LND_REST_PORT}/g" "${template}"
sed -i "s/<electrum-ip>/${ELECTRUM_IP}/g" "${template}"
sed -i "s/<electrum-port>/${ELECTRUM_PORT}/g" "${template}"
sed -i "s/<tor-proxy-ip>/${TOR_PROXY_IP}/g" "${template}"
sed -i "s/<tor-proxy-port>/${TOR_PROXY_PORT}/g" "${template}"
# Apps
sed -i "s/<app-btc-rpc-explorer-ip>/${APP_BTC_RPC_EXPLORER_IP}/g" "${template}"
sed -i "s/<app-btc-rpc-explorer-port>/${APP_BTC_RPC_EXPLORER_PORT}/g" "${template}"
sed -i "s/<app-thunderhub-ip>/${APP_THUNDERHUB_IP}/g" "${template}"
sed -i "s/<app-thunderhub-port>/${APP_THUNDERHUB_PORT}/g" "${template}"
sed -i "s/<app-sphinx-relay-ip>/${APP_SPHINX_RELAY_IP}/g" "${template}"
sed -i "s/<app-sphinx-relay-port>/${APP_SPHINX_RELAY_PORT}/g" "${template}"
sed -i "s/<app-ride-the-lightning-ip>/${APP_RIDE_THE_LIGHTNING_IP}/g" "${template}"
sed -i "s/<app-ride-the-lightning-port>/${APP_RIDE_THE_LIGHTNING_PORT}/g" "${template}"
done
##########################################################
############### Performance optimizations ################
##########################################################
echo
echo "Making performance optimizations"
echo
echo "Setting dbcache size"
echo
if [[ -f "${STATUS_DIR}/node-status-bitcoind-ready" ]]; then
# Limit dbcache to 200 after IBD
DBCACHE_SIZE="200"
else
# Allocate (50% of RAM) - 300MB to dbcache for IDB
DBCACHE_SIZE=$(awk '/MemTotal/{printf "%d\n", ($2/2^10 * 0.5) - 300}' /proc/meminfo)
fi
sed -i -e "s/dbcache=<size>/dbcache=$DBCACHE_SIZE/g" "$BITCOIN_CONF_FILE"
# TODO: Adjust prune size based on available disk space
##########################################################
############## Override main config files ################
##########################################################
mv -f "$NGINX_CONF_FILE" "./nginx/nginx.conf"
mv -f "$BITCOIN_CONF_FILE" "./bitcoin/bitcoin.conf"
mv -f "$LND_CONF_FILE" "./lnd/lnd.conf"
mv -f "$TOR_CONF_FILE" "./tor/torrc"
mv -f "$ELECTRS_CONF_FILE" "./electrs/electrs.toml"
mv -f "$ENV_FILE" "./.env"
##########################################################
################ Configuration complete ##################
##########################################################
echo "Configuring permissions..."
echo
chown -R 1000:1000 "$UMBREL_ROOT"
# Create configured status
touch "${STATUS_DIR}/configured"
echo "Configuration successful"
echo "You can now start Umbrel by running:"
echo " sudo ./scripts/start"
echo