Skip to content

Instantly share code, notes, and snippets.

@seiyashima
Forked from jamesls/alias
Last active September 26, 2020 04:39
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 seiyashima/24bd19f0f5224e82a1b0b1f793acbd4b to your computer and use it in GitHub Desktop.
Save seiyashima/24bd19f0f5224e82a1b0b1f793acbd4b to your computer and use it in GitHub Desktop.
AWS CLI v2 upgrade aliases.
[toplevel]
# Put this in ~/.aws/cli/alias
# and you'll have an "aws upgrade"
# and an "aws check-upgrade" command.
#
# Only works on macOS and installs using
# the .pkg installer.
#
upgrade = !f() {
curl -s "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "/tmp/AWSCLIV2.pkg"
sudo installer -pkg /tmp/AWSCLIV2.pkg -target /
rm -f /tmp/AWSCLIV2.pkg
}; f
check-upgrade = !f() {
rm -f /tmp/AWSCLIV2.pkg
latest_cli_version=$(curl -s "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o - | \
tar xOv - 2>/dev/null | \
grep -a '<pkg-info' | \
sed "s#.* version=\"\([0-9\.]*\)\".*#\1#")
release_date=$(curl -sI "https://awscli.amazonaws.com/AWSCLIV2.pkg" | \
grep 'Last-Modified' | cut -d':' -f 2- | tr '\r\n' ' ')
echo "Current version: $(aws --version | cut -d' ' -f 1)"
echo " New version: aws-cli/${latest_cli_version} (${release_date})"
if [ "$(aws --version | cut -d' ' -f 1)" != "aws-cli/${latest_cli_version}" ]; then
echo "Current version and the new one are different. The upgrade will begin to start..."
aws upgrade
else
echo "Now, you've already installed the latest version!"
fi
}; f
install-version = !f() {
curl -s "https://awscli.amazonaws.com/AWSCLIV2-$1.pkg" -o "/tmp/AWSCLIV2.pkg"
sudo installer -pkg /tmp/AWSCLIV2.pkg -target /
rm -f /tmp/AWSCLIV2.pkg
}; f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment