2019-12-04 08:13:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# command info
|
|
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
2021-04-23 23:19:26 +01:00
|
|
|
echo "Interim optional Bitcoin Core updates between RaspiBlitz releases."
|
|
|
|
echo "bitcoin.update.sh [info|tested|reckless|custom]"
|
|
|
|
echo "info -> get actual state and possible actions"
|
|
|
|
echo "tested -> only do a tested update by the RaspiBlitz team"
|
|
|
|
echo "reckless -> the update was not tested by the RaspiBlitz team"
|
2023-12-14 18:40:05 +01:00
|
|
|
echo "custom <version> <skipverify> -> update to a chosen version"
|
|
|
|
echo " the binary checksum and signatures will be checked in all cases"
|
|
|
|
echo " except when 'skipverify' is used"
|
2021-04-23 23:19:26 +01:00
|
|
|
echo
|
|
|
|
exit 1
|
2021-04-19 15:46:44 +01:00
|
|
|
fi
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2023-12-14 18:40:05 +01:00
|
|
|
echo "# Running: bitcoin.update.sh $*"
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# 1. parameter [info|tested|reckless]
|
|
|
|
mode="$1"
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2024-07-29 20:16:24 +02:00
|
|
|
# RECOMMENDED UPDATE BY RASPIBLITZ TEAM (latest tested version available)
|
|
|
|
bitcoinVersion="27.1" # example: 22.0 .. keep empty if no newer version as sd card build is available
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# GATHER DATA
|
2021-09-17 01:14:47 +01:00
|
|
|
# setting download directory to the current user
|
|
|
|
downloadDir="/home/$(whoami)/download/bitcoin.update"
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2023-12-14 18:40:05 +01:00
|
|
|
# bitcoinOSversion
|
|
|
|
if [ "$(uname -m | grep -c 'arm')" -gt 0 ]; then
|
2019-12-04 08:13:21 +00:00
|
|
|
bitcoinOSversion="arm-linux-gnueabihf"
|
2023-12-14 18:40:05 +01:00
|
|
|
elif [ "$(uname -m | grep -c 'aarch64')" -gt 0 ]; then
|
2019-12-04 08:13:21 +00:00
|
|
|
bitcoinOSversion="aarch64-linux-gnu"
|
2023-12-14 18:40:05 +01:00
|
|
|
elif [ "$(uname -m | grep -c 'x86_64')" -gt 0 ]; then
|
2019-12-04 08:13:21 +00:00
|
|
|
bitcoinOSversion="x86_64-linux-gnu"
|
|
|
|
fi
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# installed version
|
2023-05-03 16:32:23 +01:00
|
|
|
installedVersion=$(sudo -u bitcoin bitcoind --version | head -n1 | cut -d" " -f4 | cut -c 2-)
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# test if the installed version already the tested/recommended update version
|
|
|
|
bitcoinUpdateInstalled=$(echo "${installedVersion}" | grep -c "${bitcoinVersion}")
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# get latest release from GitHub releases
|
2023-05-03 16:32:23 +01:00
|
|
|
bitcoinLatestVersion=$(curl --header "X-GitHub-Api-Version:2022-11-28" -s https://api.github.com/repos/bitcoin/bitcoin/releases | jq -r '.[].tag_name' | sort | tail -n1 | cut -c 2-)
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# INFO
|
|
|
|
function displayInfo() {
|
|
|
|
echo "# basic data"
|
|
|
|
echo "installedVersion='${installedVersion}'"
|
|
|
|
echo "bitcoinOSversion='${bitcoinOSversion}'"
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
echo "# the tested/recommended update option"
|
|
|
|
echo "bitcoinUpdateInstalled='${bitcoinUpdateInstalled}'"
|
|
|
|
echo "bitcoinVersion='${bitcoinVersion}'"
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
echo "# reckless update option (latest Bitcoin Core release from GitHub)"
|
|
|
|
echo "bitcoinLatestVersion='${bitcoinLatestVersion}'"
|
|
|
|
}
|
|
|
|
|
2024-07-29 20:16:24 +02:00
|
|
|
# COMAPRE TWO VERSION STRINGS
|
|
|
|
# 0 = first version string is equal
|
|
|
|
# 1 = first version string is older
|
|
|
|
# 2 = first version string is newer
|
|
|
|
function version_compare() {
|
|
|
|
if [[ $1 == $2 ]]
|
|
|
|
then
|
|
|
|
echo "equal"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
IFS='.' read -r -a ver1 <<< "$1"
|
|
|
|
IFS='.' read -r -a ver2 <<< "$2"
|
|
|
|
len1=${#ver1[@]}
|
|
|
|
len2=${#ver2[@]}
|
|
|
|
max_len=$((len1>len2?len1:len2))
|
|
|
|
for ((i=0; i<max_len; i++))
|
|
|
|
do
|
|
|
|
part1=${ver1[i]:-0}
|
|
|
|
part2=${ver2[i]:-0}
|
|
|
|
if ((part1 < part2))
|
|
|
|
then
|
|
|
|
# older
|
|
|
|
return 1
|
|
|
|
elif ((part1 > part2))
|
|
|
|
then
|
|
|
|
# newer
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# equal
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
if [ "${mode}" = "info" ]; then
|
|
|
|
displayInfo
|
2019-12-04 08:13:21 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# tested
|
|
|
|
if [ "${mode}" = "tested" ]; then
|
|
|
|
|
|
|
|
echo "# bitcoin.update.sh tested"
|
|
|
|
|
2024-07-29 20:16:24 +02:00
|
|
|
# check if a tested update is available
|
|
|
|
if [ ${#bitcoinVersion} -eq 0 ]; then
|
|
|
|
echo "# warn='no tested update available'"
|
|
|
|
echo "# thats OK on update from older versions"
|
|
|
|
/home/admin/config.scripts/blitz.conf.sh delete bitcoinInterimsUpdate 2>/dev/null
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
# check for optional second parameter: forced update version
|
|
|
|
fixedBitcoinVersion="$2"
|
|
|
|
if [ ${#fixedBitcoinVersion} -gt 0 ]; then
|
2024-07-29 20:16:24 +02:00
|
|
|
echo "# checking for fixed version update: installed(${installedVersion}) requested(${fixedBitcoinVersion}) available(${bitcoinVersion})"
|
|
|
|
version_compare "${fixedBitcoinVersion}" "${bitcoinVersion}"
|
|
|
|
result=$?
|
|
|
|
if [ "${result}" -eq 2 ]; then
|
|
|
|
echo "# WARNING: requested version is newer then available tested --> ABORT (already up2date)"
|
2021-04-19 15:46:44 +01:00
|
|
|
exit 1
|
|
|
|
else
|
2024-07-29 20:16:24 +02:00
|
|
|
echo "# requested version is older or equal --> OK install available tested version"
|
2021-04-19 15:46:44 +01:00
|
|
|
fi
|
|
|
|
fi
|
2024-07-29 20:16:24 +02:00
|
|
|
|
|
|
|
# check against installed version
|
|
|
|
version_compare "${installedVersion}" "${bitcoinVersion}"
|
|
|
|
result=$?
|
|
|
|
if [ "${result}" -eq 2 ]; then
|
|
|
|
# this can happen if bitcoin install script already has a higher version then the tested version set by this script (see above)
|
|
|
|
echo "# installed version is newer then to be updated version --> ABORT"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ "${result}" -eq 0 ]; then
|
|
|
|
echo "# version is already installed --> ABORT"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-19 23:14:46 +01:00
|
|
|
pathVersion=${bitcoinVersion}
|
2021-04-19 15:46:44 +01:00
|
|
|
|
|
|
|
elif [ "${mode}" = "reckless" ]; then
|
|
|
|
# RECKLESS
|
|
|
|
# this mode is just for people running test and development nodes - its not recommended
|
|
|
|
# for production nodes. In a update/recovery scenario it will not install a fixed version
|
|
|
|
# it will always pick the latest release from the github
|
|
|
|
echo "# bitcoin.update.sh reckless"
|
|
|
|
bitcoinVersion=${bitcoinLatestVersion}
|
2021-04-19 23:14:46 +01:00
|
|
|
pathVersion=${bitcoinVersion}
|
2021-04-19 15:46:44 +01:00
|
|
|
|
|
|
|
elif [ "${mode}" = "custom" ]; then
|
2023-12-14 18:40:05 +01:00
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
bitcoinVersion="$2"
|
|
|
|
else
|
|
|
|
clear
|
|
|
|
echo
|
|
|
|
echo "# Update Bitcoin Core to a chosen version."
|
|
|
|
echo
|
|
|
|
echo "# Input the version you would like to install and press ENTER."
|
|
|
|
echo "# Examples (versions below 22.1 are not supported):"
|
|
|
|
echo "24.0.1"
|
|
|
|
echo "26.0"
|
|
|
|
echo
|
|
|
|
read bitcoinVersion
|
|
|
|
fi
|
|
|
|
|
2023-05-03 16:32:23 +01:00
|
|
|
if [ $(echo ${bitcoinVersion} | grep -c "rc") -gt 0 ]; then
|
2021-04-19 23:14:46 +01:00
|
|
|
cutVersion=$(echo ${bitcoinVersion} | awk -F"r" '{print $1}')
|
|
|
|
rcVersion=$(echo ${bitcoinVersion} | awk -F"r" '{print $2}')
|
2021-09-17 01:14:47 +01:00
|
|
|
# https://bitcoincore.org/bin/bitcoin-core-22.0/test.rc3/
|
2021-04-19 23:14:46 +01:00
|
|
|
pathVersion=${cutVersion}/test.r${rcVersion}
|
|
|
|
else
|
|
|
|
pathVersion=${bitcoinVersion}
|
|
|
|
fi
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
if curl --output /dev/null --silent --head --fail \
|
2023-05-03 16:32:23 +01:00
|
|
|
https://bitcoincore.org/bin/bitcoin-core-${pathVersion}/SHA256SUMS.asc; then
|
2021-04-19 23:14:46 +01:00
|
|
|
echo "# OK version exists at https://bitcoincore.org/bin/bitcoin-core-${pathVersion}"
|
2023-12-14 18:40:05 +01:00
|
|
|
if [ "${mode}" = "custom" ] && [ "$3" = "skipverify" ]; then
|
|
|
|
echo "# skipping signature verification"
|
|
|
|
fi
|
2021-04-19 23:14:46 +01:00
|
|
|
echo "# Press ENTER to proceed to install Bitcoin Core $bitcoinVersion or CTRL+C to abort."
|
2021-04-19 15:46:44 +01:00
|
|
|
read key
|
2023-05-03 16:32:23 +01:00
|
|
|
else
|
2021-04-19 15:46:44 +01:00
|
|
|
echo "# FAIL $bitcoinVersion does not exist"
|
|
|
|
echo
|
|
|
|
echo "# Press ENTER to return to the main menu"
|
|
|
|
read key
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# JOINED INSTALL
|
2023-05-03 16:32:23 +01:00
|
|
|
if [ "${mode}" = "tested" ] || [ "${mode}" = "reckless" ] || [ "${mode}" = "custom" ]; then
|
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
displayInfo
|
|
|
|
|
2022-11-09 16:43:36 -03:00
|
|
|
if [ "$installedVersion" = "$bitcoinVersion" ]; then
|
2021-04-19 15:46:44 +01:00
|
|
|
echo "# installedVersion = bitcoinVersion"
|
|
|
|
echo "# exiting script"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-05-03 16:32:23 +01:00
|
|
|
echo
|
2021-04-19 15:46:44 +01:00
|
|
|
echo "# clean & change into download directory"
|
2021-09-17 01:14:47 +01:00
|
|
|
sudo rm -rf "${downloadDir}"
|
|
|
|
mkdir -p "${downloadDir}"
|
2021-04-19 15:46:44 +01:00
|
|
|
cd "${downloadDir}" || exit 1
|
|
|
|
|
2023-12-14 18:40:05 +01:00
|
|
|
echo "# Receive signer keys"
|
|
|
|
curl -s "https://api.github.com/repos/bitcoin-core/guix.sigs/contents/builder-keys" |
|
|
|
|
jq -r '.[].download_url' | while read url; do curl -s "$url" | gpg --import; done
|
2023-05-03 16:32:23 +01:00
|
|
|
|
2023-12-14 18:40:05 +01:00
|
|
|
# download signed binary sha256 hash sum file
|
|
|
|
wget --prefer-family=ipv4 --progress=bar:force -O SHA256SUMS https://bitcoincore.org/bin/bitcoin-core-${bitcoinVersion}/SHA256SUMS
|
|
|
|
# download the signed binary sha256 hash sum file and check
|
|
|
|
wget --prefer-family=ipv4 --progress=bar:force -O SHA256SUMS.asc https://bitcoincore.org/bin/bitcoin-core-${bitcoinVersion}/SHA256SUMS.asc
|
|
|
|
|
|
|
|
if [ "${mode}" = "custom" ] && [ "$3" = "skipverify" ]; then
|
|
|
|
echo "# skipping signature verification"
|
|
|
|
echo "# display the output of 'gpg --verify SHA256SUMS.asc'"
|
|
|
|
gpg --verify SHA256SUMS.asc
|
2021-04-19 15:46:44 +01:00
|
|
|
else
|
2023-12-14 18:40:05 +01:00
|
|
|
if gpg --verify SHA256SUMS.asc; then
|
|
|
|
echo
|
|
|
|
echo "****************************************"
|
|
|
|
echo "OK --> BITCOIN MANIFEST IS CORRECT"
|
|
|
|
echo "****************************************"
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "# BUILD FAILED --> the PGP verification failed"
|
|
|
|
echo "# try again or with a different version"
|
|
|
|
echo "# if you want to skip verifying all signatures (and just show them) use the command:"
|
|
|
|
echo "# /home/admin/config.scripts/bonus.bitcoin.sh custom ${bitcoinVersion:-<version>} skipverify"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-04-19 15:46:44 +01:00
|
|
|
fi
|
|
|
|
|
2021-04-23 23:19:26 +01:00
|
|
|
echo "# Downloading Bitcoin Core v${bitcoinVersion} for ${bitcoinOSversion} ..."
|
2021-04-19 15:46:44 +01:00
|
|
|
binaryName="bitcoin-${bitcoinVersion}-${bitcoinOSversion}.tar.gz"
|
2021-09-17 01:14:47 +01:00
|
|
|
wget https://bitcoincore.org/bin/bitcoin-core-${pathVersion}/${binaryName}
|
2023-05-03 16:32:23 +01:00
|
|
|
if [ ! -f "./${binaryName}" ]; then
|
2022-07-18 21:07:14 +01:00
|
|
|
echo "# FAIL # Downloading BITCOIN BINARY did not succeed."
|
2021-04-19 23:14:46 +01:00
|
|
|
exit 1
|
2021-04-19 15:46:44 +01:00
|
|
|
fi
|
|
|
|
|
2023-05-03 16:32:23 +01:00
|
|
|
echo "# Checking the binary checksum ..."
|
2023-12-14 18:40:05 +01:00
|
|
|
if ! sha256sum -c --ignore-missing SHA256SUMS; then
|
2021-04-23 23:19:26 +01:00
|
|
|
# get the sha256 value for the corresponding platform from signed hash sum file
|
2023-12-14 18:40:05 +01:00
|
|
|
bitcoinSHA256=$(grep -i "${binaryName}}" SHA256SUMS | cut -d " " -f1)
|
2022-07-18 21:07:14 +01:00
|
|
|
echo "# FAIL # Downloaded BITCOIN BINARY CHECKSUM:"
|
2021-04-23 23:19:26 +01:00
|
|
|
echo "$(sha256sum ${binaryName})"
|
|
|
|
echo "NOT matching SHA256 checksum:"
|
|
|
|
echo "${bitcoinSHA256}"
|
2021-04-19 15:46:44 +01:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo
|
2021-09-17 01:14:47 +01:00
|
|
|
echo "# OK --> VERIFIED BITCOIN CORE BINARY CHECKSUM IS CORRECT"
|
2021-04-19 15:46:44 +01:00
|
|
|
echo
|
|
|
|
fi
|
2023-05-03 16:32:23 +01:00
|
|
|
fi
|
2021-04-19 15:46:44 +01:00
|
|
|
|
2023-05-03 16:32:23 +01:00
|
|
|
if [ "${mode}" = "tested" ] || [ "${mode}" = "custom" ]; then
|
2021-04-19 15:46:44 +01:00
|
|
|
bitcoinInterimsUpdateNew="${bitcoinVersion}"
|
|
|
|
elif [ "${mode}" = "reckless" ]; then
|
|
|
|
bitcoinInterimsUpdateNew="reckless"
|
|
|
|
fi
|
|
|
|
|
2021-04-23 23:19:26 +01:00
|
|
|
# JOINED INSTALL
|
2023-05-03 16:32:23 +01:00
|
|
|
if [ "${mode}" = "tested" ] || [ "${mode}" = "reckless" ] || [ "${mode}" = "custom" ]; then
|
2021-04-19 15:46:44 +01:00
|
|
|
|
|
|
|
# install
|
2021-12-14 23:34:35 +01:00
|
|
|
echo "# Stopping bitcoind ..."
|
|
|
|
sudo systemctl stop bitcoind 2>/dev/null
|
|
|
|
sudo systemctl stop tbitcoind 2>/dev/null
|
|
|
|
sudo systemctl stop sbitcoind 2>/dev/null
|
2021-04-19 15:46:44 +01:00
|
|
|
echo
|
|
|
|
echo "# Installing Bitcoin Core v${bitcoinVersion}"
|
2021-09-17 01:14:47 +01:00
|
|
|
tar -xvf ${binaryName}
|
2021-04-19 15:46:44 +01:00
|
|
|
sudo install -m 0755 -o root -g root -t /usr/local/bin/ bitcoin-${bitcoinVersion}/bin/*
|
|
|
|
sleep 3
|
2023-12-14 18:40:05 +01:00
|
|
|
if ! sudo /usr/local/bin/bitcoind --version | grep "${bitcoinVersion}"; then
|
2021-04-19 15:46:44 +01:00
|
|
|
echo
|
2022-07-18 21:07:14 +01:00
|
|
|
echo "# BUILD FAILED --> Was not able to install bitcoind version(${bitcoinVersion})"
|
2021-04-19 15:46:44 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-12-14 23:34:35 +01:00
|
|
|
|
|
|
|
echo "# mark update in raspiblitz config"
|
|
|
|
/home/admin/config.scripts/blitz.conf.sh set bitcoinInterimsUpdate "${bitcoinInterimsUpdateNew}"
|
2021-04-19 15:46:44 +01:00
|
|
|
|
2021-04-19 23:14:46 +01:00
|
|
|
echo "# OK Bitcoin Core ${bitcoinVersion} is installed"
|
|
|
|
exit 0
|
2019-12-04 08:13:21 +00:00
|
|
|
|
2021-04-19 15:46:44 +01:00
|
|
|
else
|
|
|
|
echo "# error='parameter not known'"
|
|
|
|
exit 1
|
|
|
|
fi
|