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

ref(docker) home_default -> profile_default

parent 2587a56e
No related branches found
No related tags found
1 merge request!1387Docker - Duniter wrapper + Entrypoint can survive a config / peers.db loss
......@@ -13,7 +13,7 @@ fi
# Initialize vars
home=/var/lib/duniter
home_default=$home/duniter_default
profile_default=$home/duniter_default
manual_config="$(boolean "${DUNITER_MANUAL_CONFIG:-false}")"
auto_sync="$(boolean "${DUNITER_AUTO_SYNC:-false}")"
DUNITER_PEER_HOST="${DUNITER_PEER_HOST:-${DUNITER_SYNC_HOST:-}}"
......@@ -24,33 +24,33 @@ mkdir -p "$home/duniter_default"
# Manual config when enabled
if [ "$manual_config" = true ]; then
# Do not start until a configuration file was initialized
while ! [ -f "$home_default/conf.json.orig" ]; do
echo "Waiting for initial configuration file... Please copy your configuration file to '$home_default/conf.json.orig'"
while ! [ -f "$profile_default/conf.json.orig" ]; do
echo "Waiting for initial configuration file... Please copy your configuration file to '$profile_default/conf.json.orig'"
sleep 10
done
echo "Configuration file found. Continuing..."
# Use new conf.json.orig when changed
md5_file="$home_default/conf.json.orig.md5"
md5_file="$profile_default/conf.json.orig.md5"
if ! md5sum -c "$md5_file"; then
if [ -f "$home_default/conf.json" ]; then
echo "Backing up old configuration file to '$home_default/conf.json.old'..."
mv $home_default/conf.json $home_default/conf.json.old
if [ -f "$profile_default/conf.json" ]; then
echo "Backing up old configuration file to '$profile_default/conf.json.old'..."
mv $profile_default/conf.json $profile_default/conf.json.old
fi
echo "Installing new configuration file..."
cp "$home_default/conf.json.orig" "$home_default/conf.json"
md5sum "$home_default/conf.json.orig" >"$md5_file"
cp "$profile_default/conf.json.orig" "$profile_default/conf.json"
md5sum "$profile_default/conf.json.orig" >"$md5_file"
fi
# Log differences between initial, old and current conf file
jq --sort-keys -r . "$home_default/conf.json.orig" >"$home_default/conf.json.orig.sorted"
jq --sort-keys -r . "$home_default/conf.json" >"$home_default/conf.json.sorted"
if [ -f "$home_default/conf.json.old" ]; then
jq --sort-keys -r . "$home_default/conf.json.old" >"$home_default/conf.json.old.sorted"
if ! diff -q "$home_default/conf.json.old.sorted" "$home_default/conf.json.orig.sorted"; then
diff -u "$home_default/conf.json.old.sorted" "$home_default/conf.json.orig.sorted"
jq --sort-keys -r . "$profile_default/conf.json.orig" >"$profile_default/conf.json.orig.sorted"
jq --sort-keys -r . "$profile_default/conf.json" >"$profile_default/conf.json.sorted"
if [ -f "$profile_default/conf.json.old" ]; then
jq --sort-keys -r . "$profile_default/conf.json.old" >"$profile_default/conf.json.old.sorted"
if ! diff -q "$profile_default/conf.json.old.sorted" "$profile_default/conf.json.orig.sorted"; then
diff -u "$profile_default/conf.json.old.sorted" "$profile_default/conf.json.orig.sorted"
fi
fi
if ! diff -q "$home_default/conf.json.orig.sorted" "$home_default/conf.json.sorted"; then
diff -u "$home_default/conf.json.orig.sorted" "$home_default/conf.json.sorted"
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
......@@ -59,7 +59,7 @@ fi
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 "$home_default/conf.json" ] && echo "${DUNITER_PEER_HOST}" | grep -E "^($host_regex|$ipv6_regex)(:[0-9]+)?$"; then
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
......@@ -67,8 +67,8 @@ if ! [ -f "$home_default/conf.json" ] && echo "${DUNITER_PEER_HOST}" | grep -E "
else
scheme=http://
fi
if wget -q -O- "$scheme$DUNITER_PEER_HOST/blockchain/parameters" >"$home_default/conf.json.new"; then
mv "$home_default/conf.json.new" "$home_default/conf.json"
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
......@@ -78,13 +78,13 @@ fi
# 'sync --only-peers'
# Working into a temporary Duniter home to avoid side effects on the current
# database
if ! [ -f "$home_default/peers.db" ] && [ -n "${DUNITER_PEER_HOST:-}" ]; then
if ! [ -f "$profile_default/peers.db" ] && [ -n "${DUNITER_PEER_HOST:-}" ]; then
echo "No peers database - Initializing from '$DUNITER_PEER_HOST'..."
rm -fr /tmp/duniter-bootstrap
(
cd /duniter
if bin/duniter --home /tmp/duniter-bootstrap sync "$DUNITER_PEER_HOST" --no-interactive --only-peers; then
mv /tmp/duniter-bootstrap/duniter_default/peers.db "$home_default/"
mv /tmp/duniter-bootstrap/duniter_default/peers.db "$profile_default/"
else
echo -e "$big_fat_warning Failed."
fi
......@@ -94,7 +94,7 @@ fi
# Auto start synchronization when enabled and starting from scratch
if [ "$auto_sync" = true ]; then
if ! [ -d "$home_default/data" ]; then
if ! [ -d "$profile_default/data" ]; then
echo "No 'data' folder. "
if [ -z "$DUNITER_SYNC_HOST:-" ]; then
echo "DUNITER_SYNC_HOST undefined. Can't start synchronization!"
......
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