Merge pull request #2390 from borgstrom/master

core: allow owner & group to be supplied as an Integer and skip lookup
This commit is contained in:
Mitchell Hashimoto 2013-11-23 11:46:50 -08:00
commit 88425f0146
3 changed files with 48 additions and 16 deletions

View File

@ -8,13 +8,27 @@ module VagrantPlugins
mount_commands = [] 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 # 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_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}" mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}"
# Second mount command uses the old style `id -g` # 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_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}" 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 the directory to the proper user
chown_commands = [] chown_commands = []
chown_commands << "chown `id -u #{options[:owner]}`:`getent group #{options[:group]} " + chown_commands << "chown #{mount_uid}:#{mount_gid} #{expanded_guest_path}"
"| cut -d: -f3` #{expanded_guest_path}" chown_commands << "chown #{mount_uid}:#{mount_gid_old} #{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) exit_status = machine.communicate.sudo(chown_commands[0], error_check: false)
return if exit_status == 0 return if exit_status == 0

View File

@ -10,12 +10,22 @@ module VagrantPlugins
# Create the shared folder # Create the shared folder
machine.communicate.execute("#{machine.config.solaris.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 if owner.is_a? Integer
# one accepts the "-u" and "-g" flags. mount_uid = owner
id_cmd = "/usr/xpg4/bin/id" 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 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] if options[:mount_options]
mount_options += ",#{options[:mount_options].join(",")}" mount_options += ",#{options[:mount_options].join(",")}"
end end
@ -23,7 +33,7 @@ module VagrantPlugins
machine.communicate.execute("#{machine.config.solaris.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 # 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 end
end end

View File

@ -14,12 +14,22 @@ module VagrantPlugins
# Create the shared folder # Create the shared folder
machine.communicate.execute("#{machine.config.solaris11.suexec_cmd} mkdir -p #{guestpath}") machine.communicate.execute("#{machine.config.solaris11.suexec_cmd} mkdir -p #{guestpath}")
# We have to use this `id` command instead of `/usr/bin/id` since this if owner.is_a? Integer
# one accepts the "-u" and "-g" flags. mount_uid = owner
id_cmd = "/usr/xpg4/bin/id" 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 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] if options[:mount_options]
mount_options += ",#{options[:mount_options].join(",")}" mount_options += ",#{options[:mount_options].join(",")}"
end end
@ -27,7 +37,7 @@ module VagrantPlugins
machine.communicate.execute("#{machine.config.solaris11.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}") machine.communicate.execute("#{machine.config.solaris11.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}")
# chown the folder to the proper owner/group # 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.solaris11.suexec_cmd} chown #{mount_uid}:#{mount_gid} #{guestpath}")
end end
end end
end end