devopsgroup-io / vagrant-hostmanager

:pencil: A Vagrant plugin that manages hosts files within a multi-machine environment.
Mozilla Public License 2.0
1.46k stars 146 forks source link

If hosts file is writable without sudo, don't use sudo #194

Closed bendoh closed 8 years ago

bendoh commented 8 years ago

On my machine I keep my hosts file writable by wheel so that my regular user account can modify it at a whim without having to inconveniently present my password.

This plugin didn't recognize the writability of that file and thus prompted me for a password unnecessarily.

This change uses the shell to check writability of the file and uses cat to overwrite the file (so permissions stay the same) when it can, otherwise it calls sudo as before.

seth-reeser commented 8 years ago

Hi @bendoh - thank you for the pull request! Can you confirm that this will function cross *nix?

bendoh commented 8 years ago

So this is pretty cross-platform for anything POSIX, since the expression is evaluated by /bin/sh and I made sure that it worked in that context. I have not done any sort of multi-environment matrix testing, however.