Skip to content

Instantly share code, notes, and snippets.

@leggiero
Last active August 26, 2023 15:04
Show Gist options
  • Select an option

  • Save leggiero/73a7cfc9ad853e204b24530a88d54cf5 to your computer and use it in GitHub Desktop.

Select an option

Save leggiero/73a7cfc9ad853e204b24530a88d54cf5 to your computer and use it in GitHub Desktop.
Install or upgrade hub; ideal to run via cron, e.g. /etc/cron.weekly/hub-upgrade
#!/bin/sh
set -e
if [ -f /usr/local/bin/hub ]; then
current_version=$(/usr/local/bin/hub --version | grep "hub version" | cut -d' ' -f3)
fi
latest_version=$(curl -s https://api.github.com/repos/github/hub/releases/latest | grep -oP '"tag_name": "v?\K(.*)(?=")')
if [ "$latest_version" != "$current_version" ]; then
tmp_dir=$(mktemp -d /tmp/$(basename "$0").XXXXXX)
trap "rm -rf $tmp_dir" EXIT
wget -q -P $tmp_dir https://github.com/github/hub/releases/download/v$latest_version/hub-linux-amd64-$latest_version.tgz
tar xf $tmp_dir/hub-linux-amd64-$latest_version.tgz -C $tmp_dir
$tmp_dir/hub-linux-amd64-$latest_version/install
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment