Skip to content

Commit 82f7ebc

Browse files
committed
Merge pull request #46 from loadsys/f/vagrant-nfs
Add script for configuring nfsexport commands in /etc/sudoers
2 parents 8a4e481 + f8c19fe commit 82f7ebc

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
@@ -47,6 +47,7 @@
4747
"git-submodules",
4848
"init-repo",
4949
"migrations",
50+
"nfsexports-setsudoaccess",
5051
"paths",
5152
"pear-install-deps",
5253
"pear-package-installed",

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)