Skip to content

Instantly share code, notes, and snippets.

@scottj
Created November 25, 2023 20:35
Show Gist options
  • Save scottj/ff343a1e9843fe1ecd5fc41b6ddaaef1 to your computer and use it in GitHub Desktop.
Save scottj/ff343a1e9843fe1ecd5fc41b6ddaaef1 to your computer and use it in GitHub Desktop.
Update AWS CLI
#!/usr/bin/env bash
URL=https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
AWS=/usr/local/aws-cli
BIN=/usr/local/bin
TMP=$(mktemp -d /tmp/update-awscli.XXXXXX)
ZIP=$TMP/awscli.zip
echo [+] Downloading $URL
curl -so $ZIP $URL
if [[ -e $ZIP ]]; then
echo [+] Extracting files
unzip -q $ZIP -d $TMP && rm $ZIP
echo [+] Comparing versions
if [[ -x $BIN/aws && -x $TMP/aws/dist/aws ]]; then
OLD=$($BIN/aws --version | cut -d\ -f1)
NEW=$($TMP/aws/dist/aws --version | cut -d\ -f1)
if [[ $OLD == $NEW ]]; then
echo [=] Already on the latest version
else
echo [+] Updating
sudo $TMP/aws/install --bin-dir $BIN --install-dir $AWS --update
fi
else
echo [-] Error comparing files
fi
else
echo [-] Error downloading file
fi
echo [+] Cleaning up
rm -rf $TMP
if [[ ! -z $NEW ]]; then
echo [+] Version: $NEW
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment