Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update install script to better support non-PATH installations #1184

Merged
merged 10 commits into from
Aug 16, 2021
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TFLint is a framework and each feature is provided by plugins, the key features
Bash script (Linux):

```console
curl https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
```

Homebrew (macOS):
Expand Down
10 changes: 6 additions & 4 deletions install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ processor=$(uname -m)

if [ "$processor" == "x86_64" ]; then
arch="amd64"
elif [ "$processor" == "arm64" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could submit this separately happy to merge it right away

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 #1185

arch="arm64"
else
arch="386"
fi
Expand Down Expand Up @@ -41,7 +43,7 @@ else
fi

echo "Downloading TFLint $version"
curl -L -o /tmp/tflint.zip "https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${os}.zip"
curl --fail --silent -L -o /tmp/tflint.zip "https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${os}.zip"
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to download tflint_${os}.zip"
Expand All @@ -68,13 +70,13 @@ else
dest="${TFLINT_INSTALL_PATH:-/usr/local/bin}/"
echo "Installing /tmp/tflint to ${dest}..."

if [[ "$(id -u)" == 0 ]]; then SUDO=""; else
if [[ "$(id -u)" == 0 ]] || [[ $TFLINT_INSTALL_NO_ROOT == 1 ]]; then SUDO=""; else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the script should just test whether it can access the directory as the non-root user and use sudo if not rather than adding an option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 👍 a80c763

SUDO="sudo";
fi


$SUDO mkdir -p "$dest"
$SUDO install -b -c -v /tmp/tflint "$dest"
$SUDO install --backup=none -c -v /tmp/tflint "$dest"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps scope creeping a but - but I suggest we change this to not create any backup, to avoid polluting the PATH. What happens now if you run the install script more than once is that you'll end up with a tflint and tflint~ (the backup) in in your install destination.

retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to install tflint"
Expand All @@ -89,4 +91,4 @@ rm -f /tmp/tflint.zip /tmp/tflint

echo -e "\n\n===================================================="
echo "Current tflint version"
tflint -v
"${dest}/tflint" -v