Skip to content

Instantly share code, notes, and snippets.

@moto-timo
Created February 23, 2023 05:18
Show Gist options
  • Save moto-timo/7c583f76fb2b54c33a0c4b97053284d3 to your computer and use it in GitHub Desktop.
Save moto-timo/7c583f76fb2b54c33a0c4b97053284d3 to your computer and use it in GitHub Desktop.
#!/bin/sh
USER=digitalocean
REPO=doctl
VERSION=$(curl -s https://api.github.com/repos/$USER/$REPO/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
MACHINE=$(uname -m)
DOCTL_VERSION=$(doctl version | grep -oP '(\d+\.\d+\.\d+)' )
echo "Current doctl version: v$DOCTL_VERSION"
echo "Upstream doctl version: $VERSION"
# https://github.com/digitalocean/doctl/releases/download/v1.92.1/doctl-1.92.1-linux-amd64.tar.gz
if [ "${MACHINE}" = 'x86_64' ]; then
MACHINE='amd64'
fi
if [ "${MACHINE}" = 'aarch64' ]; then
MACHINE='arm64'
fi
if [ v"${DOCTL_VERSION}" != "${VERSION}" ]; then
wget -qO- https://github.com/${USER}/${REPO}/releases/download/$VERSION/${REPO}-${VERSION:1}-linux-${MACHINE}.tar.gz | tar -xvz -C /tmp
sudo mv /tmp/doctl /usr/local/bin/
else
echo "Nothing to do: v${DOCTL_VERSION} == ${VERSION}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment