From 8a24d73e4962e98f37a2dd2c830e6b28e2ed961c Mon Sep 17 00:00:00 2001 From: Seth Reeser Date: Tue, 17 Apr 2018 17:56:00 -0400 Subject: [PATCH 1/8] Releasing v1.8.8 --- README.md | 2 +- lib/vagrant-hostmanager/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e880cf..5ef103c 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ To release a new version of vagrant-hostmanager you will need to do the followin *(only contributors of the GitHub repo and owners of the project at RubyGems will have rights to do this)* -1. First, bump the version in ~/lib/vagrant-hostmanager/version.rb: +1. First, bump, commit, and push the version in ~/lib/vagrant-hostmanager/version.rb: * Follow [Semantic Versioning](http://semver.org/). 2. Then, create a matching GitHub Release (this will also create a tag): * Preface the version number with a `v`. diff --git a/lib/vagrant-hostmanager/version.rb b/lib/vagrant-hostmanager/version.rb index 0f65654..fa6acc5 100644 --- a/lib/vagrant-hostmanager/version.rb +++ b/lib/vagrant-hostmanager/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module HostManager - VERSION = '1.8.7' + VERSION = '1.8.8' end end From 9e10d773f64408ec3f42171ccda385f0023235df Mon Sep 17 00:00:00 2001 From: John Landis Date: Thu, 17 May 2018 16:35:39 -0400 Subject: [PATCH 2/8] Move newlines out of quoted header and footer. Match carriage return along with newline in hosts file pattern. --- lib/vagrant-hostmanager/hosts_file/updater.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-hostmanager/hosts_file/updater.rb b/lib/vagrant-hostmanager/hosts_file/updater.rb index 4ba7d19..ba8f38b 100644 --- a/lib/vagrant-hostmanager/hosts_file/updater.rb +++ b/lib/vagrant-hostmanager/hosts_file/updater.rb @@ -88,8 +88,8 @@ def update_file(file, resolving_machine = nil, include_id = true, line_endings) def update_content(file_content, resolving_machine, include_id, line_endings) id = include_id ? " id: #{read_or_create_id}" : "" - header = "## vagrant-hostmanager-start#{id}\n" - footer = "## vagrant-hostmanager-end\n" + header = "## vagrant-hostmanager-start#{id}" + footer = "## vagrant-hostmanager-end" body = get_machines .map { |machine| get_hosts_file_entry(machine, resolving_machine) } .join @@ -146,12 +146,12 @@ def get_new_content(header, footer, body, old_content, line_endings) if body.empty? block = "\n" else - block = "\n\n" + header + body + footer + "\n" + block = "\n\n" + header + "\n" + body + footer + "\n\n" end # Pattern for finding existing block header_pattern = Regexp.quote(header) footer_pattern = Regexp.quote(footer) - pattern = Regexp.new("\n*#{header_pattern}.*?#{footer_pattern}\n*", Regexp::MULTILINE) + pattern = Regexp.new("[\r\n]*#{header_pattern}.*?#{footer_pattern}[\r\n]*", Regexp::MULTILINE) # Replace existing block or append content = old_content.match(pattern) ? old_content.sub(pattern, block) : old_content.rstrip + block if line_endings == "crlf" From f4cc6b8804951ee9faf4e47685852f6a868ff4c4 Mon Sep 17 00:00:00 2001 From: Seth Reeser Date: Fri, 18 May 2018 10:23:04 -0400 Subject: [PATCH 3/8] Releasing v1.8.9 --- lib/vagrant-hostmanager/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-hostmanager/version.rb b/lib/vagrant-hostmanager/version.rb index fa6acc5..ae0a99a 100644 --- a/lib/vagrant-hostmanager/version.rb +++ b/lib/vagrant-hostmanager/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module HostManager - VERSION = '1.8.8' + VERSION = '1.8.9' end end From 97216551b7cba559dd563212bb3b4e650c7b7b53 Mon Sep 17 00:00:00 2001 From: Seth Reeser Date: Fri, 18 May 2018 10:34:59 -0400 Subject: [PATCH 4/8] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5ef103c..2eb8fb1 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ Vagrant Host Manager `vagrant-hostmanager` is a Vagrant plugin that manages the `hosts` file on guest machines (and optionally the host). Its goal is to enable resolution of multi-machine environments deployed with a cloud provider where IP addresses are not known in advance. +Do you like what we do? Consider supporting us through Patreon. All of the money goes directly back into growing our collection of open source and free software. +[![Patreon](https://img.shields.io/badge/patreon-donate-red.svg)](https://www.patreon.com/devopsgroup) + Installation ------------ From 8098966a03dd5202b11eb5145d4ae067e1bd3dc1 Mon Sep 17 00:00:00 2001 From: vafschoen <52745702+vafschoen@users.noreply.github.com> Date: Thu, 15 Oct 2020 11:47:04 +0200 Subject: [PATCH 5/8] adds support for wsl2 --- lib/vagrant-hostmanager/hosts_file/updater.rb | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-hostmanager/hosts_file/updater.rb b/lib/vagrant-hostmanager/hosts_file/updater.rb index ba8f38b..2ee2ad9 100644 --- a/lib/vagrant-hostmanager/hosts_file/updater.rb +++ b/lib/vagrant-hostmanager/hosts_file/updater.rb @@ -55,13 +55,34 @@ def update_host # copy and modify hosts file on host with Vagrant-managed entries file = @global_env.tmp_path.join('hosts.local') - if WindowsSupport.windows? + if WindowsSupport.windows? || WindowsSupport.wsl? # lazily include windows Module class << self include WindowsSupport unless include? WindowsSupport end - hosts_location = "#{ENV['WINDIR']}\\System32\\drivers\\etc\\hosts" - copy_proc = Proc.new { windows_copy_file(file, hosts_location) } + windir = ENV['WINDIR'] + if WindowsSupport.wsl? + Dir.chdir('/mnt/c'){ + windir = `cmd.exe /c echo %WINDIR%`.strip + } + # convert wsl path to windows path + if file.to_s =~ /\/mnt\/[a-z]\// + win_file = file.to_s.sub(/^\/mnt\/([a-z])\//, '\1:\\').gsub('/', '\\') + else + win_file = "\\\\wsl\$\\#{ENV['WSL_DISTRO_NAME']}" + file.to_s.gsub('/', '\\') + end + win_hosts_location = "#{windir}\\System32\\drivers\\etc\\hosts" + hosts_location = "/mnt/" + windir[0].downcase + "/" + windir[3..-1] + "/System32/drivers/etc/hosts" + + # add to both, windows host and wsl machine + copy_proc = Proc.new { + wsl_copy_file(file, hosts_location, win_file, win_hosts_location) + `[ -w "/etc/hosts" ] && cat "#{file}" > "/etc/hosts" || sudo cp "#{file}" "/etc/hosts"` + } + else + hosts_location = "#{windir}\\System32\\drivers\\etc\\hosts" + copy_proc = Proc.new { windows_copy_file(file, hosts_location) } + end line_endings = "crlf" else hosts_location = '/etc/hosts' @@ -70,6 +91,9 @@ class << self end FileUtils.cp(hosts_location, file) + if WindowsSupport.wsl? + FileUtils.chmod("+w", file) + end if update_file(file, nil, true, line_endings) copy_proc.call @@ -183,6 +207,10 @@ def self.windows? RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ end + def self.wsl? + defined?(ENV['WSLENV']) + end + require 'win32ole' if windows? def windows_copy_file(source, dest) @@ -195,6 +223,16 @@ def windows_copy_file(source, dest) end end + def wsl_copy_file(source, dest, win_source, win_dest) + begin + # First, try Ruby copy + FileUtils.cp(source, dest) + rescue Errno::EACCES + # Access denied, try with elevated privileges + system('powershell.exe', 'Start-Process -Verb Runas -FilePath cmd.exe -Argumentlist "/C","copy","' + win_source + '","' + win_dest + '"') + end + end + private def windows_copy_file_elevated(source, dest) From 3c2c7840eec2588dc6818ca3aa4692b7b29707e9 Mon Sep 17 00:00:00 2001 From: vafschoen <52745702+vafschoen@users.noreply.github.com> Date: Thu, 15 Oct 2020 12:10:40 +0200 Subject: [PATCH 6/8] fixed check to determine if we are in wsl2 --- lib/vagrant-hostmanager/hosts_file/updater.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-hostmanager/hosts_file/updater.rb b/lib/vagrant-hostmanager/hosts_file/updater.rb index 2ee2ad9..6048905 100644 --- a/lib/vagrant-hostmanager/hosts_file/updater.rb +++ b/lib/vagrant-hostmanager/hosts_file/updater.rb @@ -208,7 +208,7 @@ def self.windows? end def self.wsl? - defined?(ENV['WSLENV']) + ENV.include?('WSLENV') end require 'win32ole' if windows? From dfd661740e8a5414690747302f95c3ae97fa7ca5 Mon Sep 17 00:00:00 2001 From: Stephen Reay Date: Thu, 29 Jun 2023 23:44:24 +0700 Subject: [PATCH 7/8] Use keyword argument in place of a hash for I18n.t() calls Fixes devopsgroup-io/vagrant-hostmanager#290 --- lib/vagrant-hostmanager/action/update_guest.rb | 4 +--- lib/vagrant-hostmanager/config.rb | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/vagrant-hostmanager/action/update_guest.rb b/lib/vagrant-hostmanager/action/update_guest.rb index a957608..9824dc8 100644 --- a/lib/vagrant-hostmanager/action/update_guest.rb +++ b/lib/vagrant-hostmanager/action/update_guest.rb @@ -17,9 +17,7 @@ def initialize(app, env) def call(env) if @config.hostmanager.manage_guest? - env[:ui].info I18n.t('vagrant_hostmanager.action.update_guest', { - :name => @machine.name - }) + env[:ui].info I18n.t('vagrant_hostmanager.action.update_guest', name: @machine.name) @updater.update_guest(@machine) @app.call(env) diff --git a/lib/vagrant-hostmanager/config.rb b/lib/vagrant-hostmanager/config.rb index 1ae26f4..305d681 100644 --- a/lib/vagrant-hostmanager/config.rb +++ b/lib/vagrant-hostmanager/config.rb @@ -49,7 +49,7 @@ def validate(machine) # check if aliases option is an Array if !machine.config.hostmanager.aliases.kind_of?(Array) && !machine.config.hostmanager.aliases.kind_of?(String) - errors << I18n.t('vagrant_hostmanager.config.not_an_array_or_string', { + errors << I18n.t('vagrant_hostmanager.config.not_an_array_or_string', **{ :config_key => 'hostmanager.aliases', :is_class => aliases.class.to_s, }) @@ -57,7 +57,7 @@ def validate(machine) if !machine.config.hostmanager.ip_resolver.nil? && !machine.config.hostmanager.ip_resolver.kind_of?(Proc) - errors << I18n.t('vagrant_hostmanager.config.not_a_proc', { + errors << I18n.t('vagrant_hostmanager.config.not_a_proc', **{ :config_key => 'hostmanager.ip_resolver', :is_class => ip_resolver.class.to_s, }) @@ -72,7 +72,7 @@ def validate(machine) def validate_bool(key, value) if ![TrueClass, FalseClass].include?(value.class) && value != UNSET_VALUE - I18n.t('vagrant_hostmanager.config.not_a_bool', { + I18n.t('vagrant_hostmanager.config.not_a_bool', **{ :config_key => key, :value => value.class.to_s }) From 1e634d96487e9aedbba9317173dd3e76fd7bc4b7 Mon Sep 17 00:00:00 2001 From: Seth Reeser Date: Sun, 30 Jul 2023 15:47:34 -0400 Subject: [PATCH 8/8] Releasing v1.8.10 --- Gemfile | 2 +- README.md | 10 ++++------ lib/vagrant-hostmanager/version.rb | 2 +- vagrant-hostmanager.gemspec | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 9018418..22145ff 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' group :development do - gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.9.4' + gem 'vagrant', :git => 'https://github.com/hashicorp/vagrant.git', :tag => 'v2.3.7' end group :plugins do diff --git a/README.md b/README.md index 2eb8fb1..b2d2707 100644 --- a/README.md +++ b/README.md @@ -191,12 +191,10 @@ To contribute, fork then clone the repository, and then the following: **Developing** -1. Ideally, install the version of Vagrant as defined in the `Gemfile` -1. Install [Ruby](https://www.ruby-lang.org/en/documentation/installation/) -2. Currently the Bundler version is locked to 1.14.6, please install this version. - * `gem install bundler -v '1.14.6'` -3. Then install vagrant-hostmanager dependancies: - * `bundle _1.14.6_ install` +1. Install [RVM](https://rvm.io/rvm/install) +2. If using MacOS, follow these [OpenSSL instructions](https://github.com/rvm/rvm/issues/5252#issuecomment-1298835941) +3. Use Ruby v3.0.0 `rvm use 3.0.0` +4. Run `bundle install` **Testing** diff --git a/lib/vagrant-hostmanager/version.rb b/lib/vagrant-hostmanager/version.rb index ae0a99a..89d5311 100644 --- a/lib/vagrant-hostmanager/version.rb +++ b/lib/vagrant-hostmanager/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module HostManager - VERSION = '1.8.9' + VERSION = '1.8.10' end end diff --git a/vagrant-hostmanager.gemspec b/vagrant-hostmanager.gemspec index cb63b8f..eff7015 100644 --- a/vagrant-hostmanager.gemspec +++ b/vagrant-hostmanager.gemspec @@ -17,6 +17,6 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] - gem.add_development_dependency 'bundler', '~> 1.3' + gem.add_development_dependency 'bundler' gem.add_development_dependency 'rake' end