Skip to content

Instantly share code, notes, and snippets.

@adv0r
Created August 3, 2022 09:35
Show Gist options
  • Save adv0r/3d4e8144cca5df43e739726ae34c4667 to your computer and use it in GitHub Desktop.
Save adv0r/3d4e8144cca5df43e739726ae34c4667 to your computer and use it in GitHub Desktop.
A script to update lighthouse to a given version
#!/bin/bash
# Assumption 1: you have lighthouse running on ubuntu with systemctl
# Assumption 2: lighthouse binary is in /home/lighthouse/.cargo/bin/lighthouse
# If otherwise, change the script accordingly
latestVersion="2.5.0" ##Change this before running, see https://github.com/sigp/lighthouse/releases
logFile="/home/lighthouse/lighthouseUpdate.log"
filename="lighthouse-v"$latestVersion"-aarch64-unknown-linux-gnu.tar.gz"
url="https://github.com/sigp/lighthouse/releases/download/v"$latestVersion"/lighthouse-v"$latestVersion"-aarch64-unknown-linux-gnu.tar.gz"
#remove the old logfile
rm $logFile
currentVersion=$(/home/lighthouse/.cargo/bin/lighthouse --version)
currentVersion=${currentVersion:0:25}
echo 'lighthouse current version' $currentVersion
echo 'Now updating lighthouse to v'$latestVersion', process started'
cd lighthouse-bin/
echo 'Downloading v'$latestVersion' from ' $url
wget $url > $logFile 2>&1
echo 'Unpacking '$filename
tar -xvf $filename >> $logFile 2>&1
echo 'Stoppping validator and beacon node (can take some time)'
sudo systemctl stop lighthousevalidator >> $logFile 2>&1
sudo systemctl stop lighthousebeacon >> $logFile 2>&1
echo 'Backing up the old bin to /home/lighthouse/.cargo/bin/_lighthouse'
mv /home/lighthouse/.cargo/bin/lighthouse /home/lighthouse/.cargo/bin/_lighthouse
echo 'Replacing the new binary'
mv lighthouse /home/lighthouse/.cargo/bin/lighthouse
installedVersion=$(/home/lighthouse/.cargo/bin/lighthouse --version)
installedVersion=${installedVersion:0:25}
echo 'Checking installed version: ' $installedVersion
echo 'Starting beacon and validator node (can take some time)'
sudo systemctl start lighthousebeacon >> $logFile 2>&1
sudo systemctl start lighthousevalidator >> $logFile 2>&1
echo 'Removing the tar compressed file '$filename
rm $filename
echo "Process completed! Check the logs in "$logFile
echo 'if it failed, you could restore the old version('$currentVersion') with mv /home/lighthouse/.cargo/bin/_lighthouse /home/lighthouse/.cargo/bin/lighthouse'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment