Skip to content

Instantly share code, notes, and snippets.

@adityatelange
Created March 18, 2022 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityatelange/98a6b8e8cf9551a5eeee129aead01823 to your computer and use it in GitHub Desktop.
Save adityatelange/98a6b8e8cf9551a5eeee129aead01823 to your computer and use it in GitHub Desktop.
Update GH CLI on Ubuntu / Deb amd64
#!/bin/bash
url=$(wget -O- -q https://api.github.com/repos/cli/cli/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep "linux_amd64.deb")
# url=$(wget -O- -q --header="Authorization: token xyzABC" https://api.github.com/repos/cli/cli/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep "linux_amd64.deb")
version=$(echo $url | cut -d '/' -f 8 | cut -d 'v' -f 2)
name=$(echo $url | cut -d '/' -f 9)
checksums_url="https://github.com/cli/cli/releases/download/v${version}/gh_${version}_checksums.txt"
installed_ver=$(gh version | cut -d " " -f 3 | cut -d "h" -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 "gh_${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 "gh_${version}_checksums.txt" | grep $name > "${name}.sha256"
if sha256sum --check $name.sha256 ;then
sudo dpkg -i $name
fi
fi
else
echo "GH CLI is Up-to-Date (¬_¬)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment