raspiblitz/home.admin/config.scripts/lnd.update.sh

257 lines
9.1 KiB
Bash
Raw Normal View History

2020-04-25 21:47:54 +02:00
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
2020-04-25 21:56:57 +02:00
echo "Interim optional LND updates between RaspiBlitz releases."
2020-04-28 20:55:09 +02:00
echo "lnd.update.sh [info|verified|reckless]"
2020-04-25 21:47:54 +02:00
echo "info -> get actual state and possible actions"
2020-04-28 20:55:09 +02:00
echo "verified -> only do recommended updates by RaspiBlitz team"
2020-04-25 21:47:54 +02:00
echo " binary will be checked by signature and checksum"
echo "reckless -> if you just want to update to the latest release"
echo " published on LND GitHub releases (RC or final) without any"
echo " testing or security checks."
exit 1
fi
2020-04-28 20:55:09 +02:00
# 1. parameter [info|verified|reckless]
2020-04-25 21:47:54 +02:00
mode="$1"
# RECOMMENDED UPDATE BY RASPIBLITZ TEAM
# comment will be shown as "BEWARE Info" when option is choosen (can be multiple lines)
2021-08-26 20:24:31 +02:00
lndUpdateVersion="" # example: 0.13.2-beta .. just keep entry if no newer version as sd card build is available
lndUpdateComment="Please keep in mind that downgrading afterwards is not tested. Also not all additional apps are fully tested with the this update - but it looked good on first tests."
2020-04-25 21:47:54 +02:00
2020-04-26 00:00:55 +02:00
# check who signed the release in https://github.com/lightningnetwork/lnd/releases
# olaoluwa
2021-08-26 14:51:38 +02:00
PGPauthor="roasbeef"
lndUpdatePGPpkeys="https://keybase.io/roasbeef/pgp_keys.asc"
lndUpdatePGPcheck="4AB7F8DA6FAEBB3B70B1F903BC13F65E2DC84465"
2020-04-26 00:00:55 +02:00
#joostjager
# PGPauthor="joostjager"
2020-04-26 00:00:55 +02:00
# lndUpdatePGPpkeys="https://keybase.io/joostjager/pgp_keys.asc"
# lndUpdatePGPcheck="D146D0F68939436268FA9A130E26BB61B76C4D3A"
# bitconner
2021-08-26 14:51:38 +02:00
# PGPauthor="bitconner"
# lndUpdatePGPpkeys="https://keybase.io/bitconner/pgp_keys.asc"
# lndUpdatePGPcheck="9C8D61868A7C492003B2744EE7D737B67FA592C7"
2020-04-26 00:00:55 +02:00
# wpaulino
# PGPauthor="wpaulino"
2020-04-26 00:00:55 +02:00
# lndUpdatePGPpkeys="https://keybase.io/wpaulino/pgp_keys.asc"
# lndUpdatePGPcheck="729E9D9D92C75A5FBFEEE057B5DD717BEF7CA5B1"
2020-04-25 21:47:54 +02:00
# GATHER DATA
2020-04-26 00:00:55 +02:00
# setting download directory
downloadDir="/home/admin/download"
2020-04-25 21:47:54 +02:00
# detect CPU architecture & fitting download link
cpuArchitecture=""
if [ $(uname -m | grep -c 'arm') -eq 1 ] ; then
cpuArchitecture="armv7"
fi
if [ $(uname -m | grep -c 'aarch64') -eq 1 ] ; then
cpuArchitecture="arm64"
fi
if [ $(uname -m | grep -c 'x86_64') -eq 1 ] ; then
cpuArchitecture="amd64"
fi
if [ $(uname -m | grep -c 'i386\|i486\|i586\|i686\|i786') -eq 1 ] ; then
cpuArchitecture="386"
fi
# installed LND version
2020-04-26 01:34:51 +02:00
lndInstalledVersion=$(sudo -u bitcoin lncli --version | cut -d " " -f3)
2020-04-25 21:47:54 +02:00
lndInstalledVersionMajor=$(echo "${lndInstalledVersion}" | cut -d "-" -f1 | cut -d "." -f1)
lndInstalledVersionMain=$(echo "${lndInstalledVersion}" | cut -d "-" -f1 | cut -d "." -f2)
lndInstalledVersionMinor=$(echo "${lndInstalledVersion}" | cut -d "-" -f1 | cut -d "." -f3)
2020-04-28 20:55:09 +02:00
# test if the installed version already the verified/recommended update version
2020-05-03 01:12:21 +02:00
lndUpdateInstalled=$(echo "${lndInstalledVersion}" | grep -c "${lndUpdateVersion}")
2020-04-25 21:47:54 +02:00
# get latest release from LND GitHub releases
gitHubLatestReleaseJSON="$(curl -s https://api.github.com/repos/lightningnetwork/lnd/releases | jq '.[0]')"
2020-04-25 21:47:54 +02:00
lndLatestVersion=$(echo "${gitHubLatestReleaseJSON}" | jq -r '.tag_name')
lndLatestDownload=$(echo "${gitHubLatestReleaseJSON}" | grep "browser_download_url" | grep "linux-${cpuArchitecture}" | cut -d '"' -f4)
# INFO
if [ "${mode}" = "info" ]; then
echo "# basic data"
echo "cpuArchitecture='${cpuArchitecture}'"
echo "lndInstalledVersion='${lndInstalledVersion}'"
echo "lndInstalledVersionMajor='${lndInstalledVersionMajor}'"
echo "lndInstalledVersionMain='${lndInstalledVersionMain}'"
echo "lndInstalledVersionMinor='${lndInstalledVersionMinor}'"
2020-04-28 20:55:09 +02:00
echo "# the verified/recommended update option"
2020-04-25 21:47:54 +02:00
echo "lndUpdateInstalled='${lndUpdateInstalled}'"
echo "lndUpdateVersion='${lndUpdateVersion}'"
echo "lndUpdateComment='${lndUpdateComment}'"
echo "# reckless update option (latest LND release from GitHub)"
echo "lndLatestVersion='${lndLatestVersion}'"
echo "lndLatestDownload='${lndLatestDownload}'"
2020-04-26 01:03:14 +02:00
exit 1
fi
2020-04-25 21:47:54 +02:00
2020-04-28 20:55:09 +02:00
# verified
if [ "${mode}" = "verified" ]; then
2020-04-25 21:47:54 +02:00
2020-04-28 20:55:09 +02:00
echo "# lnd.update.sh verified"
2020-04-25 21:47:54 +02:00
# check for optional second parameter: forced update version
2020-04-28 20:55:09 +02:00
# --> only does the verified update if its the given version
2020-04-25 21:47:54 +02:00
# this is needed for recovery/update.
fixedUpdateVersion="$2"
if [ ${#fixedUpdateVersion} -gt 0 ]; then
2020-04-25 21:56:57 +02:00
echo "# checking for fixed version update: askedFor(${fixedUpdateVersion}) available(${lndUpdateVersion})"
if [ "${fixedUpdateVersion}" != "${lndUpdateVersion}" ]; then
echo "warn='required update version does not match'"
echo "# this is normal when the recovery script of a new RaspiBlitz version checks for an old update - just ignore"
exit 1
else
echo "# OK - update version is matching"
fi
2020-04-25 21:47:54 +02:00
fi
2020-05-01 19:38:52 +02:00
echo
echo "# clean & change into download directory"
2020-04-26 01:22:57 +02:00
sudo rm -r ${downloadDir}/*
2020-04-26 00:00:55 +02:00
cd "${downloadDir}"
2020-05-01 19:38:52 +02:00
echo
echo "# extract the SHA256 hash from the manifest file for the corresponding platform"
2020-04-26 00:00:55 +02:00
sudo -u admin wget -N https://github.com/lightningnetwork/lnd/releases/download/v${lndUpdateVersion}/manifest-v${lndUpdateVersion}.txt
2020-04-26 00:37:52 +02:00
checkDownload=$(ls manifest-v${lndUpdateVersion}.txt 2>/dev/null | grep -c manifest-v${lndUpdateVersion}.txt)
if [ ${checkDownload} -eq 0 ]; then
echo "error='download manifest failed'"
exit 1
fi
2020-04-26 00:00:55 +02:00
lndSHA256=$(grep -i "linux-${cpuArchitecture}" manifest-v$lndUpdateVersion.txt | cut -d " " -f1)
echo "# SHA256 hash: $lndSHA256"
2020-05-01 19:38:52 +02:00
echo
echo "# get LND binary"
2020-04-26 00:00:55 +02:00
binaryName="lnd-linux-${cpuArchitecture}-v${lndUpdateVersion}.tar.gz"
sudo -u admin wget -N https://github.com/lightningnetwork/lnd/releases/download/v${lndUpdateVersion}/${binaryName}
2020-04-26 00:37:52 +02:00
checkDownload=$(ls ${binaryName} 2>/dev/null | grep -c ${binaryName})
if [ ${checkDownload} -eq 0 ]; then
echo "error='download binary failed'"
exit 1
fi
2020-04-26 00:00:55 +02:00
2020-05-01 19:38:52 +02:00
echo
echo "# check binary was not manipulated (checksum test)"
sudo -u admin wget -N https://github.com/lightningnetwork/lnd/releases/download/v${lndUpdateVersion}/manifest-${PGPauthor}-v${lndUpdateVersion}.sig
2020-06-01 22:03:07 +02:00
sudo -u admin wget --no-check-certificate -N -O "${downloadDir}/pgp_keys.asc" ${lndUpdatePGPpkeys}
2020-04-26 00:00:55 +02:00
binaryChecksum=$(sha256sum ${binaryName} | cut -d " " -f1)
echo "# binary chdecksum: ${binaryChecksum}"
echo "# lndSHA256: ${lndSHA256}"
validSignature=$(echo "${lndSHA256}" | grep -c "${binaryChecksum}")
if [ ${validSignature} -eq 0 ]; then
2020-04-26 00:00:55 +02:00
echo "error='checksum not matching'"
exit 1
fi
2020-05-01 19:38:52 +02:00
echo
echo "# getting gpg finger print"
2020-04-26 00:00:55 +02:00
gpg ./pgp_keys.asc
fingerprint=$(sudo gpg "${downloadDir}/pgp_keys.asc" 2>/dev/null | grep "${lndUpdatePGPcheck}" -c)
if [ ${fingerprint} -lt 1 ]; then
echo "error='PGP author check failed'"
2020-05-01 19:38:52 +02:00
exit 1
2020-04-26 00:00:55 +02:00
fi
2020-05-01 19:38:52 +02:00
echo "fingerprint='${fingerprint}'"
echo
echo "# checking gpg finger print"
2020-04-26 00:00:55 +02:00
gpg --import ./pgp_keys.asc
sleep 3
verifyResult=$(gpg --verify manifest-${PGPauthor}-v${lndUpdateVersion}.sig manifest-v${lndUpdateVersion}.txt 2>&1)
2020-04-26 00:00:55 +02:00
goodSignature=$(echo ${verifyResult} | grep 'Good signature' -c)
2020-05-01 19:38:52 +02:00
echo "goodSignature='${goodSignature}'"
2020-04-26 00:00:55 +02:00
correctKey=$(echo ${verifyResult} | tr -d " \t\n\r" | grep "${lndUpdatePGPcheck}" -c)
2020-05-01 19:38:52 +02:00
echo "correctKey='${correctKey}'"
2020-04-26 00:00:55 +02:00
if [ ${correctKey} -lt 1 ] || [ ${goodSignature} -lt 1 ]; then
echo "error='PGP verify fail'"
exit 1
fi
2020-04-26 01:19:25 +02:00
2020-04-26 01:03:14 +02:00
# note: install will be done the same as reckless further down
2020-05-01 19:16:49 +02:00
lndInterimsUpdateNew="${lndUpdateVersion}"
2020-04-26 01:19:25 +02:00
2020-04-26 01:03:14 +02:00
fi
# 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
if [ "${mode}" = "reckless" ]; then
echo "# lnd.update.sh reckless"
# check that download link has a value
if [ ${#lndLatestDownload} -eq 0 ]; then
echo "error='no download link'"
exit 1
fi
2020-04-26 01:22:57 +02:00
# clean & change into download directory
sudo rm -r ${downloadDir}/*
2020-04-26 01:03:14 +02:00
cd "${downloadDir}"
# download binary
echo "# downloading binary"
binaryName=$(basename "${lndLatestDownload}")
sudo -u admin wget -N ${lndLatestDownload}
checkDownload=$(ls ${binaryName} 2>/dev/null | grep -c ${binaryName})
if [ ${checkDownload} -eq 0 ]; then
echo "error='download binary failed'"
exit 1
fi
# prepare install
2020-04-26 01:19:25 +02:00
lndInterimsUpdateNew="reckless"
2020-04-26 01:03:14 +02:00
fi
2020-04-28 20:55:09 +02:00
# JOINED INSTALL (verified & RECKLESS)
if [ "${mode}" = "verified" ] || [ "${mode}" = "reckless" ]; then
2020-04-26 00:00:55 +02:00
# install
echo "# stopping LND"
sudo systemctl stop lnd
2020-04-26 01:19:25 +02:00
echo "# unzip LND binary"
2020-04-26 00:00:55 +02:00
sudo -u admin tar -xzf ${binaryName}
2020-04-26 01:19:25 +02:00
# removing the tar.gz ending from the binary
directoryName="${binaryName%.*.*}"
echo "# install binary directory '${directoryName}'"
2020-04-26 01:23:48 +02:00
sudo install -m 0755 -o root -g root -t /usr/local/bin ${directoryName}/*
2020-04-26 00:00:55 +02:00
sleep 3
installed=$(sudo -u admin lnd --version)
if [ ${#installed} -eq 0 ]; then
echo "error='install failed'"
exit 1
fi
echo "# flag update in raspiblitz config"
source /mnt/hdd/raspiblitz.conf
if [ ${#lndInterimsUpdate} -eq 0 ]; then
2020-04-26 01:19:25 +02:00
echo "lndInterimsUpdate='${lndInterimsUpdateNew}'" >> /mnt/hdd/raspiblitz.conf
2020-04-26 00:00:55 +02:00
else
2020-04-26 01:19:25 +02:00
sudo sed -i "s/^lndInterimsUpdate=.*/lndInterimsUpdate='${lndInterimsUpdateNew}'/g" /mnt/hdd/raspiblitz.conf
2020-04-26 00:00:55 +02:00
fi
echo "# OK LND Installed"
2020-04-26 01:34:51 +02:00
echo "# NOTE: RaspiBlitz may need to reboot now"
2020-04-26 00:00:55 +02:00
exit 1
2020-04-25 21:47:54 +02:00
else
2020-04-26 01:03:14 +02:00
2020-04-25 21:47:54 +02:00
echo "error='parameter not known'"
2020-04-26 01:03:14 +02:00
exit 1
2020-04-25 21:47:54 +02:00
fi