Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

117 sed prints an error in the terminal during install #119

Merged
Merged
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
34 changes: 17 additions & 17 deletions bin/install-core
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export DATA_DIR=$SOURCE/Persistent/.bitcoin
export DOTFILES=$SOURCE/dotfiles
export LOCAL_DIR=$DOTFILES/.local

readonly DOWNLOAD_DIR=$HOME/.local/share/bitcoin-core


link_dotfiles() {
( # runs in subshell to preserve current directory
cd $DOTFILES
Expand All @@ -54,7 +57,7 @@ check_sigs() {
good_sig=$(gpg --verify SHA256SUMS.asc SHA256SUMS 2>&1 | grep --count 'Good signature')
if (( good_sig < $1 )); then
type=warning
keys="$(grep fingerprint $destination_dir/show-keys | sed 's/ //g' | cut -f2 -d= | shuf)"
keys="$(grep fingerprint $DOWNLOAD_DIR/show-keys | sed 's/ //g' | cut -f2 -d= | shuf)"
for key in $keys; do
search_key
(( good_sig >= $1 )) && { type=info; break; }
Expand Down Expand Up @@ -106,30 +109,27 @@ pkill tca &>/dev/null
# enables job control so background downloads can be foregrounded to show progress while user waits
set -m

# Set the destination directory for the download
destination_dir=$HOME/.local/share/bitcoin-core

# Checks for existing Bitcoin Core versions
old_versions=$(ls -d $destination_dir/bitcoin-core-* | wc --lines)
old_versions=$(ls -d $DOWNLOAD_DIR/bitcoin-core-* | wc --lines)

# Installs Bails to tmpfs
rsync --recursive $BAILS_DIR/{bin,lib,share,state} $HOME/.local/

# Create the destination directory if it doesn't exist
mkdir -p "$destination_dir"
mkdir -p "$DOWNLOAD_DIR"

# TODO uncomment the downloads when done testing other things
# Download Bitcoin core checksums and signatures in background

( cd "$destination_dir"; #wget --tries=1 --no-host-directories --cut-dirs=1 --recursive --level=1 --accept=SHA256SUMS* --include-directories=bin http://6hasakffvppilxgehrswmffqurlcjjjhd76jgvaqmsg6ul25s7t3rzyd.onion/en/download/ ||
( cd "$DOWNLOAD_DIR"; #wget --tries=1 --no-host-directories --cut-dirs=1 --recursive --level=1 --accept=SHA256SUMS* --include-directories=bin http://6hasakffvppilxgehrswmffqurlcjjjhd76jgvaqmsg6ul25s7t3rzyd.onion/en/download/ ||
wget --no-host-directories --cut-dirs=1 --recursive --level=1 --accept=SHA256SUMS* --include-directories=bin https://bitcoincore.org/en/download/; ) & sig_dl=$!
# TODO FIXME uncomment the onion service when bitcoincore.org fixes their service.
# Download Bitcoin Core in background to the destination directory
( sleep 1; while pgrep wget &>/dev/null; do sleep 1; done; cd "$destination_dir"; #wget --continue --tries=1 --no-host-directories --cut-dirs=1 --recursive --level=1 --accept=x86_64-linux-gnu.tar.gz --include-directories=bin http://6hasakffvppilxgehrswmffqurlcjjjhd76jgvaqmsg6ul25s7t3rzyd.onion/en/download/ ||
( sleep 1; while pgrep wget &>/dev/null; do sleep 1; done; cd "$DOWNLOAD_DIR"; #wget --continue --tries=1 --no-host-directories --cut-dirs=1 --recursive --level=1 --accept=x86_64-linux-gnu.tar.gz --include-directories=bin http://6hasakffvppilxgehrswmffqurlcjjjhd76jgvaqmsg6ul25s7t3rzyd.onion/en/download/ ||
wget --continue --no-host-directories --cut-dirs=1 --recursive --level=1 --accept=x86_64-linux-gnu.tar.gz --include-directories=bin https://bitcoincore.org/en/download/; ) & core_download=$!

# Download chain parameters in background
( cd $destination_dir; wget -O chainparams.cpp https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/kernel/chainparams.cpp ) & get_size=$!
( cd $DOWNLOAD_DIR; wget -O chainparams.cpp https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/kernel/chainparams.cpp ) & get_size=$!

# clear the terminal
clear -x
Expand All @@ -145,14 +145,14 @@ printf '\033]2;Getting Bitcoin Core signatures...\a'
ps -p $sig_dl &>/dev/null && fg %$(jobs -l | grep $sig_dl | cut -f1 -d' ' | tr -c -d '[:digit:]')

# Switch into latest bitcoin-core directory
cd "$(ls -dt $destination_dir/bitcoin-core-* | head -1)" || {
cd "$(ls -dt "$DOWNLOAD_DIR"/bitcoin-core-* | head -1)" || {
zenity --warning --title="Download failure" --text="Click OK to try downloading Bitcoin Core again." --ellipsize $ICON &&
sleep 5
install-core # launch this script again
exit 1
}

versions=$(ls -d $destination_dir/bitcoin-core-* | wc --lines)
versions=$(ls -d $DOWNLOAD_DIR/bitcoin-core-* | wc --lines)

if (( old_versions != versions )) || [ ! -f $LOCAL_DIR/bin/bitcoind ]; then
if zenity --question --title='Verify Bitcoin Core download' --text='Download verification is optional but highly recommended. It requires around 5 to 10 minutes.\n\nPerforming the verification steps ensures that you have not downloaded an unexpected or tampered version of Bitcoin, which may result in loss of funds.' --cancel-label='Skip' --ok-label='Verify' --width=610 $ICON --icon-name=gtk-dialog-authentication; then
Expand All @@ -166,7 +166,7 @@ if (( old_versions != versions )) || [ ! -f $LOCAL_DIR/bin/bitcoind ]; then
fi
zenity --info --title="Trustworthy individuals" --text="Bitcoin releases are signed by a number of individuals, each with a unique public key. In order to recognize the validity of signatures, you will choose a few individuals who you find trustworthy. Their keys will be used to check the signature attesting to the validity of your download." --width=620 $ICON --icon-name=security-high & understood=$!
printf '\033]2;Getting Bitcoin Core builder keys...\a'
( cd $destination_dir
( cd $DOWNLOAD_DIR
[ -d "guix.sigs" ] || git clone https://github.com/bitcoin-core/guix.sigs --depth=1 && \
gpg --show-keys guix.sigs/builder-keys/*.gpg > show-keys )
(( versions > 1 )) && gpg --refresh-keys # refresh keys in keyring to see if any were revoked since last install
Expand All @@ -178,8 +178,8 @@ fi

# Bring chainparams.cpp download to foreground then set assumed chainstate & blockchain size
ps -p $get_size &>/dev/null && fg %$(jobs -l | grep $get_size | cut -f1 -d' ' | tr -c -d '[:digit:]')
assumed_chain_state_size=$(grep --max-count=1 m_assumed_chain_state_size $destination_dir/chainparams.cpp | sed 's/[^0-9]*//g')
assumed_blockchain_size=$(grep --max-count=1 m_assumed_blockchain_size $destination_dir/chainparams.cpp | sed 's/[^0-9]*//g')
assumed_chain_state_size=$(grep --max-count=1 m_assumed_chain_state_size $DOWNLOAD_DIR/chainparams.cpp | sed 's/[^0-9]*//g')
assumed_blockchain_size=$(grep --max-count=1 m_assumed_blockchain_size $DOWNLOAD_DIR/chainparams.cpp | sed 's/[^0-9]*//g')

# Display information about pruning and initial block download while user waits for download
space=$(($(df --output=size $SOURCE | tail -1)/1024 - ( assumed_chain_state_size+10 )*1024))
Expand All @@ -192,7 +192,7 @@ printf '\033]2;Downloading Bitcoin Core...\a'
ps -p $core_download &>/dev/null && fg %$(jobs -l | grep $core_download | cut -f1 -d' ' | tr -c -d '[:digit:]')

# Move completed download to persistent storage
rsync --remove-source-files --recursive $destination_dir $LOCAL_DIR/share/
rsync --remove-source-files --recursive $DOWNLOAD_DIR $LOCAL_DIR/share/
link_dotfiles

# Verify download integrity # TODO make sure they can actually retry the download by re-running the script, that everything gets skipped that needs to be skipped.
Expand Down Expand Up @@ -245,8 +245,8 @@ rsync --remove-source-files -recursive "$BAILS_DIR"/config/ $DOTFILES/.config
}' > $DATA_DIR/settings.json

# Cleanup
rm -Rf ${BAILS_DIR:?}/{bin,lib,share,state,config} "$destination_dir"/{download,*.tmp,wget-log*}
rsync -r --remove-source-files $BAILS_DIR $LOCAL_DIR/share/
rm -Rf ${BAILS_DIR:?}/{bin,lib,share,state,config} "$DOWNLOAD_DIR"/{download,*.tmp,wget-log*}
rsync -r --remove-source-files $BAILS_DIR/ $LOCAL_DIR/share/bails
rm -rf $BAILS_DIR
link_dotfiles

Expand Down