#!/usr/bin/env bash # # This script is duplicated in aws.org notes # [[ uname != "Darwin" ]] && echo "OSX Only"; exit 1 set -x INSTALL_DIR=${HOME}/.local BIN_DIR=${HOME}/bin create_choices_file(){ cat< /tmp/awschoices.xml choiceAttribute customLocation attributeSetting ${INSTALL_DIR} choiceIdentifier default EOF } cleanup_choices_file(){ rm /tmp/awschoices.xml } install_awscli() { curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "/tmp/AWSCLIV2.pkg" \ && installer -pkg /tmp/AWSCLIV2.pkg \ -target CurrentUserHomeDirectory \ -applyChoiceChangesXML /tmp/awschoices.xml \ && ln -sf ${INSTALL_DIR}/aws-cli/aws ${BIN_DIR}/aws \ && ln -sf ${INSTALL_DIR}/aws-cli/aws_completer ${BIN_DIR}/aws_completer rm /tmp/AWSCLIV2.pkg } install_samcli() { curl -L "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-macos-arm64.pkg" -o "/tmp/AWS_SAM_CLI.pkg" \ && installer -pkg /tmp/AWS_SAM_CLI.pkg \ -target CurrentUserHomeDirectory \ -applyChoiceChangesXML /tmp/awschoices.xml \ && ln -sf ${INSTALL_DIR}/aws-sam-cli/sam ${BIN_DIR}/sam rm /tmp/AWS_SAM_CLI.pkg } create_choices_file while [[ $# -gt 0 ]]; do key="$1" case $key in --sam) install_samcli shift # past argument ;; --cli) install_awscli shift # past argument ;; *) echo -e "Skipping unknown argument: $1." shift ;; esac done cleanup_choices_file