diff options
author | Josh Spicer <josh@joshspicer.com> | 2022-05-10 01:16:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-10 01:16:15 +0300 |
commit | 9efe4b3c4a5f07c45cf6ed69900006eed0e844b9 (patch) | |
tree | 1c120109a1794b913a3c71df0a456eb0ad411a54 /collection/aws-cli/install.sh | |
parent | 8759124c532d93b6e1ab38e391554d287b956d83 (diff) |
init (#1)
* init
* some copy pastin
* install.sh ref
* fixes
Diffstat (limited to 'collection/aws-cli/install.sh')
-rw-r--r-- | collection/aws-cli/install.sh | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/collection/aws-cli/install.sh b/collection/aws-cli/install.sh new file mode 100644 index 0000000..0d204de --- /dev/null +++ b/collection/aws-cli/install.sh @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/awscli.md +# Maintainer: The VS Code and Codespaces Teams +# +# Syntax: ./awscli-debian.sh [AWS CLI version] + +set -e + +AWSCLI_VERSION=${1:-"latest"} +AWSCLI_GPG_KEY=FB5DB77FD5C118B80511ADA8A6310ACC4672475C +AWSCLI_GPG_KEY_MATERIAL="-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBF2Cr7UBEADJZHcgusOJl7ENSyumXh85z0TRV0xJorM2B/JL0kHOyigQluUG +ZMLhENaG0bYatdrKP+3H91lvK050pXwnO/R7fB/FSTouki4ciIx5OuLlnJZIxSzx +PqGl0mkxImLNbGWoi6Lto0LYxqHN2iQtzlwTVmq9733zd3XfcXrZ3+LblHAgEt5G +TfNxEKJ8soPLyWmwDH6HWCnjZ/aIQRBTIQ05uVeEoYxSh6wOai7ss/KveoSNBbYz +gbdzoqI2Y8cgH2nbfgp3DSasaLZ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WAjPF +RrAGLzY7nP1xeg1a0aeP+pdsqjqlPJom8OCWc1+6DWbg0jsC74WoesAqgBItODMB +rsal1y/q+bPzpsnWjzHV8+1/EtZmSc8ZUGSJOPkfC7hObnfkl18h+1QtKTjZme4d +H17gsBJr+opwJw/Zio2LMjQBOqlm3K1A4zFTh7wBC7He6KPQea1p2XAMgtvATtNe +YLZATHZKTJyiqA== +=vYOk +-----END PGP PUBLIC KEY BLOCK-----" + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Get central common setting +get_common_setting() { + if [ "${common_settings_file_loaded}" != "true" ]; then + curl -sfL "https://aka.ms/vscode-dev-containers/script-library/settings.env" 2>/dev/null -o /tmp/vsdc-settings.env || echo "Could not download settings file. Skipping." + common_settings_file_loaded=true + fi + if [ -f "/tmp/vsdc-settings.env" ]; then + local multi_line="" + if [ "$2" = "true" ]; then multi_line="-z"; fi + local result="$(grep ${multi_line} -oP "$1=\"?\K[^\"]+" /tmp/vsdc-settings.env | tr -d '\0')" + if [ ! -z "${result}" ]; then declare -g $1="${result}"; fi + fi + echo "$1=${!1}" +} + +# Function to run apt-get if needed +apt_get_update_if_needed() +{ + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update + else + echo "Skipping apt-get update." + fi +} + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update_if_needed + apt-get -y install --no-install-recommends "$@" + fi +} + +export DEBIAN_FRONTEND=noninteractive + +check_packages curl ca-certificates gnupg2 dirmngr unzip + +verify_aws_cli_gpg_signature() { + local filePath=$1 + local sigFilePath=$2 + + get_common_setting AWSCLI_GPG_KEY + get_common_setting AWSCLI_GPG_KEY_MATERIAL true + local awsGpgKeyring=aws-cli-public-key.gpg + + echo "${AWSCLI_GPG_KEY_MATERIAL}" | gpg --dearmor > "./${awsGpgKeyring}" + gpg --batch --quiet --no-default-keyring --keyring "./${awsGpgKeyring}" --verify "${sigFilePath}" "${filePath}" + local status=$? + + rm "./${awsGpgKeyring}" + + return ${status} +} + +install() { + local scriptZipFile=awscli.zip + local scriptSigFile=awscli.sig + + # See Linux install docs at https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html + if [ "${AWSCLI_VERSION}" != "latest" ]; then + local versionStr=-${AWSCLI_VERSION} + fi + architecture=$(dpkg --print-architecture) + case "${architecture}" in + amd64) architectureStr=x86_64 ;; + arm64) architectureStr=aarch64 ;; + *) + echo "AWS CLI does not support machine architecture '$architecture'. Please use an x86-64 or ARM64 machine." + exit 1 + esac + local scriptUrl=https://awscli.amazonaws.com/awscli-exe-linux-${architectureStr}${versionStr}.zip + curl "${scriptUrl}" -o "${scriptZipFile}" + curl "${scriptUrl}.sig" -o "${scriptSigFile}" + + verify_aws_cli_gpg_signature "$scriptZipFile" "$scriptSigFile" + if (( $? > 0 )); then + echo "Could not verify GPG signature of AWS CLI install script. Make sure you provided a valid version." + exit 1 + fi + + unzip "${scriptZipFile}" + ./aws/install + + rm -rf ./aws +} + +echo "(*) Installing AWS CLI..." + +install + +echo "Done!" |