aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

install script multiple issues

Open fredyouhanaie opened this issue 3 years ago • 6 comments

Describe the bug

Hi

I noticed multiple tiny issues in the install script, while looking into the first one in the list below:

  1. The -i and -b options do not check if the directory name has been supplied. The shift command fails, but the script continues.
  2. shellcheck complains about a self assigned variable: INSTALL_DIR="$INSTALL_DIR"
  3. create_bin_symlinks() does not catch the mkdir error
  4. The install dir should be verified that it is absolute pathname, otherwise create_bin_symlinks() and create_current_symlinks() will generate bad symlinks.

Expected Behavior

  1. The script should exit if argument is missing
  2. The assignment is superfluous, does not affect the behaviour
  3. The script should exit, if mkdir fails
  4. The binary symlinks should be valid

Current Behavior

  1. There is an error message, but the script continues
  2. Does not affect the behaviour
  3. An error is reported, but the script continues
  4. If the supplied install dir (from -i) is a relative path, the symlink may be invalid

Reproduction Steps

In all cases, unpack the zip file and change to that directory:

  1. run install with -i or -b, but no arg
./install -b`
./install: line 64: shift: shift count out of range
...
  1. run shellcheck against the script
shellcheck install 

In install line 81:
  INSTALL_DIR="$INSTALL_DIR"
  ^---------^ SC2269 (info): This variable is assigned to itself, so the assignment does nothing.

For more information:
  https://www.shellcheck.net/wiki/SC2269 -- This variable is assigned to itse...
  1. create a file that has same name as the directory being created
touch bbb
./install -i aaa -b bbb
mkdir: cannot create directory ‘bbb’: File exists
ln: failed to access 'bbb/aws': Not a directory
ln: failed to access 'bbb/aws_completer': Not a directory
You can now run: bbb/aws --version

Note: the script should have aborted after the mkdir error.

  1. same steps as above
ls -l aaa/v2
total 4
drwxr-xr-x 4 fy fy 4096 Sep 29 16:54 2.7.35
lrwxrwxrwx 1 fy fy   13 Sep 29 16:54 current -> aaa/v2/2.7.35

ls -l aaa/v2/current/
ls: cannot access 'aaa/v2/current/': No such file or directory

Possible Solution

  1. Check for $# when parsing -i and -b
  2. Remove the superfluous line
  3. Append || exit 1 to the mkdir line
  4. Check that the value supplied in -i is an absolute pathname

I can provide a PR for the above, if required.

Additional Information/Context

All the above were carried out on a Linux box.

I'm not sure how the other OSes behave, or if they use the same script!

CLI version used

aws-cli/2.7.35 Python/3.9.11 Linux/5.19.11-arch1-1 exe/x86_64.arch prompt/off

Environment details (OS name and version, etc.)

5.19.11-arch1-1 GNU/Linux

fredyouhanaie avatar Sep 29 '22 16:09 fredyouhanaie

Hi @fredyouhanaie thanks for reaching out. It looks like this overlaps with https://github.com/aws/aws-cli/issues/6852. Does the comment here help provide more context: https://github.com/aws/aws-cli/issues/6852#issuecomment-1092100465? Please let us know if there's anything else you want to add or distinguish between these two issues.

tim-finnigan avatar Sep 29 '22 16:09 tim-finnigan

Hi @tim-finnigan

Thanks for the quick response. Yes, the #6852 comment does seem to address my 4th item, although the fix doesn't seem to be present in the latest release!

The other 3, though trivial, still stand.

fredyouhanaie avatar Sep 29 '22 17:09 fredyouhanaie

After a second look it appears that the PR mentioned in #6852 fixes the file aws-cli/scripts/install, which is a Python script.

However, the install script that is bundled with https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip is a shell script and comes from aws-cli/exe/assets/install on the v2 branch.

This issue is about the shell script in the zip file!

fredyouhanaie avatar Sep 29 '22 17:09 fredyouhanaie

Thanks @fredyouhanaie for following up and clarifying those points. I'll need to bring this up for discussion with the team to find out why that PR was closed and what the next steps should be regarding these issues.

tim-finnigan avatar Sep 29 '22 18:09 tim-finnigan

Hello, re-looking at the issue,

  1. The -i and -b options do not check if the directory name has been supplied. The shift command fails, but the script continues.
  1. shellcheck
  2. create_bin_symlinks() does not catch the mkdir error
  3. The install dir should be verified that it is absolute pathname, otherwise create_bin_symlinks() and create_current_symlinks() will generate bad symlinks.
  • Could you help us understand the context where these issues were discovered and know how these are used? For the shellcheck, we cannot guarantee this line isn't used elsewhere.

adev-code avatar Dec 04 '25 17:12 adev-code

Hi, Thanks for looking at the issue.

This concerns the install shell script in https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip

The script could do with some error checking, as can be seen from the examples above.

The shellcheck warning points to a redundant assignment on line 81, below are lines 80-81:

INSTALL_DIR="$ROOT_INSTALL_DIR/v2/$AWS_EXE_VERSION"
INSTALL_DIR="$INSTALL_DIR"

Thanks

fredyouhanaie avatar Dec 04 '25 19:12 fredyouhanaie