From ebb85b57fdaf5885e411819442f82e36ab209c78 Mon Sep 17 00:00:00 2001 From: Evan Borgstrom Date: Thu, 17 Oct 2013 22:40:21 -0400 Subject: [PATCH] Allow owner & group to be supplied as an Integer and skip lookup --- .../cap/mount_virtualbox_shared_folder.rb | 24 ++++++++++++++----- .../cap/mount_virtualbox_shared_folder.rb | 20 ++++++++++++---- .../cap/mount_virtualbox_shared_folder.rb | 24 +++++++++++++------ 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb index c22dc7a8d..c308ef84e 100644 --- a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb @@ -8,13 +8,27 @@ module VagrantPlugins mount_commands = [] + if options[:owner].is_a? Integer + mount_uid = options[:owner] + else + mount_uid = "`id -u #{options[:owner]}`" + end + + if options[:group].is_a? Integer + mount_gid = options[:group] + mount_gid_old = options[:group] + else + mount_gid = "`getent group #{options[:group]} | cut -d: -f3`" + mount_gid_old = "`id -g #{options[:group]}`" + end + # 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 = "-o uid=#{mount_uid},gid=#{mount_gid}" 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 = "-o uid=#{mount_uid},gid=#{mount_gid_old}" mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options] mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}" @@ -50,10 +64,8 @@ module VagrantPlugins # Chown the directory to the proper user 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}" + chown_commands << "chown #{mount_uid}:#{mount_gid} #{expanded_guest_path}" + chown_commands << "chown #{mount_uid}:#{mount_gid_old} #{expanded_guest_path}" exit_status = machine.communicate.sudo(chown_commands[0], error_check: false) return if exit_status == 0 diff --git a/plugins/guests/solaris/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/solaris/cap/mount_virtualbox_shared_folder.rb index 6ddf9d180..9c7369861 100644 --- a/plugins/guests/solaris/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/solaris/cap/mount_virtualbox_shared_folder.rb @@ -10,12 +10,22 @@ module VagrantPlugins # Create the shared folder machine.communicate.execute("#{machine.config.solaris.suexec_cmd} mkdir -p #{guestpath}") - # We have to use this `id` command instead of `/usr/bin/id` since this - # one accepts the "-u" and "-g" flags. - id_cmd = "/usr/xpg4/bin/id" + if owner.is_a? Integer + mount_uid = owner + else + # We have to use this `id` command instead of `/usr/bin/id` since this + # one accepts the "-u" and "-g" flags. + mount_uid = "`/usr/xpg4/bin/id -u #{owner}`" + end + + if group.is_a? Integer + mount_gid = group + else + mount_gid = "`/usr/xpg4/bin/id -g #{group}`" + end # Mount the folder with the proper owner/group - mount_options = "-o uid=`#{id_cmd} -u #{owner}`,gid=`#{id_cmd} -g #{group}`" + mount_options = "-o uid=#{mount_uid},gid=#{mount_gid}" if options[:mount_options] mount_options += ",#{options[:mount_options].join(",")}" end @@ -23,7 +33,7 @@ module VagrantPlugins machine.communicate.execute("#{machine.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}") # chown the folder to the proper owner/group - machine.communicate.execute("#{machine.config.solaris.suexec_cmd} chown `#{id_cmd} -u #{owner}`:`#{id_cmd} -g #{group}` #{guestpath}") + machine.communicate.execute("#{machine.config.solaris.suexec_cmd} chown #{mount_uid}:#{mount_gid} #{guestpath}") end end end diff --git a/plugins/guests/solaris11/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/solaris11/cap/mount_virtualbox_shared_folder.rb index 543350d17..cf624a0f9 100644 --- a/plugins/guests/solaris11/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/solaris11/cap/mount_virtualbox_shared_folder.rb @@ -12,22 +12,32 @@ module VagrantPlugins group = options[:group] # Create the shared folder - machine.communicate.execute("#{machine.config.solaris11.suexec_cmd} mkdir -p #{guestpath}") + machine.communicate.execute("#{machine.config.solaris.suexec_cmd} mkdir -p #{guestpath}") - # We have to use this `id` command instead of `/usr/bin/id` since this - # one accepts the "-u" and "-g" flags. - id_cmd = "/usr/xpg4/bin/id" + if owner.is_a? Integer + mount_uid = owner + else + # We have to use this `id` command instead of `/usr/bin/id` since this + # one accepts the "-u" and "-g" flags. + mount_uid = "`/usr/xpg4/bin/id -u #{owner}`" + end + + if group.is_a? Integer + mount_gid = group + else + mount_gid = "`/usr/xpg4/bin/id -g #{group}`" + end # Mount the folder with the proper owner/group - mount_options = "-o uid=`#{id_cmd} -u #{owner}`,gid=`#{id_cmd} -g #{group}`" + mount_options = "-o uid=#{mount_uid},gid=#{mount_gid}" if options[:mount_options] mount_options += ",#{options[:mount_options].join(",")}" end - machine.communicate.execute("#{machine.config.solaris11.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}") + machine.communicate.execute("#{machine.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}") # chown the folder to the proper owner/group - machine.communicate.execute("#{machine.config.solaris11.suexec_cmd} chown `#{id_cmd} -u #{owner}`:`#{id_cmd} -g #{group}` #{guestpath}") + machine.communicate.execute("#{machine.config.solaris.suexec_cmd} chown #{mount_uid}:#{mount_gid} #{guestpath}") end end end