Last active
December 25, 2020 07:18
-
-
Save m0n5t3r/7f066384d3d38cde034cd11fc1e80ad5 to your computer and use it in GitHub Desktop.
Lighthouse update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
function log() { | |
date +"[%Y-%m-%d %H:%M:%S] $*" | |
} | |
lighthouse=$HOME/bin/lighthouse | |
latest_release="$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/sigp/lighthouse/releases | jq 'sort_by("published_at") | .[0]')" | |
release_tag="$(echo "$latest_release" | jq -r '.tag_name')" | |
new_lighthouse="${lighthouse}-${release_tag}" | |
current_version="$($lighthouse -V | sed -e 's/^Lighthouse //;s/-[0-9a-f]\+$//')" | |
if [ "$release_tag" = "$current_version" ]; then | |
log "Already running the latest version $current_version" | |
if [ "$1" != "-f" ]; then | |
exit 0 | |
fi | |
fi | |
tarball_url="$(echo "$latest_release" | jq -r '.assets[] | select(.name | endswith("x86_64-unknown-linux-gnu.tar.gz")) | .browser_download_url')" | |
sigfile_url="$(echo "$latest_release" | jq -r '.assets[] | select(.name | endswith("x86_64-unknown-linux-gnu.tar.gz.asc")) | .browser_download_url')" | |
tarball_name="$(echo "$latest_release" | jq -r '.assets[] | select(.name | endswith("x86_64-unknown-linux-gnu.tar.gz")) | .name')" | |
sigfile_name="$(echo "$latest_release" | jq -r '.assets[] | select(.name | endswith("x86_64-unknown-linux-gnu.tar.gz.asc")) | .name')" | |
cd $HOME/tmp | |
wget -c $tarball_url | |
wget -c $sigfile_url | |
gpg --verify $sigfile_name $tarball_name | |
tar_lighthouse=./$(tar tf $tarball_name| grep 'lighthouse$') | |
tar xf $tarball_name | |
echo | |
echo | |
echo "Current version: $($lighthouse -V)" | |
echo "New version: $($tar_lighthouse -V)" | |
read -p "Replace? [y/N]: " REPLACE | |
if [ "${REPLACE^^}" = "Y" ]; then | |
mv $tar_lighthouse "${new_lighthouse}" | |
ln -sf "${new_lighthouse}" "$lighthouse" | |
sudo supervisorctl restart "lighthouse:*" | |
fi | |
# vim: set et ai si ts=4 sts=4 sw=4: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment