Skip to content
Snippets Groups Projects
Commit effc1f61 authored by Gilles Filippini's avatar Gilles Filippini
Browse files

docker: add variables for BMA and WS2P config

parent a12afdb5
No related branches found
No related tags found
No related merge requests found
Pipeline #33516 waiting for manual action
......@@ -2,7 +2,7 @@
set -uo pipefail
boolean () {
echo "$1" | sed -E 's/^(true|yes|1)$/true/i'
echo "$1" | sed -E 's/^(true|yes|1)$/true/i;/^true/!{s/^.*$/false/}'
}
big_fat_warning='\033[01;31m**WARNING**:\033[0m'
......@@ -56,26 +56,90 @@ if [ "$manual_config" = true ]; then
if ! diff -q "$profile_default/conf.json.orig.sorted" "$profile_default/conf.json.sorted"; then
diff -u "$profile_default/conf.json.orig.sorted" "$profile_default/conf.json.sorted"
fi
fi
# If conf.json doesn't exist and we have DUNITER_PEER_HOST, then initialise it with
# the currency parameters
host_regex='[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9]+)?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9]+)?)*'
ipv6_regex='((([0–9A-Fa-f]{1,4}:){7}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){6}:[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){5}:([0–9A-Fa-f]{1,4}:)?[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){4}:([0–9A-Fa-f]{1,4}:){0,2}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){3}:([0–9A-Fa-f]{1,4}:){0,3}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){2}:([0–9A-Fa-f]{1,4}:){0,4}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){6}((b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b).){3}(b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b))|(([0–9A-Fa-f]{1,4}:){0,5}:((b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b).){3}(b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b))|(::([0–9A-Fa-f]{1,4}:){0,5}((b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b).){3}(b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b))|([0–9A-Fa-f]{1,4}::([0–9A-Fa-f]{1,4}:){0,5}[0–9A-Fa-f]{1,4})|(::([0–9A-Fa-f]{1,4}:){0,6}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){1,7}:))'
if ! [ -f "$profile_default/conf.json" ] && echo "${DUNITER_PEER_HOST}" | grep -E "^($host_regex|$ipv6_regex)(:[0-9]+)?$"; then
echo "No config file - Initializing currency from '$DUNITER_PEER_HOST'..."
port="${DUNITER_PEER_HOST#*:}"
if [ "${port:-443}" = 443 ]; then
scheme=https://
else
# If conf.json doesn't exist and we have DUNITER_PEER_HOST, then initialise it with
# the currency parameters
host_regex='[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9]+)?(\.[a-zA-Z0-9](([a-zA-Z0-9]|-)*[a-zA-Z0-9]+)?)*'
ipv6_regex='((([0–9A-Fa-f]{1,4}:){7}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){6}:[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){5}:([0–9A-Fa-f]{1,4}:)?[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){4}:([0–9A-Fa-f]{1,4}:){0,2}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){3}:([0–9A-Fa-f]{1,4}:){0,3}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){2}:([0–9A-Fa-f]{1,4}:){0,4}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){6}((b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b).){3}(b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b))|(([0–9A-Fa-f]{1,4}:){0,5}:((b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b).){3}(b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b))|(::([0–9A-Fa-f]{1,4}:){0,5}((b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b).){3}(b((25[0–5])|(1d{2})|(2[0–4]d)|(d{1,2}))b))|([0–9A-Fa-f]{1,4}::([0–9A-Fa-f]{1,4}:){0,5}[0–9A-Fa-f]{1,4})|(::([0–9A-Fa-f]{1,4}:){0,6}[0–9A-Fa-f]{1,4})|(([0–9A-Fa-f]{1,4}:){1,7}:))'
if ! [ -f "$profile_default/conf.json" ] && echo "${DUNITER_PEER_HOST}" | grep -E "^($host_regex|$ipv6_regex)(:[0-9]+)?$"; then
echo "No config file - Initializing currency from '$DUNITER_PEER_HOST'..."
port="${DUNITER_PEER_HOST#*:}"
if [ "${port:-443}" = 443 ]; then
scheme=https://
else
scheme=http://
fi
if wget -q -O- "$scheme$DUNITER_PEER_HOST/blockchain/parameters" >"$profile_default/conf.json.new"; then
mv "$profile_default/conf.json.new" "$profile_default/conf.json"
else
echo -e "$big_fat_warning Failed."
fi
fi
# BMA configuration
if [ "$(boolean "${DUNITER_BMA_ENABLED:-false}")" = true ]; then
DUNITER_BMA_IP4="${DUNITER_BMA_IP4:-0.0.0.0}"
DUNITER_BMA_PORT="${DUNITER_BMA_PORT:-10901}"
DUNITER_BMA_REMOTE_HOST="${DUNITER_BMA_REMOTE_HOST:-$(hostname)}"
DUNITER_BMA_REMOTE_PORT="${DUNITER_BMA_REMOTE_PORT:-$DUNITER_BMA_PORT}"
jq -r '
del(.nobma, .ipv4, .port, .remoteport, .remotehost) |
. += {
"nobma": false,
"ipv4": "'$DUNITER_BMA_IP4'",
"port": "'$DUNITER_BMA_PORT'",
"remotehost": "'$DUNITER_BMA_REMOTE_HOST'",
"remoteport": "'$DUNITER_BMA_REMOTE_PORT'"
}
' "$profile_default/conf.json" >"$profile_default/conf.json.new"
else
scheme=http://
jq -r '
del(.nobma, .ipv4, .port, .remoteport, .remotehost) |
. += {
"nobma": true,
}
' "$profile_default/conf.json" >"$profile_default/conf.json.new"
fi
if wget -q -O- "$scheme$DUNITER_PEER_HOST/blockchain/parameters" >"$profile_default/conf.json.new"; then
mv "$profile_default/conf.json.new" "$profile_default/conf.json"
mv "$profile_default/conf.json.new" "$profile_default/conf.json"
# WS2P configuration
if [ -n "${DUNITER_WS2P_HOST:-}" ]; then
DUNITER_WS2P_PORT="${DUNITER_WS2P_PORT:-20901}"
DUNITER_WS2P_PUBLIC="${DUNITER_WS2P_PUBLIC:-false}"
DUNITER_WS2P_REMOTE_HOST="${DUNITER_WS2P_REMOTE_HOST:-$(hostname)}"
DUNITER_WS2P_REMOTE_PORT="${DUNITER_WS2P_REMOTE_PORT:-$DUNITER_WS2P_PORT}"
DUNITER_WS2P_REMOTE_PATH="${DUNITER_WS2P_REMOTE_PATH:-}"
jq -r '
del(.ws2p.host, .ws2p.port, .ws2p.publicAccess, .ws2p.remoteport, .ws2p.remotehost, .ws2p.remotepath) |
.ws2p += {
"host": "'$DUNITER_WS2P_HOST'",
"port": "'$DUNITER_WS2P_PORT'",
"publicAccess": '$DUNITER_WS2P_PUBLIC',
"remotehost": "'$DUNITER_WS2P_REMOTE_HOST'",
"remoteport": "'$DUNITER_WS2P_REMOTE_PORT'",
"remotepath": "'$DUNITER_WS2P_REMOTE_PATH'",
}
' "$profile_default/conf.json" >"$profile_default/conf.json.new"
else
echo -e "$big_fat_warning Failed."
jq -r '
del(.ws2p.host, .ws2p.port, .ws2p.publicAccess, .ws2p.remoteport, .ws2p.remotehost, .ws2p.remotepath)
' "$profile_default/conf.json" >"$profile_default/conf.json.new"
fi
mv "$profile_default/conf.json.new" "$profile_default/conf.json"
# UPNP
DUNITER_UPNP="$(boolean "${DUNITER_UPNP:-true}")"
jq -r '
del(.upnp, .ws2p.upnp) |
. += {
"upnp": '$DUNITER_UPNP',
} |
.ws2p += {
"upnp": '$DUNITER_UPNP',
}
' "$profile_default/conf.json" >"$profile_default/conf.json.new"
mv "$profile_default/conf.json.new" "$profile_default/conf.json"
# If peers.db is missing and DUNITER_PEER_HOST is set, bootstrap it using
# 'sync --only-peers'
......@@ -93,7 +157,7 @@ if ! [ -f "$profile_default/conf.json" ] && echo "${DUNITER_PEER_HOST}" | grep -
)
rm -fr /tmp/duniter-bootstrap
fi
fi
fi # manual_config
# Auto start synchronization when enabled and starting from scratch
if [ "$auto_sync" = true ]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment