From b9801f44a0520d37daf1648865af72d084a5c226 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 16 Sep 2013 20:51:09 -0700 Subject: [PATCH] guests/linux: try `id -g` to determine group as well [GH-2197] --- CHANGELOG.md | 2 ++ .../cap/mount_virtualbox_shared_folder.rb | 36 +++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e79cdb7ec..c28b7acc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb index 25119571a..5532c8799 100644 --- a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb @@ -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,8 +26,13 @@ module VagrantPlugins attempts = 0 while true success = true - machine.communicate.sudo(mount_command) do |type, data| - success = false if type == :stderr && data =~ /No such device/i + + 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 @@ -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