Skip to content

Instantly share code, notes, and snippets.

@EHLOVader
Forked from joemaller/install_vagrant_sudoers.sh
Last active August 29, 2015 14:03
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 EHLOVader/254e3ab580a1335d0a8d to your computer and use it in GitHub Desktop.
Save EHLOVader/254e3ab580a1335d0a8d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Add Vagrant's NFS setup commands to sudoers, for `vagrant up` without a password
# Updated to work with Vagrant 1.6.x @see https://github.com/mitchellh/vagrant/pull/3638
# 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 = /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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment