Moved code to prepare and provision git and ssh into seperate classes
[vagrant-dotfiles.git] / lib / copy_my_conf / ssh.rb
diff --git a/lib/copy_my_conf/ssh.rb b/lib/copy_my_conf/ssh.rb
new file mode 100644 (file)
index 0000000..bbe722d
--- /dev/null
@@ -0,0 +1,20 @@
+module Vagrant
+  module Provisioners
+    class CopyMyConf < Base
+      class Ssh
+        def prepare vm, tmp_root
+          vm.share_folder("ssh", "#{tmp_root}/ssh", "~/.ssh")
+        end
+
+        def provision channel, user_home, tmp_root
+          puts "Copying your ssh keys and config"
+          channel.sudo("mkdir -p #{tmp_root}/cached && chown -R vagrant #{tmp_root}/cached")
+          channel.execute("[[ -f #{user_home}/.ssh/authorized_keys ]] && mv #{user_home}/.ssh/authorized_keys #{tmp_root}/cached")
+          channel.execute("cp #{tmp_root}/ssh/* #{user_home}/.ssh")
+          channel.execute("cat #{tmp_root}/cached/authorized_keys >> #{user_home}/.ssh/authorized_keys") # So that `vagrant ssh` doesn't ask for password
+        end
+
+      end
+    end
+  end
+end