copy_my_conf 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/copy_my_conf.rb +73 -0
  2. metadata +45 -0
@@ -0,0 +1,73 @@
1
+ class CopyMyConf < Vagrant::Provisioners::Base
2
+
3
+ def prepare
4
+ prepare_vim if config.vim
5
+ prepare_git if config.git
6
+ prepare_ssh if config.ssh
7
+ end
8
+
9
+ def provision!
10
+ channel = env[:vm].channel
11
+ provision_ssh(channel) if config.ssh
12
+ provision_vim(channel) if config.vim
13
+ provision_git(channel) if config.git
14
+ end
15
+
16
+ def self.config_class
17
+ Config
18
+ end
19
+
20
+ class Config < Vagrant::Config::Base
21
+ attr_accessor :ssh
22
+ attr_accessor :vim
23
+ attr_accessor :git
24
+ attr_accessor :user_home
25
+ end
26
+
27
+ private
28
+
29
+ def tmp_root
30
+ "/tmp/copy_my_conf"
31
+ end
32
+
33
+ def prepare_ssh
34
+ env[:vm].config.vm.share_folder("ssh", "#{tmp_root}/ssh", "~/.ssh")
35
+ end
36
+
37
+ def prepare_git
38
+ `mkdir -p #{tmp_root}/git`
39
+ `cp ~/.gitconfig #{tmp_root}/git/`
40
+ env[:vm].config.vm.share_folder("git", "#{tmp_root}/git/", "#{tmp_root}/git")
41
+ end
42
+
43
+ def prepare_vim
44
+ `mkdir -p #{tmp_root}/vim`
45
+ ["~/.vimrc", "~/.vim"].each do |file|
46
+ `cp -r #{file} #{tmp_root}/vim`
47
+ end
48
+ env[:vm].config.vm.share_folder("vim", "#{tmp_root}/vim/", "#{tmp_root}/vim")
49
+ end
50
+
51
+ def provision_git(channel)
52
+ puts "Copying your gitconfig"
53
+ channel.execute("cp #{tmp_root}/git/.gitconfig ~/")
54
+ end
55
+
56
+ def provision_vim(channel)
57
+ puts "Copying your vim configuratios"
58
+ channel.execute("rm -rf #{user_home}/.vim*")
59
+ channel.execute("cp -r #{tmp_root}/vim/.??* ~/")
60
+ end
61
+
62
+ def provision_ssh(channel)
63
+ puts "Copying your ssh keys and config"
64
+ channel.sudo("mkdir -p #{tmp_root}/cached && chown -R vagrant #{tmp_root}/cached")
65
+ channel.execute("[[ -f #{user_home}/.ssh/authorized_keys ]] && mv #{user_home}/.ssh/authorized_keys #{tmp_root}/cached")
66
+ channel.execute("cp #{tmp_root}/ssh/* #{user_home}/.ssh")
67
+ channel.execute("cat #{tmp_root}/cached/authorized_keys >> #{user_home}/.ssh/authorized_keys") # So that `vagrant ssh` doesn't ask for password
68
+ end
69
+
70
+ def user_home
71
+ config.user_home || "/home/vagrant"
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: copy_my_conf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Akshay Mankar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-08 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Copy your configurations easily into vagrant box
15
+ email: itsakshaymankar@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/copy_my_conf.rb
21
+ homepage: http://github.com/akshaymankar/copy_my_conf
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.24
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Vagrant Provisioner to copy your configuration files into vagrant box
45
+ test_files: []