Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions bails/.local/bin/core-welcome-text
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash

# Copyright (c) 2026 Ben Westgate
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Print the first-install Welcome text, built from Bitcoin Core's own Intro
# dialog strings in an authenticated release source tree.
#
# Usage: core-welcome-text INTRO_UI INTRO_CPP REQUIRED_GB BLOCKCHAIN_GB \
# PRUNE_GB BACKUP_DAYS
#
# PRUNE_GB is 0 when pruning is off. Exits non-zero, printing nothing, when a
# string is missing or no longer reads the way CipherStick adapts it, so the
# caller can fall back to its built-in text.

set -u

[ "$#" -eq 6 ] || exit 2
intro_ui=$1 intro_cpp=$2 required_gb=$3 blockchain_gb=$4 prune_gb=$5 backup_days=$6
for n in "$required_gb" "$blockchain_gb" "$prune_gb" "$backup_days"; do
[[ "$n" =~ ^[0-9]+$ ]] || exit 2
done
[ -r "$intro_ui" ] && [ -r "$intro_cpp" ] || exit 1

client='Bitcoin Core'

xml_unescape() {
sed 's/&quot;/"/g; s/&apos;/'"'"'/g; s/&lt;/</g; s/&gt;/>/g; s/&amp;/\&/g'
}

