Trouble installing AWS CLI version 2

rpayne
Contributor II

Ok, Let me preface this by first stating that scripting is NOT my strong point.
I'm attempting to install AWS CLI version 2 for all users per the instructions on:

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html#cliv2-mac-install-cmd

Attempting to run the commands via policy result in an exit code 127. I've found a few posts about AWSCLI version 1, but none of the solutions seem to work. Any suggestions?

7 REPLIES 7

Mauricio
Contributor III

@rpayne Could you post your script, please?

Mauricio
Contributor III

@rpayne Just put a rough script based on the AWS info.

#!/bin/bash

#  download the AWSCLIV2.pkg to tmp folder and return the http_code
response=$(/usr/bin/curl --silent --write-out "%{http_code}" "https://awscli.amazonaws.com/AWSCLIV2.pkg" --output /tmp/AWSCLIV2.pkg)

checkForV1() {
  # https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html#install-macosos-bundled-uninstall
  # Uninstall the AWS CLI version 1 bundled installer
  # The bundled installer puts everything inside of the installation directory except the optional symlink, so to uninstall, you just need to delete those two items.

  if [[ -d  /usr/local/aws  ]]; then
    echo  "AWD CLI version 1 found"
    /bin/rm -rf /usr/local/aws
    /bin/rm /usr/local/bin/aws
  else
    echo  "AWD CLI version 1 not found"
  fi

}


# check if the download was successful
if [[ $response -eq 200  ]]; then
  echo "package downloaded"

  # https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html
  # Important
  # AWS CLI versions 1 and 2 use the same aws command name. If you have both versions installed, your computer uses the first one found in your search path. If you previously installed AWS CLI version 1, we recommend that you do one of the following to use AWS CLI version 2:
  # Recommended – Uninstall AWS CLI version 1 and use only AWS CLI version 2.
  checkForV1

  # install the package
  /usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target / || echo "Ops! Problem with the installer" ; exit 1

  # clean up
  /bin/rm /tmp/AWSCLIV2.pkg

else
  echo "download error: $response"
  # exit the curl download code so we can see in the Jamf reports where it is failing.
  exit $response
fi

exit 0

Tested on 10.15.6 VM and looks OK

kissland
New Contributor III

@Mauricio Hey, thanks for the script.

I seem to be getting the following after it installs successfully.

Running script Install AWS CLI 2...
Script exit code: 1
Script result: package downloaded
AWD CLI version 1 not found
installer: Package name is AWS Command Line Interface
installer: Upgrading at base path /
installer: The upgrade was successful.
Error running script: return code was 1.

Mauricio
Contributor III

@kissland Try to change the line of the installer.

from

/usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target / || echo "Ops! Problem with the installer" ; exit 1

to

/usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target /

You will be able to get the installer output in the log.
Hope that helps.
Regards

kissland
New Contributor III

@Mauricio Seems to work now, how can I check whether the $response returns anything? After running the script in terminal, when I run $response its just blank

Mauricio
Contributor III

@kissland Not sure if I understand the question.

If you run the curl command in Terminal that variable will be available

313f9376cfd0408aac3695e2e34847c0

If you run the script in the Terminal then the "package downloaded" is the clue that $response was 200, that variable is only available to the script.

23ec1b5a7a6a41e0af6329cb5be6f5b7

Does it make sense?
Regards

Mcleveland
New Contributor III

A lot has changed during this time, but just in case anyone goes to this post:

https://github.com/Installomator/Installomator <--- would be a good resource to use


awscli2)
    # credit: Bilal Habib (@Pro4TLZZ)
    name="AWSCLI"
    type="pkg"
    packageID="com.amazon.aws.cli2"
    downloadURL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
    appNewVersion=$( curl -fs "https://raw.githubusercontent.com/aws/aws-cli/v2/CHANGELOG.rst" | grep -i "CHANGELOG" -a4 | grep "[0-9.]" )
    expectedTeamID="94KV3E626L"
    ;;