install script multiple issues
Describe the bug
Hi
I noticed multiple tiny issues in the install script, while looking into the first one in the list below:
- The
-iand-boptions do not check if the directory name has been supplied. Theshiftcommand fails, but the script continues. shellcheckcomplains about a self assigned variable:INSTALL_DIR="$INSTALL_DIR"create_bin_symlinks()does not catch themkdirerror- The install dir should be verified that it is absolute pathname, otherwise
create_bin_symlinks()andcreate_current_symlinks()will generate bad symlinks.
Expected Behavior
- The script should exit if argument is missing
- The assignment is superfluous, does not affect the behaviour
- The script should exit, if
mkdirfails - The binary symlinks should be valid
Current Behavior
- There is an error message, but the script continues
- Does not affect the behaviour
- An error is reported, but the script continues
- 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:
- run install with
-ior-b, but no arg
./install -b`
./install: line 64: shift: shift count out of range
...
- run
shellcheckagainst 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...
- 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.
- 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
- Check for
$#when parsing-iand-b - Remove the superfluous line
- Append
|| exit 1to themkdirline - Check that the value supplied in
-iis 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
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.
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.
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!
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.
Hello, re-looking at the issue,
- The -i and -b options do not check if the directory name has been supplied. The shift command fails, but the script continues.
- As per the installation documentation, it indicates that users should specify installation locations.
- shellcheck
- create_bin_symlinks() does not catch the mkdir error
- 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.
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