warrensbox/terraform-switcher

tfswitch should not require sudo by default

Closed this issue · 7 comments

When installing tfswitch when flag --user or --system should either install it as user or as system and allow to provide path where to download it. It should never try to use /usr/local/bin when it's not a system wide installation.

Could you please elaborate on this a bit more? What is the command line you use and what its output is, what's the content of ~/.tfswitch.toml if present?

Closing as there was no feedback.

@yermulnik By default with default switches tfswitch will always ask for sudo. I am not using ~/.tfswitch.toml at all.

[jaydoubleu@fedora tmp]$ curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9272  100  9272    0     0   111k      0 --:--:-- --:--:-- --:--:--  111k
warrensbox/terraform-switcher info checking GitHub for latest tag
warrensbox/terraform-switcher info found version: 0.13.1308 for 0.13.1308/linux/amd64
install: cannot create regular file '/usr/local/bin/tfswitch': Permission denied

This is the first error I get as it is trying to self intall to /usr/local/bin while there should be no need for this to be default behaviour an require sudo

@JayDoubleu Looking at https://github.com/warrensbox/terraform-switcher/blob/master/install.sh I can see it already has an option for an alternate path for the binary installation. Is this what you're asking for?
I though would agree this might worth of a mentioning in the README.

I appreciate the a ability for it but IMO this should never be the case in the first place. It's commonly known to open source community that scripts on the web should never alter your paths or ask for higher permissions than it needs. So while the option is there I've had many of my colleagues saying to me they would rather use tfenv because they don't trust any scripts that are asking for sudo or don't execute if you don't run them with root privileges. I struggle to find justification for it being installed system wide by default

PS. The command I used to install it locally :

curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash -s -- -b  $HOME/.local/bin latest 

I think the idea that @warrensbox was relying upon back in the day was that /usr/local/bin on most of the systems already is a member of $PATH env var, while user-based locations like ~/bin, ~/.local/bin, and others are not, which means the script needs to have an additional instructions on how to add non-system-wide or custom bin path to PATH on a permanent basis (which may be error prone for newbies in NIX world), which in its turn may probably be inadvertently ignored by some of most of the users, especially within CI/CD pipelines, and hence frustration on why tfswitch command isn't found.
For most of the use cases where Homebrew is not an option (like CI/CD pipelines) or where OS-specific package managers provide outdated version of tfswitch I personally would recommend to use https://github.com/warrensbox/terraform-switcher#install-from-source — for regular users this approach has a heavy drawback as in tfswitch will never get upgraded w/o explicit user interaction.

PS. The command I used to install it locally :

That's gorgeous! This seems to be exactly what your initial request was, right? Or there's something else you're thinking of that we can amend install.sh with?
Also would you be up to create a PR to amend README with this solution so that others know how to avoid system-wide installation? We'd really appreciate this. Thank you.

I guess this solves the issue, yes. It's been a while and I managed by using this cmdlet.