From 75de0e3dd763d829272c2f643d6d415ef1bc6906 Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Tue, 13 Jan 2015 21:45:06 -0500 Subject: [PATCH] Add insert/remove public key guest capability for solaris (identical to linux) --- .../guests/solaris/cap/insert_public_key.rb | 22 +++++++++++++++++++ .../guests/solaris/cap/remove_public_key.rb | 22 +++++++++++++++++++ plugins/guests/solaris/plugin.rb | 10 +++++++++ 3 files changed, 54 insertions(+) create mode 100644 plugins/guests/solaris/cap/insert_public_key.rb create mode 100644 plugins/guests/solaris/cap/remove_public_key.rb diff --git a/plugins/guests/solaris/cap/insert_public_key.rb b/plugins/guests/solaris/cap/insert_public_key.rb new file mode 100644 index 000000000..b0b13d041 --- /dev/null +++ b/plugins/guests/solaris/cap/insert_public_key.rb @@ -0,0 +1,22 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestSolaris + module Cap + class InsertPublicKey + def self.insert_public_key(machine, contents) + # TODO: Code is identical to linux/cap/insert_public_key + 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/solaris/cap/remove_public_key.rb b/plugins/guests/solaris/cap/remove_public_key.rb new file mode 100644 index 000000000..170d63870 --- /dev/null +++ b/plugins/guests/solaris/cap/remove_public_key.rb @@ -0,0 +1,22 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestSolaris + module Cap + class RemovePublicKey + def self.remove_public_key(machine, contents) + # TODO: code is identical to linux/cap/remove_public_key + 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/solaris/plugin.rb b/plugins/guests/solaris/plugin.rb index 31988453c..9f2b315ce 100644 --- a/plugins/guests/solaris/plugin.rb +++ b/plugins/guests/solaris/plugin.rb @@ -26,6 +26,11 @@ module VagrantPlugins Cap::ConfigureNetworks end + guest_capability("solaris", "insert_public_key") do + require_relative "cap/insert_public_key" + Cap::InsertPublicKey + end + guest_capability("solaris", "halt") do require_relative "cap/halt" Cap::Halt @@ -36,6 +41,11 @@ module VagrantPlugins Cap::MountVirtualBoxSharedFolder end + guest_capability("solaris", "remove_public_key") do + require_relative "cap/remove_public_key" + Cap::RemovePublicKey + end + guest_capability("solaris", "rsync_installed") do require_relative "cap/rsync" Cap::RSync