Allow owner & group to be supplied as an Integer and skip lookup

This commit is contained in:
Evan Borgstrom 2013-10-17 22:40:21 -04:00
parent 673a06b54d
commit ebb85b57fd
3 changed files with 50 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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