Skip to content

Instantly share code, notes, and snippets.

@JoshSalway
Last active October 4, 2023 07:26
Show Gist options
  • Save JoshSalway/594108f4d388c733806d112af90b0695 to your computer and use it in GitHub Desktop.
Save JoshSalway/594108f4d388c733806d112af90b0695 to your computer and use it in GitHub Desktop.
#!/bin/zsh
install_aws_cli () {
echo "Downloading AWS CLI..."
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
echo "Installing AWS CLI..."
sudo installer -pkg AWSCLIV2.pkg -target /
rm -f AWSCLIV2.pkg
echo "Package file deleted successfully!"
echo "AWS CLI installed successfully!"
}
echo "Checking current AWS CLI version..."
if ! command -v aws &> /dev/null; then
echo "AWS CLI not installed. Installing now..."
install_aws_cli
else
current_version=$(aws --version 2>&1 | grep -oE 'aws-cli/[0-9]+\.[0-9]+\.[0-9]+' | cut -d'/' -f2)
echo "Current AWS CLI version: $current_version"
echo "Checking for the latest version..."
latest_version=$(curl -s https://raw.githubusercontent.com/aws/aws-cli/v2/CHANGELOG.rst | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)
echo "Latest AWS CLI version: $latest_version"
if [[ "$latest_version" != "$current_version" ]]; then
echo "Upgrading AWS CLI..."
install_aws_cli
else
echo "AWS CLI is already up to date. No upgrade necessary."
fi
fi
@JoshSalway
Copy link
Author

JoshSalway commented Oct 4, 2023

Example output:

Checking current AWS CLI version...
Current AWS CLI version: 2.13.1
Checking for the latest version...
Latest AWS CLI version: 2.13.23
Upgrading AWS CLI...
Downloading AWS CLI...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 36.3M  100 36.3M    0     0  6236k      0  0:00:05  0:00:05 --:--:-- 6476k
Installing AWS CLI...
Password:
installer: Package name is AWS Command Line Interface
installer: Upgrading at base path /
installer: The upgrade was successful.
Package file deleted successfully!
AWS CLI installed successfully!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment