Skip to content

Instantly share code, notes, and snippets.

@haukeadler
Forked from GUI/install_vagrant_sudoers.sh
Last active August 29, 2015 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haukeadler/6bba90d453d940a06be9 to your computer and use it in GitHub Desktop.
Save haukeadler/6bba90d453d940a06be9 to your computer and use it in GitHub Desktop.
Allow Vagrant sudo-access without password for NFS-setup (for OS X Yosemite 10.10.4, requires Vagrant 1.7.3+)
#!/bin/bash
# Script for placing sudoers.d files with syntax-checking
# Making a temporary file to contain the sudoers-changes to be pre-checked
TMP=$(mktemp -t vagrant_sudoers)
cat /etc/sudoers > $TMP
cat >> $TMP <<EOF
# Allow passwordless startup of Vagrant when using NFS.
# see http://docs.vagrantup.com/v2/synced-folders/nfs.html
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
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