Created
November 28, 2022 08:45
-
-
Save ashemedai/774dcebdbfc723bb191d203e6e57aca8 to your computer and use it in GitHub Desktop.
AWS SAM CLI installer/update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
AWSSAMCLI_DIST="awssamcli.zip" | |
LOCAL_BIN_DIR="${HOME}/.local/bin" | |
LOCAL_SHARE_DIR="${HOME}/.local/share/sam" | |
if [ -z "$(which curl)" ] || [ -z "$(which unzip)" ]; then | |
echo "Please make sure curl and unzip are installed" | |
exit 1 | |
fi | |
TMP_DIR=$(mktemp -d) | |
echo "Fetching latest AWS SAM CLI release file" | |
curl -sL "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip" -o "${TMP_DIR}/${AWSSAMCLI_DIST}" | |
echo "Unpacking AWS SAM CLI files" | |
unzip -q "${TMP_DIR}/${AWSSAMCLI_DIST}" -d "${TMP_DIR}" | |
if [ -z "$(which sam)" ]; then | |
echo "Installing AWS SAM CLI to your home directory" | |
"${TMP_DIR}"/install -b "${LOCAL_BIN_DIR}" -i "${LOCAL_SHARE_DIR}" | |
echo 'Add ${HOME}/.local/bin to your PATH environment variable as needed to run "sam" directly' | |
else | |
echo "Updating existing AWS SAM CLI installation" | |
"${TMP_DIR}"/install -u -b "${LOCAL_BIN_DIR}" -i "${LOCAL_SHARE_DIR}" | |
fi | |
if [ "$(ls -1 ${LOCAL_SHARE_DIR} | wc -l)" -gt 5 ]; then | |
# No auto-cleanup since that needs semver comparisons | |
echo "You have 5 or more AWS SAM CLI versions in ${LOCAL_SHARE_DIR}, please consider cleaning older versions" | |
echo "Currently occupying: $(du -sh ${LOCAL_SHARE_DIR} | cut -f1)" | |
fi | |
echo "Cleaning installation files from ${TMP_DIR}" | |
rm -rf "${TMP_DIR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment