vaguerent/plugins/guests/smartos/cap/remove_public_key.rb
James Nugent b84acaed3c guests/smartos: Add/fix various guest capabilities
This commit adds/changes the following for SmartOS guests:

- modifies the "Halt" capability to use /usr/sbin/poweroff in preference
  to /usr/sbin/shutdown with parameters, and modifies the associated
  test.

- adds an "InsertPublicKey" capability and tests.

- adds a "RemovePublicKey" capability and tests.

With this commit applied, the vast majority of typical Vagrant workflow
is available to SmartOS global zone guests (provided NFS mounts are used
rather than VMWare shared folders).
2017-05-30 15:18:18 +01:00

26 lines
756 B
Ruby

require "vagrant/util/shell_quote"
module VagrantPlugins
module GuestSmartos
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|
comm.execute <<-EOH.sub(/^ */, '')
if test -f /usbkey/config.inc/authorized_keys ; then
sed -i '' '/^.*#{contents}.*$/d' /usbkey/config.inc/authorized_keys
fi
if test -f ~/.ssh/authorized_keys ; then
sed -i '' '/^.*#{contents}.*$/d' ~/.ssh/authorized_keys
fi
EOH
end
end
end
end
end
end