# zenity renders --text as Pango markup.
markup_escape() {
local s=${1//&/&amp;}
s=${s//</&lt;}
printf '%s' "${s//>/&gt;}"
}

# Print the first Intro string that starts with $1, from intro.ui or tr("...")
# in intro.cpp. Fail if it is absent.
core_string() {
local s
s=$(grep -m1 -oP "(?<=<string>)\Q$1\E[^<]*(?=</string>)" "$intro_ui" | xml_unescape)
[ -n "$s" ] || s=$(grep -m1 -oP "(?<=tr\(\")\Q$1\E[^\"]*(?=\")" "$intro_cpp")
[ -n "$s" ] || return 1
printf '%s' "$s"
}

# Replace the literal $2 in $1 with $3. Fail if $2 does not occur.
adapt() {
[[ "$1" == *"$2"* ]] || return 1
printf '%s' "${1//"$2"/"$3"}"
}

welcome=$(core_string 'Welcome to %1.') || exit 1
download=$(core_string '%1 will download and store a copy of the Bitcoin block chain.') || exit 1
begin=$(core_string 'When you click OK, %1 will begin to download') || exit 1
demanding=$(core_string 'This initial synchronisation is very demanding') || exit 1

welcome=${welcome//%1/$client}
download=${download//%1/$client}
begin=${begin//%1/$client}
begin=${begin//%2/$blockchain_gb}
begin=${begin//%3/2009}
begin=${begin//%4/Bitcoin}
demanding=${demanding//%1/$client}

# Bitcoin Core is already downloading while this dialog is shown.
begin=$(adapt "$begin" "When you click OK, $client will begin to download" \
"$client has begun to download") || exit 1

# CipherStick fixes the data directory inside Persistent Storage and chooses the
# prune target itself, so adapt Core's wording for those too.
if ((prune_gb)); then
storage=$(core_string 'Approximately %1 GB of data will be stored in this directory.') || exit 1
pruning=$(core_string 'If you have chosen to limit block chain storage (pruning),') || exit 1
backup=$(core_string '(sufficient to restore backups %n day(s) old)') || exit 1
days=days
((backup_days == 1)) && days=day
backup=$(adapt "$backup" '%n day(s)' "$backup_days $days") || exit 1
pruning=$(adapt "$pruning" 'If you have chosen to limit block chain storage (pruning),' \
"CipherStick has chosen to limit block chain storage (pruning) to $prune_gb GB $backup,") || exit 1
else
storage=$(core_string 'At least %1 GB of data will be stored in this directory') || exit 1
pruning=
fi
storage=${storage//%1/$required_gb}
storage=$(adapt "$storage" 'in this directory' 'in your Persistent Storage') || exit 1

text="<i>$(markup_escape "$welcome")</i>

$(markup_escape "$download $storage")

$(markup_escape "$begin")

$(markup_escape "$demanding")"
[ -n "$pruning" ] && text+="

$(markup_escape "$pruning")"
printf '%s\n' "$text"
23 changes: 19 additions & 4 deletions bails/.local/bin/install-core
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ if [ "$action" = installation ]; then
((master_blockchain_size >= release_blockchain_size && master_blockchain_size <= release_blockchain_size * 2)); then
assumed_blockchain_size=$master_blockchain_size
fi
# Keep Bitcoin Core's own first-run Intro strings for the Welcome dialog.
# A missing file only falls back to CipherStick's built-in text.
intro_dir=$(mktemp -d)
tar -xOf "$source_tar" "$source_root/src/qt/forms/intro.ui" >"$intro_dir/intro.ui" &&
tar -xOf "$source_tar" "$source_root/src/qt/intro.cpp" >"$intro_dir/intro.cpp"
fi
rm -f "$source_tar"

Expand Down Expand Up @@ -306,17 +311,27 @@ else
"server": true
}' > $DATA_DIR/settings.json # Enable server, proxies for Tor and prune

expected_backup_days=0
if ((prune_MiB)); then
storageRequiresMsg="Approximately $((prune_GB + assumed_chain_state_size)) GB of data will be stored in your Persistent Storage."
required_GB=$((prune_GB + assumed_chain_state_size))
storageRequiresMsg="Approximately $required_GB GB of data will be stored in your Persistent Storage."
expected_backup_days=$((prune_GB * 10**9 / (2250000 * 86400 / 600)))
prune_explanation="\n\nCipherStick has chosen to limit block chain storage (pruning) to $prune_GB GB (sufficient to restore backups $expected_backup_days days old), the historical data must still be downloaded and processed, but will be deleted afterward to keep your disk usage low."
else
storageRequiresMsg="At least $((assumed_blockchain_size + assumed_chain_state_size)) GB of data will be stored in your Persistent Storage, and it will grow over time."
required_GB=$((assumed_blockchain_size + assumed_chain_state_size))
storageRequiresMsg="At least $required_GB GB of data will be stored in your Persistent Storage, and it will grow over time."
fi
zenity --info --title Welcome --icon-name=bitcoin128 --text="<i>Welcome to Bitcoin Core.</i>\n\n
# Prefer Bitcoin Core's own Intro wording from the authenticated release
# source; fall back to the built-in copy if any string has changed.
if ! welcome_text=$(core-welcome-text "${intro_dir:-}/intro.ui" "${intro_dir:-}/intro.cpp" \
"$required_GB" "$assumed_blockchain_size" "$((prune_MiB ? prune_GB : 0))" "$expected_backup_days"); then
welcome_text="<i>Welcome to Bitcoin Core.</i>\n\n
Bitcoin Core will download and store a copy of the Bitcoin block chain. $storageRequiresMsg\n
Bitcoin Core has begun to download and process the full Bitcoin block chain ($assumed_blockchain_size GB) starting with the earliest transactions in 2009 when Bitcoin initially launched.\n
This initial synchronisation is very demanding, and may expose hardware problems with your computer that had previously gone unnoticed. Each time you run Bitcoin Core, it will continue downloading where it left off.$prune_explanation" "$ICON" &
This initial synchronisation is very demanding, and may expose hardware problems with your computer that had previously gone unnoticed. Each time you run Bitcoin Core, it will continue downloading where it left off.$prune_explanation"
fi
rm -rf "${intro_dir:-}"
zenity --info --title Welcome --icon-name=bitcoin128 --text="$welcome_text" "$ICON" &
# Update $PATH environment variable to include new user bin
# shellcheck source=/dev/null
. "$HOME"/.profile
Expand Down
72 changes: 72 additions & 0 deletions tests/core-welcome-text.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
welcome="$repo_root/bails/.local/bin/core-welcome-text"
fixtures="$repo_root/tests/fixtures/core-intro"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

fail() {
echo "$*" >&2
exit 1
}

expect_text() {
local expected=$1
shift
local actual
actual=$("$welcome" "$@") || fail "core-welcome-text failed for: $*"
[ "$actual" = "$expected" ] || fail "unexpected text for: $*
--- expected
$expected
--- actual
$actual"
}

expect_failure() {
local out
if out=$("$welcome" "$@"); then
fail "expected failure for: $*"
fi
[ -z "$out" ] || fail "expected no output on failure, got: $out"
}

begin='Bitcoin Core has begun to download and process the full Bitcoin block chain (897 GB) starting with the earliest transactions in 2009 when Bitcoin initially launched.'
demanding='This initial synchronisation is very demanding, and may expose hardware problems with your computer that had previously gone unnoticed. Each time you run Bitcoin Core, it will continue downloading where it left off.'

expect_text "<i>Welcome to Bitcoin Core.</i>

Bitcoin Core will download and store a copy of the Bitcoin block chain. Approximately 16 GB of data will be stored in your Persistent Storage.

$begin

$demanding

CipherStick has chosen to limit block chain storage (pruning) to 2 GB (sufficient to restore backups 6 days old), the historical data must still be downloaded and processed, but will be deleted afterward to keep your disk usage low." \
"$fixtures/intro.ui" "$fixtures/intro.cpp" 16 897 2 6

expect_text "<i>Welcome to Bitcoin Core.</i>

Bitcoin Core will download and store a copy of the Bitcoin block chain. At least 909 GB of data will be stored in your Persistent Storage, and it will grow over time.

$begin

$demanding" \
"$fixtures/intro.ui" "$fixtures/intro.cpp" 909 897 0 0

# A one-day backup window must not read "1 days".
"$welcome" "$fixtures/intro.ui" "$fixtures/intro.cpp" 15 897 1 1 |
grep -q '(sufficient to restore backups 1 day old)' || fail 'singular day not used'

# Reworded upstream strings must fall back instead of showing odd text.
sed 's/If you have chosen to limit/When you limit/' "$fixtures/intro.ui" >"$work/intro.ui"
expect_failure "$work/intro.ui" "$fixtures/intro.cpp" 16 897 2 6
sed 's/stored in this directory/stored here/' "$fixtures/intro.cpp" >"$work/intro.cpp"
expect_failure "$fixtures/intro.ui" "$work/intro.cpp" 909 897 0 0

# Missing source files and bad numbers also fall back.
expect_failure "$work/missing.ui" "$fixtures/intro.cpp" 16 897 2 6
expect_failure "$fixtures/intro.ui" "$fixtures/intro.cpp" 16 897 x 6

printf '%s\n' 'core-welcome-text: PASS'
5 changes: 5 additions & 0 deletions tests/fixtures/core-intro/intro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Excerpt of Bitcoin Core src/qt/intro.cpp (MIT License), the strings core-welcome-text reads.
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory.");
tr("(sufficient to restore backups %n day(s) old)", "", expected_backup_days));
tr("%1 will download and store a copy of the Bitcoin block chain.").arg(CLIENT_NAME) + " " +
5 changes: 5 additions & 0 deletions tests/fixtures/core-intro/intro.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Excerpt of Bitcoin Core src/qt/forms/intro.ui (MIT License), the strings core-welcome-text reads. -->
<string>Welcome to %1.</string>
<string>When you click OK, %1 will begin to download and process the full %4 block chain (%2 GB) starting with the earliest transactions in %3 when %4 initially launched.</string>
<string>This initial synchronisation is very demanding, and may expose hardware problems with your computer that had previously gone unnoticed. Each time you run %1, it will continue downloading where it left off.</string>
<string>If you have chosen to limit block chain storage (pruning), the historical data must still be downloaded and processed, but will be deleted afterward to keep your disk usage low.</string>
Loading