Skip to content

Instantly share code, notes, and snippets.

@shaon
Last active March 9, 2018 14:43
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 shaon/4242049f353f41c8ed933230f9add55e to your computer and use it in GitHub Desktop.
Save shaon/4242049f353f41c8ed933230f9add55e to your computer and use it in GitHub Desktop.
#!/bin/bash
function get_contents() {
if [ -x "$(which curl)" ]; then
curl -s -f "$1"
elif [ -x "$(which wget)" ]; then
wget "$1" -O -
else
die "No download utility (curl, wget)"
fi
}
BUCKET_NAME="<CHANGE ME!!>"
readonly SCRIPT_NAME="aws-install-ssm-agent"
SCRIPT_URL="https://s3.amazonaws.com/$BUCKET_NAME/ssm/$SCRIPT_NAME"
cd /tmp
FILE_SIZE=0
MAX_RETRY_COUNT=3
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRY_COUNT ] ; do
echo AWS-UpdateLinuxAmi: Downloading script from $SCRIPT_URL
get_contents "$SCRIPT_URL" > "$SCRIPT_NAME"
FILE_SIZE=$(du -k /tmp/$SCRIPT_NAME | cut -f1)
echo AWS-UpdateLinuxAmi: Finished downloading script, size: $FILE_SIZE
if [ $FILE_SIZE -gt 0 ]; then
break
else
if [[ $RETRY_COUNT -lt MAX_RETRY_COUNT ]]; then
RETRY_COUNT=$((RETRY_COUNT+1));
echo AWS-UpdateLinuxAmi: FileSize is 0, retryCount: $RETRY_COUNT
fi
fi
done
if [ $FILE_SIZE -gt 0 ]; then
chmod +x "$SCRIPT_NAME"
echo AWS-UpdateLinuxAmi: Running UpdateSSMAgent script now ....
./"$SCRIPT_NAME"
else
echo AWS-UpdateLinuxAmi: Unable to download script, quitting ....
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment