s.description = "Copy your configurations easily into vagrant box"
s.authors = ["Akshay Mankar"]
s.email = 'itsakshaymankar@gmail.com'
- s.files = ["lib/copy_my_conf.rb"]
+ s.files = Dir["lib/**/*.rb"]
s.homepage = 'http://github.com/akshaymankar/copy_my_conf'
end
config.vm.box = "precise64"
config.ssh.forward_agent = true
- config.vm.provision CopyMyConf do |copy_conf|
- copy_conf.ssh = true
+ config.vm.provision Vagrant::Provisioners::CopyMyConf do |copy_conf|
+ copy_conf.ssh = false
copy_conf.vim = true
- copy_conf.git = true
+ copy_conf.git = false
copy_conf.user_home = "/home/vagrant"
end
-require "copy_my_conf/config"
\ No newline at end of file
+require "copy_my_conf/config"
+require "copy_my_conf/vim"
class CopyMyConf < Base
def prepare
- prepare_vim if config.vim
- prepare_git if config.git
- prepare_ssh if config.ssh
+ @to_be_copied = []
+ config.all_true.each do |c|
+ conf = self.class.const_get(c.capitalize).new
+ @to_be_copied << conf
+ conf.prepare env[:vm].config.vm, tmp_root
+ end
end
def provision!
channel = env[:vm].channel
+ @to_be_copied.each do |conf|
+ conf.provision channel, user_home, tmp_root
+ end
provision_ssh(channel) if config.ssh
provision_vim(channel) if config.vim
provision_git(channel) if config.git
env[:vm].config.vm.share_folder("git", "#{tmp_root}/git/", "#{tmp_root}/git")
end
- def prepare_vim
- `mkdir -p #{tmp_root}/vim`
- ["~/.vimrc", "~/.vim"].each do |file|
- `cp -r #{file} #{tmp_root}/vim`
- end
- env[:vm].config.vm.share_folder("vim", "#{tmp_root}/vim/", "#{tmp_root}/vim")
- end
-
def provision_git(channel)
puts "Copying your gitconfig"
channel.execute("cp #{tmp_root}/git/.gitconfig ~/")
end
- def provision_vim(channel)
- puts "Copying your vim configuratios"
- channel.execute("rm -rf #{user_home}/.vim*")
- channel.execute("cp -r #{tmp_root}/vim/.??* ~/")
- end
-
def provision_ssh(channel)
puts "Copying your ssh keys and config"
channel.sudo("mkdir -p #{tmp_root}/cached && chown -R vagrant #{tmp_root}/cached")
--- /dev/null
+module Vagrant
+ module Provisioners
+ class CopyMyConf < Base
+ class Vim
+ def prepare vm, tmp_root
+ `mkdir -p #{tmp_root}/vim`
+ ["~/.vimrc", "~/.vim"].each do |file|
+ `cp -r #{file} #{tmp_root}/vim`
+ end
+ vm.share_folder("vim", "#{tmp_root}/vim", "#{tmp_root}/vim")
+ end
+
+ def provision channel, user_home, tmp_root
+ puts "Copying your vim configuratios"
+ channel.execute("rm -rf #{user_home}/.vim*")
+ channel.execute("cp -r #{tmp_root}/vim/.??* ~/")
+ end
+ end
+ end
+ end
+end
--- /dev/null
+require "spec_helper"
+
+module Vagrant
+ module Provisioners
+ class CopyMyConf < Base
+ describe Vim do
+ it "should copy dotfiles to temporary location in vagrant box" do
+ Vim.any_instance.stub(:`).and_return(nil)
+ vm = Object.new
+ tmp_root = "tmp_root"
+
+ vm.should_receive(:share_folder).with(anything, "#{tmp_root}/vim", "#{tmp_root}/vim")
+ vim = Vim.new
+
+ vim.prepare vm, tmp_root
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
module Vagrant
module Provisioners
describe CopyMyConf do
- xit "should prepare provisioning process" do
- copy_my_conf = CopyMyConf.new
+ before(:each) do
+ env_vm = Object.new
+ env_vm_config = Object.new
+ @mock_vm = Object.new
+ @config = CopyMyConf.config_class.new
+ @env_channel = Object.new
+
+ CopyMyConf.any_instance.stub(:env).and_return({:vm => env_vm})
+ env_vm.stub(:config).and_return(env_vm_config)
+ env_vm.stub(:channel).and_return(@env_channel)
+ env_vm_config.stub(:vm).and_return(@mock_vm)
+ CopyMyConf.any_instance.stub(:config).and_return(@config)
+ end
+
+ it "should prepare provisioning process" do
+ @config.should_receive(:all_true).and_return([:vim])
+ CopyMyConf::Vim.any_instance.should_receive(:prepare).with(@mock_vm, anything)
- config = CopyMyConf.config_class.new
- config.vim = true
+ CopyMyConf.new.prepare
+ end
+
+ it "should provision the vm" do
+ @config.stub(:all_true).and_return([:vim])
+ copy_my_conf = CopyMyConf.new
- copy_my_conf.stub(:config).and_return(config)
+ CopyMyConf::Vim.any_instance.stub(:prepare)
+ copy_my_conf.prepare
- CopyMyConf::Vim.any_instance.should_receive(:prepare)
+ CopyMyConf::Vim.any_instance.should_receive(:provision).with(@env_channel, anything, anything)
+ copy_my_conf.provision!
end
end
end