diff --git a/nodebuilder b/nodebuilder index 03ba7dd6e..093bee733 100755 --- a/nodebuilder +++ b/nodebuilder @@ -637,6 +637,21 @@ ensure_xargs_dependency() fi } +get_directory_size_in_mib() +{ + if [ $# -ne 1 ]; then + throw_error 'get_directory_size_in_mib() requires 1 argument.' + fi + + readonly directory_to_check="$1" + + if [ -d "${directory_to_check}/" ]; then + BLOCKSIZE=1M du -d0 "${directory_to_check}" | cut -f1 + else + printf '0\n' + fi +} + get_free_space_in_mib() { BLOCKSIZE=1M df "${BITCOIN_DATA_DIRECTORY}" | awk 'NR==2 {print $4}' @@ -1688,42 +1703,8 @@ if [ ! -f "${BITCOIN_CORE_CONFIG_FILE}" ]; then set_bitcoin_core_option 'server' '1' fi -# Synced data and prune checks -readonly BITCOIN_CORE_BLOCKS_DIRECTORY="${BITCOIN_DATA_DIRECTORY}/blocks" -if [ -d "${BITCOIN_CORE_BLOCKS_DIRECTORY}"/ ]; then - case "${TARGET_KERNEL}" in - Darwin | FreeBSD | NetBSD) - INITIAL_BLOCKS_SIZE_IN_MIB="$(du -d0 -m "${BITCOIN_CORE_BLOCKS_DIRECTORY}" | cut -f1)" - ;; - OpenBSD) - INITIAL_BLOCKS_SIZE_IN_MIB="$(BLOCKSIZE=1M du -d0 "${BITCOIN_CORE_BLOCKS_DIRECTORY}" | cut -f1)" - ;; - *) - INITIAL_BLOCKS_SIZE_IN_MIB="$(du -d0 --block-size='1MiB' "${BITCOIN_CORE_BLOCKS_DIRECTORY}" | cut -f1)" - ;; - esac -else - INITIAL_BLOCKS_SIZE_IN_MIB=0 -fi -readonly INITIAL_BLOCKS_SIZE_IN_MIB -readonly BITCOIN_CORE_CHAINSTATE_DIRECTORY="${BITCOIN_DATA_DIRECTORY}/chainstate" -if [ -d "${BITCOIN_CORE_CHAINSTATE_DIRECTORY}"/ ]; then - case "${TARGET_KERNEL}" in - Darwin | FreeBSD | NetBSD) - INITIAL_CHAINSTATE_SIZE_IN_MIB="$(du -d0 -m "${BITCOIN_CORE_CHAINSTATE_DIRECTORY}" | cut -f1)" - ;; - OpenBSD) - INITIAL_CHAINSTATE_SIZE_IN_MIB="$(BLOCKSIZE=1M du -d0 "${BITCOIN_CORE_CHAINSTATE_DIRECTORY}" | cut -f1)" - ;; - *) - INITIAL_CHAINSTATE_SIZE_IN_MIB="$(du -d0 --block-size='1MiB' "${BITCOIN_CORE_CHAINSTATE_DIRECTORY}" | cut -f1)" - ;; - esac -else - INITIAL_CHAINSTATE_SIZE_IN_MIB=0 -fi -readonly INITIAL_CHAINSTATE_SIZE_IN_MIB -readonly INITIAL_DATA_ALREADY_SYNCED_IN_MIB=$((INITIAL_BLOCKS_SIZE_IN_MIB + INITIAL_CHAINSTATE_SIZE_IN_MIB)) +INITIAL_DATA_ALREADY_SYNCED_IN_MIB="$(($(get_directory_size_in_mib "${BITCOIN_DATA_DIRECTORY}/blocks") + $(get_directory_size_in_mib "${BITCOIN_DATA_DIRECTORY}/chainstate")))" +readonly INITIAL_DATA_ALREADY_SYNCED_IN_MIB log_info "Found data already synced... $((INITIAL_DATA_ALREADY_SYNCED_IN_MIB / MIB_TO_GIB)) GiB." free_space_in_mib="$(get_free_space_in_mib)"