diff --git a/release/docker/docker-entrypoint.sh b/release/docker/docker-entrypoint.sh index d12521eb1960c27b460f3b19f1ce36975ae75d19..db959ccc0628b0b3ad47d2a6215a0e4ae7cd2451 100755 --- a/release/docker/docker-entrypoint.sh +++ b/release/docker/docker-entrypoint.sh @@ -1,19 +1,41 @@ #!/bin/sh - -home=/var/lib/duniter -config=/etc/duniter -home_default=$home/duniter_default +set -u function boolean () { echo "$1" | sed -E 's/^(true|yes|1)$/true/i' } +big_fat_warning='\033[01;31m**WARNING**:\033[0m' + +DEBUG_ENTRYPOINT="$(boolean "${DEBUG_ENTRYPOINT:-false}")" +if [ "$DEBUG_ENTRYPOINT" = true ]; then + set -x +fi + +home=/var/lib/duniter +config=/etc/duniter +home_default=$home/duniter_default manual_config="$(boolean "${DUNITER_MANUAL_CONFIG:-false}")" auto_sync="$(boolean "${DUNITER_AUTO_SYNC:-false}")" -# Use path /etc/duniter/conf.json -if ! [ -f "$config/conf.json" ] && [ -f "$home_default/conf.json" ]; then - mv "$home_default/conf.json" "$conf/conf.json" +# Use new path /etc/duniter/conf.json +if ! [ -f "$config/conf.json" ]; then + if [ "$(readlink "$home_default/conf.json")" = "$config/conf.json" ]; then + # The configuration file was moved already but the link is dangling + # It is likely that '/etc/duniter' is an anonymous volume + echo -e "$big_fat_warning Your configuration file didn't survive the restart!" + echo -e "$big_fat_warning Make sure that '/etc/duniter' is explicitely mounted as a persistent volume or you'll lose it again." + if [ -f "$home_default/conf.json.backup" ]; then + echo -e "$big_fat_warning Found backup file '$home_default/conf.json.backup'; using it..." + mv "$home_default/conf.json.backup" "$home_default/conf.json" + fi + fi + if [ -f "$home_default/conf.json" ]; then + echo "Moving existing configuration file '$home_default/conf.json' to its new location: '$config/conf.json'" + echo "A backup is kept at '$home_default/conf.json.backup'" + cp "$home_default/conf.json" "$home_default/conf.json.backup" + mv "$home_default/conf.json" "$config/conf.json" + fi fi mkdir -p "$home/duniter_default" ln -fs "$config/conf.json" "$home_default/conf.json" @@ -55,11 +77,11 @@ fi if [ "$auto_sync" = true ]; then if ! [ -d "$home_default/data" ]; then echo "No 'data' folder. " - if [ -z "$DUNITER_SYNC_HOST" ]; then + if [ -z "$DUNITER_SYNC_HOST:-" ]; then echo "DUNITER_SYNC_HOST undefined. Can't start synchronization!" else echo "Starting synchronization..." - /usr/bin/duniter --home "$home" sync "$DUNITER_SYNC_HOST" + /usr/bin/duniter sync "$DUNITER_SYNC_HOST" fi fi fi