#ctags
tags
+
+vagrant-up.txt
+
--- /dev/null
+build:
+ vagrant destroy -f
+ rm -rf .vagrant/plugins*
+ rm -rf *.gem
+ gem build vagrant-dotfiles.gemspec
+ vagrant plugin install --local ./vagrant-dotfiles-1.0.0.gem
+ (vagrant up --debug 2>&1 | tee vagrant-up.txt)
-# CopyMyConf
+# vagrant-dotfiles
Now you can copy your dotfiles into your vagrant box, so that you don't feel like visiting Mars whenever you are in vagrant shell.
+This project from forked from https://github.com/akshaymankar/copy_my_conf on 9/28/2018.
+
## How to Use
-It is a simple 3 step process
+It is a simple 2 step process
### Add gem in your vagrant
- $ vagrant plugin install copy_my_conf
+ $ vagrant plugin install vagrant-dotfiles
-### Add provisioner in your Vagrantfile
+### Create a ~/.vagrant/dotfiles files
-Add these lines in your vagrant file inside the `Vagrant::Config.run` block
+Each line in the file should be a dotfile in your home directory of your workstations.
- config.vm.provision :copy_my_conf do |copy_conf|
- copy_conf.git
- copy_conf.vim
- copy_conf.ssh
- end
+The plugin will copy this file into your /home/vagrant directory during the 'vagrant up' action.
Don't worry if you have any other provisioners, vagrant can work with multiple provisioners. Yay \o/
-As you might have guessed, If you make any of these false, the corresponding files won't be copied
If home directory of the user is not `/home/vagrant` then you can specify that using the `user_home` option in above code
- copy_conf.user_home = '/home/some_other_user'
+ config.vm.provision :vagrant-dotfiles do |dotfiles_config|
+ dotfiles_conf.user_home = '/home/some_other_user'
+ emd
+
+Note there are some edge cases with trying to copy your .ssh and .ssh/authorized_keys and .tmpssh* files over so the plugin doesn't clobber
+the vagrant key stored in .ssh/authorized_keys.
### Fire !
And you'll be good to go.
+## Development Notes
+
+Reminders for the occasional/accidental rubyist
+
+Rebuilding the gem: gem build vagrant-dotfiles.gemspec
+Running the tests: rspec spec
+Loading the gem to the local dev environment: vagrant plugin install --local ./vagrant-dotfiles-1.0.0.gem
+
## Feedback
This is my first gem so any kind of feedback would be appreciated.
Feel free fork, edit and send pull requests.
## Copyrights & Author
-Copyright(c) 2013 Akshay Mankar <itsakshaymankar@gmail.com>
+Copyright(c) 2018 Jude Nagurney <jude@pwan.org>
License: [MIT License](http://mit-license.org/)
--- /dev/null
+# Get rspec tests working
+## https://github.com/hashicorp/vagrant-spec
+
+# Need to loop over all VMs being upped, for when the Vagrantfile defines multiple VMs
+# 'with_target_vms(argv[0]) do |vm|` from https://github.com/clintoncwolfe/vagrant-rspec-ci/blob/master/lib/vagrant-rspec-ci/command.rb ??
--- /dev/null
+./example/Vagrantfile
\ No newline at end of file
+++ /dev/null
-Gem::Specification.new do |s|
- s.name = 'copy_my_conf'
- s.version = '0.1.1'
- s.date = '2013-07-06'
- s.summary = "Vagrant Provisioner to copy your configuration files into vagrant box"
- s.description = "Copy your configurations easily into vagrant box"
- s.authors = ["Akshay Mankar"]
- s.email = 'itsakshaymankar@gmail.com'
- s.files = Dir["lib/**/*.rb"]
- s.homepage = 'http://github.com/akshaymankar/copy_my_conf'
-end
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
- config.vm.box = "precise64"
+ config.vm.box = "ubuntu/trusty64"
- config.vm.provision :copy_my_conf do |copy_conf|
- copy_conf.vim
- copy_conf.git
- copy_conf.ssh
- copy_conf.user_home = "/home/vagrant"
+ config.vm.provision 'vagrant-dotfiles' do |dotfile_conf|
+ dotfile_conf.user_home = "/home/vagrant"
end
+
end
--- /dev/null
+.gitconfig
+.tmpssh
+.gitattributes
+.ssh/authorized_keys
+.vim
+.vimrc
+not_a_dotfile_dont_care
+subdir/also_not_a_dotfile
--- /dev/null
+
+module VagrantPlugins
+ module VagrantDotfiles
+ class Config < Vagrant.plugin("2", :config)
+ attr_accessor :user_home
+
+ def initialize
+ @user_home = UNSET_VALUE
+ end
+
+ def finalize!
+ @user_home = '/home/vagrant' if @user_home == UNSET_VALUE
+ end
+
+ end # class
+ end # module vdt
+end # module vp
+
+++ /dev/null
-module CopyMyConf
- class Plugin < Vagrant.plugin("2")
- name "copy_my_conf"
-
- config(:copy_my_conf, :provisioner) do
- require File.expand_path('../copy_my_conf/config', __FILE__)
- Config
- end
-
- provisioner :copy_my_conf do
- require File.expand_path('../copy_my_conf/provisioner', __FILE__)
- Provisioner
- end
-
- end
-end
+++ /dev/null
-require_relative "git"
-require_relative "ssh"
-require_relative "vim"
-
-module CopyMyConf
- class Config < Vagrant.plugin("2", :config)
- attr_accessor :user_home
-
- def git
- @git ||= CopyMyConf::Git.new
- end
-
- def vim
- @vim ||= CopyMyConf::Vim.new
- end
-
- def ssh
- @ssh ||=CopyMyConf::Ssh.new
- end
-
- def all_enabled_attributes
- [@ssh, @vim, @git].compact
- end
- end
-end
-
+++ /dev/null
-module CopyMyConf
- class Git
- def prepare vm, tmp_root
- `mkdir -p #{tmp_root}/git`
- `cp ~/.gitconfig #{tmp_root}/git/`
- vm.synced_folder("#{tmp_root}/git/", "#{tmp_root}/git", :id => "git")
- end
-
- def provision channel, user_home, tmp_root
- puts "Copying your gitconfig"
- channel.execute("cp #{tmp_root}/git/.gitconfig #{user_home}")
- end
- end
-end
+++ /dev/null
-module CopyMyConf
- class Provisioner < Vagrant.plugin("2", :provisioner)
-
- def configure(root_config)
- `rm -rf /tmp/copy_my_conf`
- @to_be_copied = []
- config.all_enabled_attributes.each do |conf|
- @to_be_copied << conf
- conf.prepare root_config.vm, tmp_root
- end
- end
-
- def provision
- channel = @machine.communicate
- @to_be_copied.each do |conf|
- conf.provision channel, user_home, tmp_root
- end
- end
-
- def self.config_class
- Config
- end
-
- private
-
- def tmp_root
- "/tmp/copy_my_conf"
- end
-
- def user_home
- config.user_home || "/home/vagrant"
- end
- end
-end
-
+++ /dev/null
-module CopyMyConf
- class Ssh
- def prepare vm, tmp_root
- vm.synced_folder("#{ENV['HOME']}/.ssh", "#{tmp_root}/ssh",:id => "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
+++ /dev/null
-module CopyMyConf
- 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.synced_folder("#{tmp_root}/vim", "#{tmp_root}/vim", :id => "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
--- /dev/null
+require 'pathname'
+
+CP_SSH_DIR=<<-end_cp_ssh_dir
+ mkdir -p %{user_home}/.tmpssh
+ touch %{user_home}/.tmpssh/authorized_keys;
+ cat %{user_home}/.tmpssh/authorized_keys {user_home}/.ssh/authorized_keys > %{user_home}/.tmpssh/authorized_keys;
+ cp -rf %{user_home)/.tmpssh/* %{user_home}/.ssh/;
+ rm -rf %{user_name}/.tmpssh"
+end_cp_ssh_dir
+
+module VagrantPlugins
+ module VagrantDotfiles
+ class Provisioner < Vagrant.plugin("2", :provisioner)
+
+ def mkdir_and_copy_file(filename, user_home, root_config)
+ dirname = File.dirname(filename)
+ if dirname != "." then
+ shell_cmd = "mkdir -p " + user_home + "/" + dirname
+ @machine.communicate.sudo("mkdir -p " + user.home + "/" + dirname)
+ end
+ file_source = "#{Dir.home}/" + filename
+ file_destination = user_home + "/" + filename
+ @machine.communicate.upload(file_source, file_destination)
+ end # mkdir_and_copy_file
+
+ def provision
+ root_config = @machine.config
+
+ # read ~/.vagrant/dotfiles
+ dotfiles = "#{Dir.home}/.vagrant/dotfiles"
+ tmpssh_list = []
+ if File.file?(dotfiles) then
+ File.readlines(dotfiles, chomp: true).each do |unstripped_file|
+
+ # No newlines please
+ file = unstripped_file.strip
+
+ # Copying the local .ssh directory will clobber the vagrant key in /home/vagrant/.ssh/authorized_keys
+ # Instead copy the .ssh directory to .tmpssh, and concat the authorized_keys files
+ # then copy the .tmpssh to .ssh and delete .tmpssh
+ if file == ".ssh" then
+ @machine.communicate.upload("#{Dir.home}/" + file, @config.user_home + "/.tmpssh")
+ @machine.communicate.sudo(CP_SSH_DIR % {user_home: @config.user_home})
+
+ # If just asking for the .ssh/authorized_keys file to be copied over, put it in .tmpssh alone, and send it as above
+ elsif file == ".ssh/authorized_keys" then
+ @machine.communicate.sudo("mkdir -p " + @config.user_home + "/.tmpssh")
+ @machine.communicate.upload("#{Dir.home}/.ssh/authorized_keys", @config.user_home + "/.tmpssh/authorized_keys")
+ @machine.communicate.sudo(CP_SSH_DIR % {user_home: @config.user_home})
+
+ # Oh my - what if the user actually wants to copy a .tmpssh file to the vagrant box and the .ssh special cases have
+ # already trampled on that directoy ? Push any .tmpssh files to a list that's handled after any .ssh files
+ elsif file.start_with?(".tmpssh") then
+ tmpssh_list.append(file)
+ else
+ mkdir_and_copy_file(file, @config.user_home, root_config)
+ end # if
+ end # read file
+
+ ## Handle any .tmpssh files that have have been postponed until after the .ssh files special processing
+ tmpssh_list.each do |tmpssh_filename|
+ mkdir_and_copy_file(tmpssh_filename, @config.user_home, root_config)
+ end #end tmpssh
+ else
+ @machine.ui.warning("vagrant-dotfiles: Missing ~/.vagrant/dotfiles")
+ @machine.ui.warning("Files in your home directory mentioned in ~/.vagrant/dotfiles (one per line) will be copied to /home/vagrant on your vagrant box.")
+ @to_be_copied = []
+ end #if
+ end # configure
+
+ end # class
+ end # module vdf
+end # module vp
--- /dev/null
+module VagrantPlugins
+ module VagrantDotfiles
+ class Plugin < Vagrant.plugin("2")
+ name "vagrant-dotfiles"
+ description <<-DESC
+ Provide support for copying home directory files mentioned in ~/.vagrant/dotfiles
+ to the /vagrant directory on the vagrant box.
+ DESC
+
+ config('vagrant-dotfiles', :provisioner) do
+ require File.expand_path("../config", __FILE__)
+ Config
+ end
+
+ provisioner('vagrant-dotfiles') do
+ require File.expand_path("../provisioner", __FILE__)
+ Provisioner
+ end
+ end
+ end
+end
+++ /dev/null
-require "spec_helper"
-module Vagrant::Provisioners
- class CopyMyConf < Base
- describe Config do
- it "should list all the true attributes" do
- config = Config.new
-
- config.vim
- config.ssh
-
- all_enabled_attributes = config.all_enabled_attributes
- all_enabled_attributes.map(&:class) =~ [Vim, Ssh]
- 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
+++ /dev/null
-require "spec_helper"
-
-module Vagrant
- module Provisioners
- describe CopyMyConf do
- 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_enabled_attributes).and_return([CopyMyConf::Vim.new])
- CopyMyConf::Vim.any_instance.should_receive(:prepare).with(@mock_vm, anything)
-
- CopyMyConf.new.prepare
- end
-
- it "should provision the vm" do
- @config.stub(:all_enabled_attributes).and_return([CopyMyConf::Vim.new])
- copy_my_conf = CopyMyConf.new
-
- CopyMyConf::Vim.any_instance.stub(:prepare)
- copy_my_conf.prepare
-
- CopyMyConf::Vim.any_instance.should_receive(:provision).with(@env_channel, anything, anything)
- copy_my_conf.provision!
- end
- end
- end
-end
require "fixtures"
$:<<File.dirname(__FILE__)+"/../lib"
-require "copy_my_conf"
\ No newline at end of file
+require "vagrant-dotfiles"
--- /dev/null
+require "spec_helper"
+
+module Vagrant
+ module Provisioners
+ describe VagrantDotfiles do
+ before(:each) do
+ env_vm = Object.new
+ env_vm_config = Object.new
+ @mock_vm = Object.new
+ @config = VagrantDotfiles.config_class.new
+ @env_channel = Object.new
+
+ VagrantDotfiles.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)
+ VagrantDotfiles.any_instance.stub(:config).and_return(@config)
+ end
+
+ it "should prepare provisioning process" do
+ @config.should_receive(:all_enabled_attributes).and_return([VagrantDotfiles::Vim.new])
+ VagrantDotfiles::Vim.any_instance.should_receive(:prepare).with(@mock_vm, anything)
+
+ VagrantDotfiles.new.prepare
+ end
+
+ it "should provision the vm" do
+ @config.stub(:all_enabled_attributes).and_return([VagrantDotfiles::Vim.new])
+ vagrant_dotfiles = VagrantDotfiles.new
+
+ VagrantDotfiles::Vim.any_instance.stub(:prepare)
+ vagrant_dotfiles.prepare
+
+ VagrantDotfiles::Vim.any_instance.should_receive(:provision).with(@env_channel, anything, anything)
+ vagrant_dotfiles.provision!
+ end
+ end
+ end
+end
--- /dev/null
+require "spec_helper"
+module Vagrant::Provisioners
+ class VagrantDotfiles < Base
+ describe Config do
+ it "should list all the true attributes" do
+ config = Config.new
+
+ end
+ end
+ end
+end
+
--- /dev/null
+Gem::Specification.new do |s|
+ s.name = 'vagrant-dotfiles'
+ s.version = '1.0.0'
+ s.date = '2018-09-28'
+ s.summary = "Vagrant Provisioner to copy your configuration files into vagrant box"
+ s.description = "Copy your configurations easily into vagrant box"
+ s.authors = ["Jude Nagurney"]
+ s.email = 'juden@pwan.org'
+ s.files = Dir["lib/**/*.rb"]
+ s.homepage = 'http://github.com/jude/vagrant-dotfiles'
+ s.license = 'MIT'
+end