Skip to content

Instantly share code, notes, and snippets.

@leggiero
Last active August 26, 2023 15:04
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 leggiero/73a7cfc9ad853e204b24530a88d54cf5 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/bash
# The MIT License (MIT)
# Copyright 2023 Eduardo Leggiero
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
set -e
arch=amd64
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-$arch-$latest_version.tgz
tar xf $tmp_dir/hub-linux-$arch-$latest_version.tgz -C $tmp_dir
$tmp_dir/hub-linux-$arch-$latest_version/install
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment