Skip to content

Instantly share code, notes, and snippets.

@Strykar
Last active October 16, 2023 11:13
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Strykar/389e1a1ed2e2ecf4068cafd584d735e0 to your computer and use it in GitHub Desktop.
Save Strykar/389e1a1ed2e2ecf4068cafd584d735e0 to your computer and use it in GitHub Desktop.
Upgrade Livepeer Go binaries. Run as: $ upgrade_livepeer.sh 4efbda6d5e6586e7eb1e6ccbd526da65cdbe2e4e27a01cb76b1f2893fe790fdb
#!/bin/bash
# Download, extract and update Livepeer binary from Github to a pre-existing directory you set below
# It assumes you have extracted the previous livpeer tar.gz in it and run livepeer from the same directory
# Not intended to be run as root
#
# Expects bash, jq, curl, grep, sed, sha256sum and tar to be installed, usually available even on embedded systems
# Windows Subsystem for Linux (WSL) or Cygwin should provide every utility on Windows
# shellcheck disable=SC2015
set -euf -o pipefail
# Requires you to specify _ostype and the path to the existing install in _lptdir below
# Do not append the directory created by the tar.gz like livepeer-linux-amd64 or livepeer-windows-amd64
# This would look like:
## $ ls /home/strykar/livepeer
## livepeer-linux-amd64 livepeer-linux-amd64.tar.gz
### User config starts
_ostype=linux # Either 1) darwin 2) windows 3) linux
_lptdir="/home/strykar/livepeer"
### User config ends
# Start checks
[ -d "${_lptdir}" ] && [ ! -h "${_lptdir}" ] || \
{ echo >&2 "${_lptdir} does not exist. Exiting."; exit 127; }
[[ "${_ostype}" =~ ^(darwin|windows|linux)$ ]] || \
{ echo >&2 "The variable _ostype can only be one of 1) darwin 2) windows 3) linux"; exit 127; }
hash jq sed tar curl grep sha256sum 2>/dev/null || \
{ echo >&2 "Some required utilities are not installed. **Aborting.**"; exit 127; }
[ -z "$*" ] && { echo >&2 "No checksum specified! Copy paste the appropriate SHA256sum from \
https://github.com/livepeer/go-livepeer/releases as the first argument to the script."; exit 127; }
# Checks complete
# Get installed version and latest release from Github
_curdir=${_lptdir}/livepeer-${_ostype}-amd64
_curver=$(${_curdir}/livepeer -version \
| sed -n 's/^Livepeer Node Version: \([^-]*\).*$/\1/p')
_newver=$(curl -sL https://api.github.com/repos/livepeer/go-livepeer/releases/latest \
| jq -r '.assets[].browser_download_url' \
| grep -m1 -F -e ${_ostype})
# Exit if installed version is the latest
url="${_newver}" ver=${url%/*} ver=${ver##*/v}; declare url ver
echo "Current Version: ${_curver} => New Version: ${ver}"
[ "${ver}" = "${_curver}" ] && { echo >&2 "Latest version already installed"; exit 1;}
# Download release
echo "Downloading ${_newver}"
pushd ${_lptdir} > /dev/null
curl -sLo livepeer-${_ostype}-amd64.tar.gz "${_newver}"
# Verify csum
echo "Verifying SHA256 checksum.."
_csum=$(echo "$1" livepeer-${_ostype}-amd64.tar.gz | /usr/bin/sha256sum --strict --ignore-missing -c)
[ "${_csum}" != "livepeer-${_ostype}-amd64.tar.gz: OK" ] && { echo >&2 "** WARNING ** Checksum mismatch, exiting!"; exit 129; }
# Install new version
if [ "${ver}" != "${_curver}" ]; then
echo "Installing ${_newver}"
pushd ${_lptdir} > /dev/null
tarball="$(find . -name "livepeer-${_ostype}-amd64.tar.gz" 2>/dev/null)"
tar -xzf "${tarball}"
popd > /dev/null
echo -n " ... Upgrade complete!"
#echo "Restarting Livepeer services.."
#/usr/bin/sudo /usr/bin/systemctl restart livepeer.service
#/usr/bin/systemctl --user restart gtx1070.service
#/usr/bin/systemctl --user restart t600.service
#echo -n " ... done."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment