terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.98k stars 357 forks source link

Fix linux install failing #1866

Closed ddelange closed 1 year ago

ddelange commented 1 year ago

Fixes #1865

$ TFLINT_VERSION=v0.48.0 curl -s https://raw.githubusercontent.com/ddelange/tflint/patch-1/install_linux.sh | bash
arch=amd64
os=linux_amd64
====================================================
Looking up the latest version ...
Downloading TFLint v0.48.0
Downloaded successfully
====================================================
Unpacking /tmp/tflint.UpItlTocXZ/tflint.zip ...
Archive:  /tmp/tflint.UpItlTocXZ/tflint.zip
  inflating: /tmp/tflint.UpItlTocXZ/tflint  
Installing /tmp/tflint.UpItlTocXZ/tflint to /usr/local/bin/ ...
'/tmp/tflint.UpItlTocXZ/tflint' -> '/usr/local/bin/tflint'
Cleaning temporary downloaded files directory /tmp/tflint.UpItlTocXZ ...
====================================================
Current tflint version
TFLint version 0.48.0
+ ruleset.terraform (0.4.0-bundled)
bendrucker commented 1 year ago

This creates a regression by removing a legitimate feature. It causes API requests that complete with non-2xx responses to not error. I'm going to decline this PR. You need to supply a sufficiently modern version of curl. We might accept a PR checking the cURL version to produce a clearer error but since that's not straightforward I'd have to see the code to decide on that tradeoff.

bendrucker commented 1 year ago

I guess I misread the original, sounds like you do have --fail in your cURL version. Not sure why it's not working as expected, but removing --fail as you've done here isn't right. If set -e changes the behavior over #!/bin/bash -e, that's weird but fine, happy to accept that change.

ddelange commented 1 year ago

Hi @bendrucker :wave:

This PR fixes two bugs:

I removed -x again, which just makes the script more verbose by showing which commands are run, useful for debugging (docs). Using set is preferred over flags in shebang, ~mainly due to historical reasons I think~. edit: see the next comment

How does the diff look now?

ddelange commented 1 year ago

Ah, my curl --help posted in the issue was a bit unclear. Their man is clearer about it. Looks like it's indeed safe to have it for the file transfer. I have reverted the curl commands.

So then, the reason for the script continuing despite the errors, is that the install script is piped to plain bash. So the shebang is ignored :) The shebang is to help your shell identify how to execute this file if you made the file executable and you simply try running it like $ install_script.sh instead of $ bash install_script.sh.

Final diff:

bendrucker commented 1 year ago

Ah that makes sense. PR welcome to fix that, otherwise I'll get to it eventually.