-
Notifications
You must be signed in to change notification settings - Fork 1.4k
AWS CLI feature #1326
AWS CLI feature #1326
Changes from all commits
a90a768
4a852c2
85894ce
e451dac
aa44ccd
e720bbf
eb14d69
72b8a9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,143 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
#!/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 | ||||||||||||||||||||||||||||||||||||||||||||||||
gbdzoqI2Y8cgH2nbfgp3DSasaLZEdCSsIsK1u05CinE7k2qZ7KgKAUIcT/cR/grk | ||||||||||||||||||||||||||||||||||||||||||||||||
C6VwsnDU0OUCideXcQ8WeHutqvgZH1JgKDbznoIzeQHJD238GEu+eKhRHcz8/jeG | ||||||||||||||||||||||||||||||||||||||||||||||||
94zkcgJOz3KbZGYMiTh277Fvj9zzvZsbMBCedV1BTg3TqgvdX4bdkhf5cH+7NtWO | ||||||||||||||||||||||||||||||||||||||||||||||||
lrFj6UwAsGukBTAOxC0l/dnSmZhJ7Z1KmEWilro/gOrjtOxqRQutlIqG22TaqoPG | ||||||||||||||||||||||||||||||||||||||||||||||||
fYVN+en3Zwbt97kcgZDwqbuykNt64oZWc4XKCa3mprEGC3IbJTBFqglXmZ7l9ywG | ||||||||||||||||||||||||||||||||||||||||||||||||
EEUJYOlb2XrSuPWml39beWdKM8kzr1OjnlOm6+lpTRCBfo0wa9F8YZRhHPAkwKkX | ||||||||||||||||||||||||||||||||||||||||||||||||
XDeOGpWRj4ohOx0d2GWkyV5xyN14p2tQOCdOODmz80yUTgRpPVQUtOEhXQARAQAB | ||||||||||||||||||||||||||||||||||||||||||||||||
tCFBV1MgQ0xJIFRlYW0gPGF3cy1jbGlAYW1hem9uLmNvbT6JAlQEEwEIAD4WIQT7 | ||||||||||||||||||||||||||||||||||||||||||||||||
Xbd/1cEYuAURraimMQrMRnJHXAUCXYKvtQIbAwUJB4TOAAULCQgHAgYVCgkICwIE | ||||||||||||||||||||||||||||||||||||||||||||||||
FgIDAQIeAQIXgAAKCRCmMQrMRnJHXJIXEAChLUIkg80uPUkGjE3jejvQSA1aWuAM | ||||||||||||||||||||||||||||||||||||||||||||||||
yzy6fdpdlRUz6M6nmsUhOExjVIvibEJpzK5mhuSZ4lb0vJ2ZUPgCv4zs2nBd7BGJ | ||||||||||||||||||||||||||||||||||||||||||||||||
MxKiWgBReGvTdqZ0SzyYH4PYCJSE732x/Fw9hfnh1dMTXNcrQXzwOmmFNNegG0Ox | ||||||||||||||||||||||||||||||||||||||||||||||||
au+VnpcR5Kz3smiTrIwZbRudo1ijhCYPQ7t5CMp9kjC6bObvy1hSIg2xNbMAN/Do | ||||||||||||||||||||||||||||||||||||||||||||||||
ikebAl36uA6Y/Uczjj3GxZW4ZWeFirMidKbtqvUz2y0UFszobjiBSqZZHCreC34B | ||||||||||||||||||||||||||||||||||||||||||||||||
hw9bFNpuWC/0SrXgohdsc6vK50pDGdV5kM2qo9tMQ/izsAwTh/d/GzZv8H4lV9eO | ||||||||||||||||||||||||||||||||||||||||||||||||
tEis+EpR497PaxKKh9tJf0N6Q1YLRHof5xePZtOIlS3gfvsH5hXA3HJ9yIxb8T0H | ||||||||||||||||||||||||||||||||||||||||||||||||
QYmVr3aIUes20i6meI3fuV36VFupwfrTKaL7VXnsrK2fq5cRvyJLNzXucg0WAjPF | ||||||||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
verify_aws_cli_gpg_signature() { | ||||||||||||||||||||||||||||||||||||||||||||||||
local filePath=$1 | ||||||||||||||||||||||||||||||||||||||||||||||||
local sigFilePath=$2 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
get_common_setting AWSCLI_GPG_KEY | ||||||||||||||||||||||||||||||||||||||||||||||||
get_common_setting AWSCLI_GPG_KEY_MATERIAL | ||||||||||||||||||||||||||||||||||||||||||||||||
local awsCliPublicKeyFile=aws-cli-public-key.pem | ||||||||||||||||||||||||||||||||||||||||||||||||
echo "${AWSCLI_GPG_KEY_MATERIAL}" > "${awsCliPublicKeyFile}" | ||||||||||||||||||||||||||||||||||||||||||||||||
gpg --quiet --import "${awsCliPublicKeyFile}" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
gpg --batch --quiet --verify "${sigFilePath}" "${filePath}" | ||||||||||||||||||||||||||||||||||||||||||||||||
local status=$? | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
gpg --batch --quiet --delete-keys "${AWSCLI_GPG_KEY}" | ||||||||||||||||||||||||||||||||||||||||||||||||
rm "${awsCliPublicKeyFile}" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that this script fails with the standard debian and ubuntu images due to the fact that curl and gpg are not in them. You can add the following to make sure these are installed if they're missing:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in eb14d69 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I actually just noticed that these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not download and source that file in separately right now. Users do tend to go to these files directly and curl the script in without the utility as well, so we try to keep them self-contained. So, there's a legacy here we're dealing with TBH. As the features functionality stabilizes, we'll shuffle things around, but there's a bit of a dual use here today. |
||||||||||||||||||||||||||||||||||||||||||||||||
echo "(*) Installing AWS CLI..." | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
install | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
echo "Done!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get this model to work, you'd still include the key as the default along with the get_common_setting script. Add the following:
This will update the setting if one is found and otherwise use what is embedded in the script. This is particularly critical for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I follow... I don't love having this giant base64 blob in two places, but I get that the script needs a default. Why would I add the
get_common_setting
function though, if it's already inshared/utils.sh
? I see that this function exists in the relatedazcli-debian.sh
script, but I don't get why its necessary there either. The body is identical to the shared function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not download and source that file in separately right now. Users do tend to go to these files directly and curl the script in without the utility as well, so we try to keep them self-contained. So, there's a legacy here we're dealing with TBH.
As the features functionality stabilizes, we'll shuffle things around, but there's a bit of a dual use here today.
So, this is point-in-time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and on the blob, yes - the idea with the central file is for out of band updates. There are pros-and-cons with having a default value here. Technically we could separate updating the settings.env part of the PR out, merge that first, then merge the script itself. That would be the alternative which would work too.
What having a value here does is that it creates a fallback value if for some reason the script is unable to pull common
settings.env
file for some reason (network blips, etc). The get_common_setting script intentionally prints just a warning (Could not download settings file. Skipping.) and continues on using whatever the value was before that point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I can accept "because legacy" lol. Added
get_common_setting
in 72b8a9a.