You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

478 lines
21 KiB

#!/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"
APPS_TOR_CONF_FILE="./templates/torrc-apps"
APPS_2_TOR_CONF_FILE="./templates/torrc-apps-2"
APPS_3_TOR_CONF_FILE="./templates/torrc-apps-3"
UMBREL_TOR_CONF_FILE="./templates/torrc-umbrel"
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 "$APPS_TOR_CONF_FILE" ]] && rm -f "$APPS_TOR_CONF_FILE"
[[ -f "$APPS_2_TOR_CONF_FILE" ]] && rm -f "$APPS_2_TOR_CONF_FILE"
[[ -f "$APPS_3_TOR_CONF_FILE" ]] && rm -f "$APPS_3_TOR_CONF_FILE"
[[ -f "$UMBREL_TOR_CONF_FILE" ]] && rm -f "$UMBREL_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-apps-sample" ]] && cp "./templates/torrc-apps-sample" "$APPS_TOR_CONF_FILE"
[[ -f "./templates/torrc-apps-2-sample" ]] && cp "./templates/torrc-apps-2-sample" "$APPS_2_TOR_CONF_FILE"
[[ -f "./templates/torrc-apps-3-sample" ]] && cp "./templates/torrc-apps-3-sample" "$APPS_3_TOR_CONF_FILE"
[[ -f "./templates/torrc-umbrel-sample" ]] && cp "./templates/torrc-umbrel-sample" "$UMBREL_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
NETWORK_IP="10.21.21.0"
GATEWAY_IP="10.21.21.1"
NGINX_IP="10.21.21.2"
NGINX_PORT="${NGINX_PORT:-80}"
DASHBOARD_IP="10.21.21.3"
MANAGER_IP="10.21.21.4"
MIDDLEWARE_IP="10.21.21.5"
NEUTRINO_SWITCHER_IP="10.21.21.6"
BITCOIN_IP="10.21.21.8"
BITCOIN_RPC_PORT="8332"
BITCOIN_P2P_PORT="8333"
BITCOIN_ZMQ_RAWBLOCK_PORT="28332"
BITCOIN_ZMQ_RAWTX_PORT="28333"
BITCOIN_ZMQ_HASHBLOCK_PORT="28334"
LND_IP="10.21.21.9"
LND_GRPC_PORT="10009"
LND_REST_PORT="8080"
ELECTRUM_IP="10.21.21.10"
ELECTRUM_PORT="50001"
TOR_PROXY_IP="10.21.21.11"
APPS_TOR_IP="10.21.21.47"
APPS_2_TOR_IP="10.21.21.48"
APPS_3_TOR_IP="10.21.21.49"
TOR_PROXY_PORT="9050"
# Apps
APP_BTC_RPC_EXPLORER_IP="10.21.21.12"
APP_BTC_RPC_EXPLORER_IP="10.21.21.12"
APP_BTC_RPC_EXPLORER_PORT="3002"
APP_THUNDERHUB_IP="10.21.21.13"
APP_THUNDERHUB_PORT="3000"
APP_SPHINX_RELAY_IP="10.21.21.14"
APP_SPHINX_RELAY_PORT="3300"
APP_RIDE_THE_LIGHTNING_IP="10.21.21.15"
APP_RIDE_THE_LIGHTNING_PORT="3001"
APP_RIDE_THE_LIGHTNING_LOOP_IP="10.21.21.16"
APP_LIGHTNING_TERMINAL_IP="10.21.21.17"
APP_LIGHTNING_TERMINAL_PORT="3004"
APP_SPECTER_DESKTOP_IP="10.21.21.18"
APP_SPECTER_DESKTOP_PORT="25441"
APP_BTCPAY_SERVER_IP="10.21.21.19"
APP_BTCPAY_SERVER_PORT="3003"
APP_BTCPAY_SERVER_NBXPLORER_IP="10.21.21.20"
APP_BTCPAY_SERVER_DB_IP="10.21.21.21"
APP_LNBITS_IP="10.21.21.29"
APP_LNBITS_PORT="3007"
APP_MEMPOOL_IP="10.21.21.26"
APP_MEMPOOL_PORT="3006"
APP_MEMPOOL_API_IP="10.21.21.27"
APP_MEMPOOL_DB_IP="10.21.21.28"
APP_SAMOURAI_SERVER_IP="10.21.21.22"
APP_SAMOURAI_SERVER_DOJO_PORT="3009"
APP_SAMOURAI_SERVER_CONNECT_PORT="3005"
APP_SAMOURAI_SERVER_WHIRLPOOL_IP="10.21.21.23"
APP_SAMOURAI_SERVER_WHIRLPOOL_PORT="8898"
APP_SAMOURAI_SERVER_DB_IP="10.21.21.24"
APP_SAMOURAI_SERVER_NODE_IP="10.21.21.25"
APP_BLUEWALLET_LNDHUB_IP="10.21.21.30"
APP_BLUEWALLET_LNDHUB_PORT="3008"
APP_BLUEWALLET_REDIS_IP="10.21.21.31"
APP_NEXTCLOUD_PORT="8081"
APP_NEXTCLOUD_IP="10.21.21.32"
APP_NEXTCLOUD_DB_IP="10.21.21.33"
APP_NEXTCLOUD_REDIS_IP="10.21.21.34"
APP_NEXTCLOUD_CRON_IP="10.21.21.35"
APP_PI_HOLE_PORT="8082"
APP_PI_HOLE_IP="10.21.21.36"
APP_HOME_ASSISTANT_PORT="8083"
APP_HOME_ASSISTANT_IP="10.21.21.37"
APP_GITEA_PORT="8085"
APP_GITEA_SSH_PORT="2222"
APP_GITEA_IP="10.21.21.39"
APP_GITEA_DB_IP="10.21.21.40"
APP_SIMPLETORRENT_PORT="8086"
APP_SIMPLETORRENT_IP="10.21.21.41"
APP_PHOTOPRISM_IP="10.21.21.42"
APP_PHOTOPRISM_PORT="8087"
APP_PHOTOPRISM_DB_IP="10.21.21.43"
APP_SYNAPSE_IP="10.21.21.44"
APP_SYNAPSE_PORT="8008"
APP_ELEMENT_IP="10.21.21.45"
APP_ELEMENT_PORT="8088"
APP_VAULTWARDEN_IP="10.21.21.46"
APP_VAULTWARDEN_PORT="8089"
APP_CODE_SERVER_IP="10.21.21.53"
APP_CODE_SERVER_PORT="8091"
APP_SQUEAKNODE_IP="10.21.21.54"
APP_SQUEAKNODE_PORT="12994"
APP_SQUEAKNODE_GRPC_PORT="8994"
APP_SQUEAKNODE_P2P_PORT="8555"
APP_SQUEAKNODE_P2P_TESTNET_PORT="18555"
APP_KRYSTAL_BULL_IP="10.21.21.56"
APP_KRYSTAL_BULL_PORT="3010"
APP_KRYSTAL_BULL_SERVER_IP="10.21.21.57"
APP_NODE_RED_IP="10.21.21.55"
APP_NODE_RED_PORT="1880"
APP_LNMARKETS_IP="10.21.21.58"
APP_LNMARKETS_PORT="4242"
# 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, P2P and ZMQ 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;" "$UMBREL_TOR_CONF_FILE"
sed -i "s/<bitcoin-p2p-port>/$BITCOIN_P2P_PORT/g;" "$UMBREL_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;" "$UMBREL_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
# Set LND fee URL (but only for mainnet Neutrino)
LND_FEE_URL=""
if [[ "$BITCOIN_NETWORK" == "mainnet" ]] && [[ ! -f "${STATUS_DIR}/node-status-bitcoind-ready" ]]; then
LND_FEE_URL="https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json"
fi
# TODO: Update all the above code to use this simpler logic
for template in "${NGINX_CONF_FILE}" "${BITCOIN_CONF_FILE}" "${LND_CONF_FILE}" "${APPS_TOR_CONF_FILE}" "${APPS_2_TOR_CONF_FILE}" "${APPS_3_TOR_CONF_FILE}" "${UMBREL_TOR_CONF_FILE}" "${ELECTRS_CONF_FILE}" "${ENV_FILE}"; do
# Umbrel
sed -i "s/<network-ip>/${NETWORK_IP}/g" "${template}"
sed -i "s/<gateway-ip>/${GATEWAY_IP}/g" "${template}"
sed -i "s/<nginx-ip>/${NGINX_IP}/g" "${template}"
sed -i "s/<nginx-port>/${NGINX_PORT}/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/<bitcoin-ip>/${BITCOIN_IP}/g" "${template}"
sed -i "s/<bitcoin-p2p-port>/${BITCOIN_P2P_PORT}/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}"
sed -i "s/<apps-tor-ip>/${APPS_TOR_IP}/g" "${template}"
sed -i "s/<apps-2-tor-ip>/${APPS_2_TOR_IP}/g" "${template}"
sed -i "s/<apps-3-tor-ip>/${APPS_3_TOR_IP}/g" "${template}"
sed -i "s/<zmq-rawblock-port>/${BITCOIN_ZMQ_RAWBLOCK_PORT}/g;" "${template}"
sed -i "s/<zmq-rawtx-port>/${BITCOIN_ZMQ_RAWTX_PORT}/g;" "${template}"
sed -i "s/<zmq-hashblock-port>/${BITCOIN_ZMQ_HASHBLOCK_PORT}/g;" "${template}"
sed -i "s#<lndfeeurl>#${LND_FEE_URL}#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}"
sed -i "s/<app-ride-the-lightning-loop-ip>/${APP_RIDE_THE_LIGHTNING_LOOP_IP}/g" "${template}"
sed -i "s/<app-lightning-terminal-ip>/${APP_LIGHTNING_TERMINAL_IP}/g" "${template}"
sed -i "s/<app-lightning-terminal-port>/${APP_LIGHTNING_TERMINAL_PORT}/g" "${template}"
sed -i "s/<app-specter-desktop-ip>/${APP_SPECTER_DESKTOP_IP}/g" "${template}"
sed -i "s/<app-specter-desktop-port>/${APP_SPECTER_DESKTOP_PORT}/g" "${template}"
sed -i "s/<app-btcpay-server-ip>/${APP_BTCPAY_SERVER_IP}/g" "${template}"
sed -i "s/<app-btcpay-server-port>/${APP_BTCPAY_SERVER_PORT}/g" "${template}"
sed -i "s/<app-btcpay-server-nbxplorer-ip>/${APP_BTCPAY_SERVER_NBXPLORER_IP}/g" "${template}"
sed -i "s/<app-btcpay-server-db-ip>/${APP_BTCPAY_SERVER_DB_IP}/g" "${template}"
sed -i "s/<app-lnbits-ip>/${APP_LNBITS_IP}/g" "${template}"
sed -i "s/<app-lnbits-port>/${APP_LNBITS_PORT}/g" "${template}"
sed -i "s/<app-mempool-ip>/${APP_MEMPOOL_IP}/g" "${template}"
sed -i "s/<app-mempool-port>/${APP_MEMPOOL_PORT}/g" "${template}"
sed -i "s/<app-mempool-db-ip>/${APP_MEMPOOL_DB_IP}/g" "${template}"
sed -i "s/<app-mempool-api-ip>/${APP_MEMPOOL_API_IP}/g" "${template}"
sed -i "s/<app-samourai-server-ip>/${APP_SAMOURAI_SERVER_IP}/g" "${template}"
sed -i "s/<app-samourai-server-dojo-port>/${APP_SAMOURAI_SERVER_DOJO_PORT}/g" "${template}"
sed -i "s/<app-samourai-server-connect-port>/${APP_SAMOURAI_SERVER_CONNECT_PORT}/g" "${template}"
sed -i "s/<app-samourai-server-whirlpool-ip>/${APP_SAMOURAI_SERVER_WHIRLPOOL_IP}/g" "${template}"
sed -i "s/<app-samourai-server-whirlpool-port>/${APP_SAMOURAI_SERVER_WHIRLPOOL_PORT}/g" "${template}"
sed -i "s/<app-samourai-server-db-ip>/${APP_SAMOURAI_SERVER_DB_IP}/g" "${template}"
sed -i "s/<app-samourai-server-node-ip>/${APP_SAMOURAI_SERVER_NODE_IP}/g" "${template}"
sed -i "s/<app-bluewallet-lndhub-ip>/${APP_BLUEWALLET_LNDHUB_IP}/g" "${template}"
sed -i "s/<app-bluewallet-lndhub-port>/${APP_BLUEWALLET_LNDHUB_PORT}/g" "${template}"
sed -i "s/<app-bluewallet-redis-ip>/${APP_BLUEWALLET_REDIS_IP}/g" "${template}"
sed -i "s/<app-nextcloud-port>/${APP_NEXTCLOUD_PORT}/g" "${template}"
sed -i "s/<app-nextcloud-ip>/${APP_NEXTCLOUD_IP}/g" "${template}"
sed -i "s/<app-nextcloud-db-ip>/${APP_NEXTCLOUD_DB_IP}/g" "${template}"
sed -i "s/<app-nextcloud-redis-ip>/${APP_NEXTCLOUD_REDIS_IP}/g" "${template}"
sed -i "s/<app-nextcloud-cron-ip>/${APP_NEXTCLOUD_CRON_IP}/g" "${template}"
sed -i "s/<app-pi-hole-port>/${APP_PI_HOLE_PORT}/g" "${template}"
sed -i "s/<app-pi-hole-ip>/${APP_PI_HOLE_IP}/g" "${template}"
sed -i "s/<app-home-assistant-port>/${APP_HOME_ASSISTANT_PORT}/g" "${template}"
sed -i "s/<app-home-assistant-ip>/${APP_HOME_ASSISTANT_IP}/g" "${template}"
sed -i "s/<app-gitea-port>/${APP_GITEA_PORT}/g" "${template}"
sed -i "s/<app-gitea-ssh-port>/${APP_GITEA_SSH_PORT}/g" "${template}"
sed -i "s/<app-gitea-ip>/${APP_GITEA_IP}/g" "${template}"
sed -i "s/<app-gitea-db-ip>/${APP_GITEA_DB_IP}/g" "${template}"
sed -i "s/<app-simple-torrent-port>/${APP_SIMPLETORRENT_PORT}/g" "${template}"
sed -i "s/<app-simple-torrent-ip>/${APP_SIMPLETORRENT_IP}/g" "${template}"
sed -i "s/<app-photoprism-ip>/${APP_PHOTOPRISM_IP}/g" "${template}"
sed -i "s/<app-photoprism-port>/${APP_PHOTOPRISM_PORT}/g" "${template}"
sed -i "s/<app-photoprism-db-ip>/${APP_PHOTOPRISM_DB_IP}/g" "${template}"
sed -i "s/<app-synapse-ip>/${APP_SYNAPSE_IP}/g" "${template}"
sed -i "s/<app-synapse-port>/${APP_SYNAPSE_PORT}/g" "${template}"
sed -i "s/<app-element-ip>/${APP_ELEMENT_IP}/g" "${template}"
sed -i "s/<app-element-port>/${APP_ELEMENT_PORT}/g" "${template}"
sed -i "s/<app-vaultwarden-ip>/${APP_VAULTWARDEN_IP}/g" "${template}"
sed -i "s/<app-vaultwarden-port>/${APP_VAULTWARDEN_PORT}/g" "${template}"
sed -i "s/<app-code-server-ip>/${APP_CODE_SERVER_IP}/g" "${template}"
sed -i "s/<app-code-server-port>/${APP_CODE_SERVER_PORT}/g" "${template}"
sed -i "s/<app-squeaknode-ip>/${APP_SQUEAKNODE_IP}/g" "${template}"
sed -i "s/<app-squeaknode-port>/${APP_SQUEAKNODE_PORT}/g" "${template}"
sed -i "s/<app-squeaknode-grpc-port>/${APP_SQUEAKNODE_GRPC_PORT}/g" "${template}"
sed -i "s/<app-squeaknode-p2p-port>/${APP_SQUEAKNODE_P2P_PORT}/g" "${template}"
sed -i "s/<app-squeaknode-p2p-testnet-port>/${APP_SQUEAKNODE_P2P_TESTNET_PORT}/g" "${template}"
sed -i "s/<app-krystal-bull-ip>/${APP_KRYSTAL_BULL_IP}/g" "${template}"
sed -i "s/<app-krystal-bull-port>/${APP_KRYSTAL_BULL_PORT}/g" "${template}"
sed -i "s/<app-krystal-bull-server-ip>/${APP_KRYSTAL_BULL_SERVER_IP}/g" "${template}"
sed -i "s/<app-node-red-ip>/${APP_NODE_RED_IP}/g" "${template}"
sed -i "s/<app-node-red-port>/${APP_NODE_RED_PORT}/g" "${template}"
sed -i "s/<app-lnmarkets-ip>/${APP_LNMARKETS_IP}/g" "${template}"
sed -i "s/<app-lnmarkets-port>/${APP_LNMARKETS_PORT}/g" "${template}"
done
##########################################################
############## Override main config files ################
##########################################################
mv -f "$NGINX_CONF_FILE" "./nginx/nginx.conf"
mv -f "$BITCOIN_CONF_FILE" "./bitcoin/bitcoin.conf"
mv -f "$APPS_TOR_CONF_FILE" "./tor/torrc-apps"
mv -f "$APPS_2_TOR_CONF_FILE" "./tor/torrc-apps-2"
mv -f "$APPS_3_TOR_CONF_FILE" "./tor/torrc-apps-3"
mv -f "$UMBREL_TOR_CONF_FILE" "./tor/torrc-umbrel"
mv -f "$ELECTRS_CONF_FILE" "./electrs/electrs.toml"
mv -f "$ENV_FILE" "./.env"
# Only write LND config if one doesn't already exist to preserve any user changes.
if [[ -f "./lnd/lnd.conf" ]]; then
echo "Skipping lnd.conf update to preserve user changes..."
rm "$LND_CONF_FILE"
else
mv -f "$LND_CONF_FILE" "./lnd/lnd.conf"
fi
##########################################################
######### Generate hidden services on first run ##########
##########################################################
# Prevents CORS issue if dashboard's hidden service
# doesn't exist on the first run
if [[ ! -f "${STATUS_DIR}/configured" ]]; then
echo "Generating hidden services..."
echo
docker-compose up --detach tor
wait_for_tor=10
while [[ ! -f "${UMBREL_ROOT}/tor/data/web/hostname" ]]; do
if [[ "${wait_for_tor}" == 0 ]]; then
echo "Dashboard's hidden service file wasn't created..."
echo
break
fi
sleep 1
((wait_for_tor--))
done
docker-compose down
fi
##########################################################
################ Configuration complete ##################
##########################################################
echo "Configuring permissions..."
echo
find "$UMBREL_ROOT" -path "$UMBREL_ROOT/app-data" -prune -o -exec chown 1000:1000 {} +
# Create configured status
touch "${STATUS_DIR}/configured"
echo "Configuration successful"
echo "You can now start Umbrel by running:"
echo " sudo ./scripts/start"
echo