guests/linux: try `id -g` to determine group as well [GH-2197]
This commit is contained in:
parent
42df2ed2c9
commit
b9801f44a0
|
@ -17,6 +17,8 @@ BUG FIXES:
|
|||
- core: Increase timeout for individual SSH connection to 60 seconds. [GH-2163]
|
||||
- core: Call realpath after creating directory so NFS directory creation
|
||||
works. [GH-2196]
|
||||
- guests/linux: Try `id -g` in addition to `getent` for mounting
|
||||
VirtualBox shared folders [GH-2197]
|
||||
- hosts/arch: NFS exporting works properly, no exceptions. [GH-2161]
|
||||
- hosts/bsd: Use only `sudo` for writing NFS exports. This lets NFS
|
||||
exports work if you have sudo privs but not `su`. [GH-2191]
|
||||
|
|
|
@ -6,13 +6,17 @@ module VagrantPlugins
|
|||
expanded_guest_path = machine.guest.capability(
|
||||
:shell_expand_guest_path, guestpath)
|
||||
|
||||
# Determine the permission string to attach to the mount command
|
||||
mount_options = "-o uid=`id -u #{options[:owner]}`,gid=`getent group #{options[:group]} | cut -d: -f3`"
|
||||
if options[:mount_options]
|
||||
mount_options += ",#{options[:mount_options].join(",")}"
|
||||
end
|
||||
mount_commands = []
|
||||
|
||||
mount_command = "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}"
|
||||
# First mount command uses getent to get the group
|
||||
mount_options = "-o uid=`id -u #{options[:owner]}`,gid=`getent group #{options[:group]} | cut -d: -f3`"
|
||||
mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
|
||||
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}"
|
||||
|
||||
# Second mount command uses the old style `id -g`
|
||||
mount_options = "-o uid=`id -u #{options[:owner]}`,gid=`id -g #{options[:group]}`"
|
||||
mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
|
||||
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}"
|
||||
|
||||
# Create the guest path if it doesn't exist
|
||||
machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
|
||||
|
@ -22,11 +26,16 @@ module VagrantPlugins
|
|||
attempts = 0
|
||||
while true
|
||||
success = true
|
||||
machine.communicate.sudo(mount_command) do |type, data|
|
||||
|
||||
mount_commands.each do |command|
|
||||
machine.communicate.sudo(command) do |type, data|
|
||||
success = false if type == :stderr && data =~ /No such device/i
|
||||
end
|
||||
|
||||
break if success
|
||||
end
|
||||
|
||||
break if success
|
||||
|
||||
attempts += 1
|
||||
raise Vagrant::Errors::LinuxMountFailed, :command => mount_command
|
||||
|
@ -34,8 +43,15 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
# Chown the directory to the proper user
|
||||
machine.communicate.sudo(
|
||||
"chown `id -u #{options[:owner]}`:`getent group #{options[:group]} | cut -d: -f3` #{expanded_guest_path}")
|
||||
chown_commands = []
|
||||
chown_commands << "chown `id -u #{options[:owner]}`:`getent group #{options[:group]} " +
|
||||
"| cut -d: -f3` #{expanded_guest_path}"
|
||||
chown_commands << "chown `id -u #{options[:owner]}`:`id -g #{options[:group]} " +
|
||||
"#{expanded_guest_path}"
|
||||
|
||||
exit_status = machine.communicate.sudo(chown_commands[0], error_check: false)
|
||||
return if exit_status == 0
|
||||
machine.communicate.sudo(chown_commands[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue