Skip to content

Instantly share code, notes, and snippets.

@JBKahn
Created July 28, 2014 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JBKahn/e0f0e6afb8abeb2e6d20 to your computer and use it in GitHub Desktop.
Save JBKahn/e0f0e6afb8abeb2e6d20 to your computer and use it in GitHub Desktop.
Add Vagrant NFS mount to sudoers file
#!/bin/bash
# Script for placing sudoers.d files with syntax-checking
# slightly modified version of https://gist.github.com/GUI/2864683
# Making a temporary file to contain the sudoers-changes to be pre-checked
TMP=$(mktemp -t)
cat /etc/sudoers > $TMP
cat >> $TMP <<EOF
# Allow passwordless startup of Vagrant when using NFS.
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/su root -c echo '*' >> /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -e /*/ d -ibak /etc/exports
%staff ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
EOF
# Check if the changes we want are OK
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment