-
-
Save joemaller/6764700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add Vagrant's NFS setup commands to sudoers, for `vagrant up` without a password | |
# Updated to work with Vagrant 1.3.x | |
# Stage updated sudoers in a temporary file for syntax checking | |
TMP=$(mktemp -t vagrant_sudoers) | |
cat /etc/sudoers > $TMP | |
cat >> $TMP <<EOF | |
# Allow passwordless startup of Vagrant when using NFS. | |
# https://gist.github.com/joemaller/6764700 | |
Cmnd_Alias VAGRANT_EXPORTS_ADD = /bin/bash -c echo '*' >> /etc/exports | |
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart | |
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports | |
%staff ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE | |
EOF | |
# Check syntax and overwrite sudoers if clean | |
visudo -c -f $TMP | |
if [ $? -eq 0 ]; then | |
echo "Adding vagrant commands to sudoers" | |
cat $TMP > /etc/sudoers | |
else | |
echo "sudoers syntax wasn't valid. Aborting!" | |
fi | |
rm -f $TMP |
Finally Vagrant 1.6 has this fixed with a "stable" hack to visudo
:
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Too bad GitHib doesn't have notification for mentions in Gist comments. I didn't know there're answers here till today.
@karlingen yes I'm using zsh
@justinatcamfil That's probably the reason. I ended up leave it alone as I rarely destroy the box. When I don't need it I just need to
vagrant suspend
and it's all good. Memory released.