From a9337aba22814ce87f2350ab664c577e25115b8b Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Tue, 4 Feb 2014 01:09:29 -0300 Subject: [PATCH] guests/{free,net}bsd: add `insert_public_key` capability Copy the cap to missing *bsd variants. --- .../guests/freebsd/cap/insert_public_key.rb | 21 +++++++++++++++++++ plugins/guests/freebsd/plugin.rb | 5 +++++ .../guests/netbsd/cap/insert_public_key.rb | 21 +++++++++++++++++++ plugins/guests/netbsd/plugin.rb | 5 +++++ 4 files changed, 52 insertions(+) create mode 100644 plugins/guests/freebsd/cap/insert_public_key.rb create mode 100644 plugins/guests/netbsd/cap/insert_public_key.rb diff --git a/plugins/guests/freebsd/cap/insert_public_key.rb b/plugins/guests/freebsd/cap/insert_public_key.rb new file mode 100644 index 000000000..5fc414d39 --- /dev/null +++ b/plugins/guests/freebsd/cap/insert_public_key.rb @@ -0,0 +1,21 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestFreeBSD + module Cap + class InsertPublicKey + def self.insert_public_key(machine, contents) + contents = Vagrant::Util::ShellQuote.escape(contents, "'") + contents = contents.gsub("\n", "\\n") + + machine.communicate.tap do |comm| + comm.execute("mkdir -p ~/.ssh", shell: "sh") + comm.execute("chmod 0700 ~/.ssh", shell: "sh") + comm.execute("printf '#{contents}' >> ~/.ssh/authorized_keys", shell: "sh") + comm.execute("chmod 0600 ~/.ssh/authorized_keys", shell: "sh") + end + end + end + end + end +end diff --git a/plugins/guests/freebsd/plugin.rb b/plugins/guests/freebsd/plugin.rb index 50f82bea2..8136adfdf 100644 --- a/plugins/guests/freebsd/plugin.rb +++ b/plugins/guests/freebsd/plugin.rb @@ -26,6 +26,11 @@ module VagrantPlugins Cap::Halt end + guest_capability("freebsd", "insert_public_key") do + require_relative "cap/insert_public_key" + Cap::InsertPublicKey + end + guest_capability("freebsd", "mount_nfs_folder") do require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder diff --git a/plugins/guests/netbsd/cap/insert_public_key.rb b/plugins/guests/netbsd/cap/insert_public_key.rb new file mode 100644 index 000000000..dadce0f56 --- /dev/null +++ b/plugins/guests/netbsd/cap/insert_public_key.rb @@ -0,0 +1,21 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestNetBSD + module Cap + class InsertPublicKey + def self.insert_public_key(machine, contents) + contents = Vagrant::Util::ShellQuote.escape(contents, "'") + contents = contents.gsub("\n", "\\n") + + machine.communicate.tap do |comm| + comm.execute("mkdir -p ~/.ssh") + comm.execute("chmod 0700 ~/.ssh") + comm.execute("printf '#{contents}' >> ~/.ssh/authorized_keys") + comm.execute("chmod 0600 ~/.ssh/authorized_keys") + end + end + end + end + end +end diff --git a/plugins/guests/netbsd/plugin.rb b/plugins/guests/netbsd/plugin.rb index 97fcf952f..ef822e4d4 100644 --- a/plugins/guests/netbsd/plugin.rb +++ b/plugins/guests/netbsd/plugin.rb @@ -26,6 +26,11 @@ module VagrantPlugins Cap::Halt end + guest_capability("netbsd", "insert_public_key") do + require_relative "cap/insert_public_key" + Cap::InsertPublicKey + end + guest_capability("netbsd", "mount_nfs_folder") do require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder