diff --git a/plugins/guests/darwin/cap/insert_public_key.rb b/plugins/guests/darwin/cap/insert_public_key.rb new file mode 100644 index 000000000..59e5dd58c --- /dev/null +++ b/plugins/guests/darwin/cap/insert_public_key.rb @@ -0,0 +1,21 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestDarwin + module Cap + class InsertPublicKey + def self.insert_public_key(machine, contents) + contents = contents.chomp + contents = Vagrant::Util::ShellQuote.escape(contents, "'") + + machine.communicate.tap do |comm| + comm.execute("mkdir -p ~/.ssh") + comm.execute("chmod 0700 ~/.ssh") + comm.execute("printf '#{contents}\\n' >> ~/.ssh/authorized_keys") + comm.execute("chmod 0600 ~/.ssh/authorized_keys") + end + end + end + end + end +end diff --git a/plugins/guests/darwin/cap/remove_public_key.rb b/plugins/guests/darwin/cap/remove_public_key.rb new file mode 100644 index 000000000..1e0fe415a --- /dev/null +++ b/plugins/guests/darwin/cap/remove_public_key.rb @@ -0,0 +1,21 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestDarwin + module Cap + class RemovePublicKey + def self.remove_public_key(machine, contents) + contents = contents.chomp + contents = Vagrant::Util::ShellQuote.escape(contents, "'") + + machine.communicate.tap do |comm| + if comm.test("test -f ~/.ssh/authorized_keys") + comm.execute( + "sed -i '' '/^.*#{contents}.*$/d' ~/.ssh/authorized_keys") + end + end + end + end + end + end +end diff --git a/plugins/guests/darwin/plugin.rb b/plugins/guests/darwin/plugin.rb index 9736500bd..305154fde 100644 --- a/plugins/guests/darwin/plugin.rb +++ b/plugins/guests/darwin/plugin.rb @@ -26,6 +26,11 @@ module VagrantPlugins Cap::Halt end + guest_capability("darwin", "insert_public_key") do + require_relative "cap/insert_public_key" + Cap::InsertPublicKey + end + guest_capability("darwin", "mount_nfs_folder") do require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder @@ -36,6 +41,11 @@ module VagrantPlugins Cap::MountVmwareSharedFolder end + guest_capability("darwin", "remove_public_key") do + require_relative "cap/remove_public_key" + Cap::RemovePublicKey + end + guest_capability("darwin", "rsync_installed") do require_relative "cap/rsync" Cap::RSync