Sha256: 67111320d96bf518e4aed374212f52672bd70ae1ab20dcb905ff0abfe757d704

Contents?: true

Size: 666 Bytes

Versions: 3

Compression:

Stored size: 666 Bytes

Contents

require "vagrant/util/shell_quote"

module VagrantPlugins
  module GuestMSYS2
    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(<<SCRIPT)
sed -e '/^.*#{contents}.*$/d' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.new
mv ~/.ssh/authorized_keys.new ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
SCRIPT
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-guest-msys2-0.0.6 lib/vagrant-guest-msys2/cap/remove_public_key.rb
vagrant-guest-msys2-0.0.5 lib/vagrant-guest-msys2/cap/remove_public_key.rb
vagrant-guest-msys2-0.0.4 lib/vagrant-guest-msys2/cap/remove_public_key.rb