Skip to content

Instantly share code, notes, and snippets.

@adityatelange
Last active November 6, 2022 05:46
Show Gist options
  • Save adityatelange/5ed465f86e3e09e3919f39a3f2e4c934 to your computer and use it in GitHub Desktop.
Save adityatelange/5ed465f86e3e09e3919f39a3f2e4c934 to your computer and use it in GitHub Desktop.
Update Hugo [not extended] on Ubuntu / Deb amd64
#!/bin/bash
url=$(wget -O- -q https://api.github.com/repos/gohugoio/hugo/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep "linux-amd64.deb" | grep -v "hugo_extended")
# url=$(wget -O- -q --header="Authorization: token xyzABC" https://api.github.com/repos/gohugoio/hugo/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep "linux-amd64.deb" | grep -v "hugo_extended")
version=$(echo $url | cut -d '/' -f 8 | cut -d 'v' -f 2)
name=$(echo $url | cut -d '/' -f 9)
checksums_url="https://github.com/gohugoio/hugo/releases/download/v${version}/hugo_${version}_checksums.txt"
installed_ver=$(hugo version | cut -d "v" -f 2 | cut -d "-" -f 1)
if [ "$version" != "$installed_ver" ]; then
cd /tmp/
if [ ! -f $name.sha256 ] || [ ! -f $name ]; then
wget -q -O "${name}" "${url}" --show-progress
wget -q "${checksums_url}" --show-progress
cat "hugo_${version}_checksums.txt" | grep $name > "${name}.sha256"
if sha256sum --check $name.sha256 ;then
sudo dpkg -i $name
fi
else
wget -q "${checksums_url}" --show-progress
cat "hugo_${version}_checksums.txt" | grep $name > "${name}.sha256"
if sha256sum --check $name.sha256 ;then
sudo dpkg -i $name
fi
fi
else
echo "Hugo is Up-to-Date (¬_¬)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment