Skip to content

Commit 91b8ea1

Browse files
committed
Merge pull request #47 from loadsys/f/vagrant-nfs-3.0
Add script for configuring nfsexport commands in /etc/sudoers
2 parents f87959e + 2b70d4b commit 91b8ea1

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"git-submodules",
4141
"init-repo",
4242
"migrations",
43+
"nfsexports-setsudoaccess",
4344
"pear-install-deps",
4445
"pear-package-installed",
4546
"pear-package-installed-dumb",

nfsexports-setsudoaccess

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
#---------------------------------------------------------------------
4+
usage ()
5+
{
6+
cat <<EOT
7+
8+
${0##*/}
9+
Script to inject the proper command exceptions into a system's
10+
/etc/sudoers file to allow vagrant to modify /etc/exports for
11+
NFS shared folder use without prompting the user for an
12+
administrator password during \`vagrant up\`.
13+
See: https://docs.vagrantup.com/v2/synced-folders/nfs.html
14+
Has no effect if run repeatedly.
15+
16+
Usage:
17+
bin/${0##*/}
18+
19+
20+
EOT
21+
22+
exit 0
23+
}
24+
if [ "$1" = '-h' ]; then
25+
usage
26+
fi
27+
28+
# Make sure only root can run our script
29+
if [[ $EUID -ne 0 ]]; then
30+
echo "!! This script must be run using sudo." 1>&2
31+
exit 1
32+
fi
33+
34+
comment="Allow Vagrant with NFS without requiring a password"
35+
if grep -q "$comment" "/etc/sudoers"; then
36+
echo 'Vagrant permissions already present in /etc/sudoers';
37+
else
38+
echo 'Adding Vagrant permissions into /etc/sudoers';
39+
cat <<EOF >> /etc/sudoers
40+
41+
# $comment
42+
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
43+
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
44+
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
45+
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
46+
EOF
47+
fi

0 commit comments

Comments
 (0)