2021-09-27 23:34:49 +01:00
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ " $1 " = "-h" ] || [ " $1 " = "-help" ] ; then
2021-10-12 01:09:46 +01:00
echo
2022-07-27 08:37:36 +02:00
echo "Interim optional Core Lightning updates between RaspiBlitz releases."
2021-10-12 01:09:46 +01:00
echo "cl.update.sh [info|verified|reckless]"
echo "info -> get actual state and possible actions"
echo "verified -> only do recommended updates by RaspiBlitz team"
echo " binary will be checked by signature and checksum"
echo "reckless -> if you just want to update to the latest release"
2023-05-16 12:12:36 +01:00
echo " published on Core Lightning GitHub releases without any"
2021-10-12 01:09:46 +01:00
echo " testing or security checks."
echo
exit 1
2021-09-27 23:34:49 +01:00
fi
# 1. parameter [info|verified|reckless]
mode = " $1 "
# RECOMMENDED UPDATE BY RASPIBLITZ TEAM
2023-05-08 19:30:39 +01:00
# comment will be shown as "BEWARE Info" when option is choosen (can be multiple lines)
2023-12-04 22:07:05 +01:00
clUpdateVersion = "" # example: v23.02.2 # keep empty if no newer version as sd card build is available
2021-09-27 23:34:49 +01:00
clUpdateComment = "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."
# GATHER DATA
2022-07-27 08:37:36 +02:00
# installed Core Lightning version
2023-05-16 12:12:36 +01:00
clInstalledVersion = $( sudo -u bitcoin lightningd --version) # example output: v23.02.2
2021-09-27 23:34:49 +01:00
clInstalledVersionMajor = $( echo " ${ clInstalledVersion } " | cut -d "-" -f1 | cut -d "." -f1)
clInstalledVersionMain = $( echo " ${ clInstalledVersion } " | cut -d "-" -f1 | cut -d "." -f2)
clInstalledVersionMinor = $( echo " ${ clInstalledVersion } " | cut -d "-" -f1 | cut -d "." -f3)
# test if the installed version already the verified/recommended update version
clUpdateInstalled = $( echo " ${ clInstalledVersion } " | grep -c " ${ clUpdateVersion } " )
2022-07-27 08:37:36 +02:00
# get latest release from Core Lightning GitHub releases without release candidates
2022-12-16 11:12:56 +01:00
clLatestVersion = $( curl --header "X-GitHub-Api-Version:2022-11-28" -s https://api.github.com/repos/ElementsProject/lightning/releases | jq -r '.[].tag_name' | grep -v "rc" | head -n1)
2023-05-16 12:12:36 +01:00
# example output: v23.05
2021-09-27 23:34:49 +01:00
# INFO
if [ " ${ mode } " = "info" ] ; then
echo "# basic data"
echo " clInstalledVersion=' ${ clInstalledVersion } ' "
echo " clInstalledVersionMajor=' ${ clInstalledVersionMajor } ' "
echo " clInstalledVersionMain=' ${ clInstalledVersionMain } ' "
echo " clInstalledVersionMinor=' ${ clInstalledVersionMinor } ' "
echo "# the verified/recommended update option"
echo " clUpdateInstalled=' ${ clUpdateInstalled } ' "
echo " clUpdateVersion=' ${ clUpdateVersion } ' "
echo " clUpdateComment=' ${ clUpdateComment } ' "
2022-07-27 08:37:36 +02:00
echo "# reckless update option (latest Core Lightning release from GitHub)"
2021-09-27 23:34:49 +01:00
echo " clLatestVersion=' ${ clLatestVersion } ' "
exit 1
fi
# verified
if [ " ${ mode } " = "verified" ] ; then
echo "# cl.update.sh verified"
# check for optional second parameter: forced update version
# --> only does the verified update if its the given version
2023-05-08 19:30:39 +01:00
# this is needed for recovery/update.
2021-09-27 23:34:49 +01:00
fixedUpdateVersion = " $2 "
if [ ${# fixedUpdateVersion } -gt 0 ] ; then
echo " # checking for fixed version update: askedFor( ${ fixedUpdateVersion } ) available( ${ clUpdateVersion } ) "
if [ " ${ fixedUpdateVersion } " != " ${ clUpdateVersion } " ] ; 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"
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh delete clInterimsUpdate
2021-09-27 23:34:49 +01:00
exit 1
else
echo "# OK - update version is matching"
fi
fi
2023-05-08 19:30:39 +01:00
if [ ${# clUpdateVersion } -gt 0 ] ; then
2023-05-16 12:12:36 +01:00
# only update if the clUpdateVersion is different from the installed
if [ " ${ clInstalledVersion } " = " ${ clUpdateVersion } " ] ; then
echo " # clInstalledVersion = clUpdateVersion ( ${ clUpdateVersion } ) "
echo "# There is no need to update again."
else
/home/admin/config.scripts/cl.install.sh update ${ clUpdateVersion }
fi
2021-09-27 23:34:49 +01:00
else
/home/admin/config.scripts/cl.install.sh on
fi
# note: install will be done the same as reckless further down
clInterimsUpdateNew = " ${ clUpdateVersion } "
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 "# cl.update.sh reckless"
2021-12-19 23:56:40 +00:00
# only update if the latest release is different from the installed
2023-05-08 19:30:39 +01:00
if [ " ${ clInstalledVersion } " = " ${ clLatestVersion } " ] ; then
2023-05-16 12:12:36 +01:00
echo " # clInstalledVersion = clLatestVersion ( ${ clLatestVersion } ) "
2021-12-19 23:56:40 +00:00
echo "# There is no need to update again."
2023-05-16 12:12:36 +01:00
clInterimsUpdateNew = " ${ clLatestVersion } "
2021-12-19 23:56:40 +00:00
else
/home/admin/config.scripts/cl.install.sh update ${ clLatestVersion }
clInterimsUpdateNew = "reckless"
fi
2021-09-27 23:34:49 +01:00
fi
# JOINED INSTALL (verified & RECKLESS)
if [ " ${ mode } " = "verified" ] || [ " ${ mode } " = "reckless" ] ; then
echo "# flag update in raspiblitz config"
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh set clInterimsUpdate " ${ clInterimsUpdateNew } "
2021-09-27 23:34:49 +01:00
2022-07-27 08:37:36 +02:00
echo "# OK Core Lightning is installed"
2021-09-27 23:34:49 +01:00
echo "# NOTE: RaspiBlitz may need to reboot now"
exit 1
else
echo "error='parameter not known'"
exit 1
fi