haiku: Improve capabilities. (public keys, halt)

This commit is contained in:
Alexander von Gluck IV 2017-12-05 18:19:15 -06:00
parent a22b13034d
commit 263a2c4d9b
4 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,16 @@
module VagrantPlugins
module GuestHaiku
module Cap
class Halt
def self.halt(machine)
begin
machine.communicate.execute("/bin/shutdown")
rescue IOError, Vagrant::Errors::SSHDisconnected
# Ignore, this probably means connection closed because it
# shut down.
end
end
end
end
end
end

View File

@ -0,0 +1,21 @@
require "vagrant/util/shell_quote"
module VagrantPlugins
module GuestHaiku
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 $(finddir B_USER_SETTINGS_DIRECTORY)/ssh")
comm.execute("chmod 0700 $(finddir B_USER_SETTINGS_DIRECTORY)/ssh")
comm.execute("printf '#{contents}\\n' >> $(finddir B_USER_SETTINGS_DIRECTORY)/ssh/authorized_keys")
comm.execute("chmod 0600 $(finddir B_USER_SETTINGS_DIRECTORY)/ssh/authorized_keys")
end
end
end
end
end
end

View File

@ -0,0 +1,21 @@
require "vagrant/util/shell_quote"
module VagrantPlugins
module GuestHaiku
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 $(finddir B_USER_SETTINGS_DIRECTORY)/ssh/authorized_keys")
comm.execute(
"sed -i '/^.*#{contents}.*$/d' $(finddir B_USER_SETTINGS_DIRECTORY)/ssh/authorized_keys")
end
end
end
end
end
end
end

View File

@ -11,10 +11,25 @@ module VagrantPlugins
Guest Guest
end end
guest_capability(:haiku, :halt) do
require_relative "cap/halt"
Cap::Halt
end
guest_capability(:haiku, :change_host_name) do guest_capability(:haiku, :change_host_name) do
require_relative "cap/change_host_name" require_relative "cap/change_host_name"
Cap::ChangeHostName Cap::ChangeHostName
end end
guest_capability(:haiku, :insert_public_key) do
require_relative "cap/insert_public_key"
Cap::InsertPublicKey
end
guest_capability(:haiku, :remove_public_key) do
require_relative "cap/remove_public_key"
Cap::RemovePublicKey
end
end end
end end
end end