-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnfsexports-setsudoaccess
More file actions
executable file
·47 lines (38 loc) · 1.27 KB
/
nfsexports-setsudoaccess
File metadata and controls
executable file
·47 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
#---------------------------------------------------------------------
usage ()
{
cat <<EOT
${0##*/}
Script to inject the proper command exceptions into a system's
/etc/sudoers file to allow vagrant to modify /etc/exports for
NFS shared folder use without prompting the user for an
administrator password during \`vagrant up\`.
See: https://docs.vagrantup.com/v2/synced-folders/nfs.html
Has no effect if run repeatedly.
Usage:
bin/${0##*/}
EOT
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
}
if [ "$1" = '-h' ]; then
usage
fi
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "!! This script must be run using sudo." 1>&2
exit 1
fi
comment="Allow Vagrant with NFS without requiring a password"
if grep -q "$comment" "/etc/sudoers"; then
echo 'Vagrant permissions already present in /etc/sudoers';
else
echo 'Adding Vagrant permissions into /etc/sudoers';
cat <<EOF >> /etc/sudoers
# $comment
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
fi