diff --git a/images/linux/scripts/installers/aws-sam-cli.sh b/images/linux/scripts/installers/aws-sam-cli.sh new file mode 100644 index 000000000..ac56144b3 --- /dev/null +++ b/images/linux/scripts/installers/aws-sam-cli.sh @@ -0,0 +1,31 @@ +#!/bin/bash +################################################################################ +## File: aws-sam-cli.sh +## Desc: Installs AWS SAM CLI +## Requires Python >=3.6, must be run as non-root user after toolset installation +################################################################################ + + +# Download latest aws sam cli sources +TarballUrl=$(curl -s https://api.github.com/repos/aws/aws-sam-cli/releases/latest | jq -r '.tarball_url') +TarballPath="/tmp/aws-sam-cli.tar.gz" +wget $TarballUrl -O $TarballPath +tar -xzvf $TarballPath -C /tmp +cd /tmp/aws-aws-sam-cli* + +mkdir /opt/python-aws-sam-cli +cp -r /opt/hostedtoolcache/Python/3.7* /opt/python-aws-sam-cli + +# Use copy of python 3.7 from toolcache to install aws sam, setuptools package required for the installation +Python3Dir=$(echo /opt/python-aws-sam-cli/3.7*/x64) +Python3BinDir="${Python3Dir}/bin" +$Python3BinDir/python3 -m pip install setuptools +$Python3BinDir/python3 setup.py install +ln -sf ${Python3BinDir}/sam /usr/local/bin/sam + +# Run tests to determine that the software installed as expected +echo "Testing to make sure that script performed as expected, and basic scenarios work" +if ! sam --version; then + echo "AWS SAM CLI was not installed" + exit 1 +fi diff --git a/images/linux/scripts/installers/python.sh b/images/linux/scripts/installers/python.sh index 8535074b0..b939b62b5 100644 --- a/images/linux/scripts/installers/python.sh +++ b/images/linux/scripts/installers/python.sh @@ -19,25 +19,33 @@ if isUbuntu20; then ln -s /usr/bin/pip3 /usr/bin/pip fi -# Install pipx -# Set pipx custom directory -export PIPX_BIN_DIR=/opt/pipx_bin -export PIPX_HOME=/opt/pipx +if isUbuntu18 || isUbuntu20 ; then + # Install pipx + # Set pipx custom directory + export PIPX_BIN_DIR=/opt/pipx_bin + export PIPX_HOME=/opt/pipx -python3 -m pip install pipx -python3 -m pipx ensurepath + python3 -m pip install pipx + python3 -m pipx ensurepath -# Update /etc/environment -setEtcEnvironmentVariable "PIPX_BIN_DIR" $PIPX_BIN_DIR -setEtcEnvironmentVariable "PIPX_HOME" $PIPX_HOME -prependEtcEnvironmentPath /opt/pipx_bin + # Update /etc/environment + setEtcEnvironmentVariable "PIPX_BIN_DIR" $PIPX_BIN_DIR + setEtcEnvironmentVariable "PIPX_HOME" $PIPX_HOME + prependEtcEnvironmentPath /opt/pipx_bin -# Add pipx bin directory to path -echo 'export PATH="$PATH:/opt/pipx_bin"' >> /etc/skel/.bashrc + # Add pipx bin directory to path + echo 'export PATH="$PATH:/opt/pipx_bin"' >> /etc/skel/.bashrc + + # Test pipx + if ! command -v pipx; then + echo "pipx was not installed or not found on PATH" + exit 1 + fi +fi # Run tests to determine that the software installed as expected echo "Testing to make sure that script performed as expected, and basic scenarios work" -for cmd in python pip python3 pip3 pipx; do +for cmd in python pip python3 pip3; do if ! command -v $cmd; then echo "$cmd was not installed or not found on PATH" exit 1 diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 2fc97542d..8a4255ec7 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -234,7 +234,10 @@ { "type": "shell", "scripts": [ - "{{template_dir}}/scripts/installers/pipx-packages.sh" + "{{template_dir}}/scripts/installers/aws-sam-cli.sh" + ], + "environment_vars": [ + "HELPER_SCRIPTS={{user `helper_script_folder`}}" ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" },