vagrant-goodhosts 1.1.0beta → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f6a0225da423c0c803dacaeb97182e8768510d601db33c182a088733d282f60
4
- data.tar.gz: f2756ce326a5d766baa4fd63f5d4d158c13fb0591c88a9763dc6e9846b377bbc
3
+ metadata.gz: d9d571c66bee739daa440ff14420530877b8de9a54772960000c322a621a6dfc
4
+ data.tar.gz: 1da6af09b2600518c6bc98b46dfd788429408fd43cd22b652cedf699931eca5f
5
5
  SHA512:
6
- metadata.gz: 11d1c0937d56326ebbd390adc477c8c047b6422f0c81c21ad454d297992876941267102811acbc7e7e32e960a2feb2767d055f086a4461b8f6008cd1b81d0581
7
- data.tar.gz: 528d8f7ff5b81d8a377530a628710ef62ae4432790099f3c8a4673c01e2c3d1ef4032181680e63bc5cd49f8925d01374ed3d8ae919a09bd2849ad0def44022d2
6
+ metadata.gz: f6d3f083e720d58cadeab5a822bbe3eebfcc25adbe1e7bc695b6ad7bb81762d6a2dfe5851ab37580dfcde0bd194d07b78043d5abaa40e64d273d95fc0775b293
7
+ data.tar.gz: 2094f799367acc58696189954d1691564c7feb3d677fed5edca8ac760e34e819a0dd1313309eb90636b17117ef69c8b05e0195e4bb62c71486ce16cb27c2dc3e
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "https://rubygems.org"
2
+ ruby "~> 2.5.0"
2
3
 
3
4
  group :development do
4
5
  gem "vagrant", git: "https://github.com/hashicorp/vagrant.git"
data/README.md CHANGED
@@ -24,6 +24,13 @@ To update the plugin:
24
24
  vagrant plugin update vagrant-goodhosts
25
25
  ```
26
26
 
27
+ ### Installation from Gem file
28
+
29
+ The gem file is released with every [release](https://github.com/goodhosts/vagrant/releases) and you can install it with vagrant as it is a plugin after all.
30
+ Affter downloading the file run this command to install manually:
31
+
32
+ `vagrant plugin install vagrant-goodhosts-*.gem`
33
+
27
34
  ## Usage
28
35
 
29
36
  You currently only need the `hostname` and a `:private_network` network with a fixed IP address.
@@ -115,7 +122,7 @@ You have to open an elevated command prompt; hold `❖ Win` and press `X`, then
115
122
 
116
123
  cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
117
124
 
118
- ## Installing The Development Version
125
+ ## Generate The Development Version
119
126
 
120
127
  If you would like to install `vagrant-goodhosts` to make contributions or changes, run the following commands::
121
128
 
@@ -125,3 +132,7 @@ cd vagrant-goodhosts
125
132
  ./package.sh
126
133
  vagrant plugin install vagrant-goodhosts-*.gem
127
134
  ```
135
+
136
+ ## Test the plugin
137
+
138
+ You need to run a Vagrant machine with the minimum settings specified in the [Usage](https://github.com/goodhosts/vagrant#usage) section, it is enough a turn on and off and in the meantime if the hosts file in your machine is written in the right way.
@@ -48,7 +48,12 @@ module VagrantPlugins
48
48
  if OS.windows?
49
49
  return 'cli.exe'
50
50
  elsif OS.mac?
51
- return 'cli_osx'
51
+ type = system('uname -m')
52
+ if type == 'x86_64'
53
+ return 'cli_amd64_osx'
54
+ else
55
+ return 'cli_arm64_osx'
56
+ end
52
57
  elsif OS.linux?
53
58
  return 'cli'
54
59
  else
@@ -104,30 +109,27 @@ module VagrantPlugins
104
109
  rescue StandardError => _e
105
110
  hostnames_to_add.append(hostname)
106
111
  end
107
- return hostnames_to_add
112
+ return hostnames_to_add.join(' ')
108
113
  end
109
114
 
110
115
  def add_goodhost_entries(ip_address, hostnames)
111
116
  cli = get_cli
112
117
  if cli.include? ".exe"
113
- clean = "\"--clean\","
114
- if disable_clean(ip_address)
115
- clean = ''
116
- end
117
- stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
118
+ clean = get_clean_parameter_by_system(ip_address, true)
119
+ command = "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs"
120
+ stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", command)
118
121
  else
119
- clean = "--clean"
120
- if disable_clean(ip_address)
121
- clean = ''
122
- end
123
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}")
122
+ clean = get_clean_parameter_by_system(ip_address, false)
123
+ command = "sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}"
124
+ stdin, stdout, stderr, wait_thr = Open3.popen3(command)
124
125
  end
125
- return stdin, stdout, stderr, wait_thr
126
+ return stdin, stdout, stderr, wait_thr, command
126
127
  end
127
128
 
128
129
  def add_host_entries
129
130
  error = false
130
- error_text = ""
131
+ error_text = ''
132
+ command = ''
131
133
  hostnames_by_ips = generate_hostnames_by_ips
132
134
 
133
135
  return if hostnames_by_ips.none?
@@ -142,34 +144,35 @@ module VagrantPlugins
142
144
 
143
145
  # filter out the hosts we've already added
144
146
  hosts_to_add = check_hostnames_to_add(ip_address, hostnames)
145
- next if hosts_to_add.none?
147
+ next if hosts_to_add.empty?
146
148
 
147
- _stdin, _stdout, stderr, wait_thr = add_goodhost_entries(ip_address, hosts_to_add)
149
+ _stdin, _stdout, stderr, wait_thr, command = add_goodhost_entries(ip_address, hosts_to_add)
148
150
  unless wait_thr.value.success?
149
151
  error = true
150
152
  error_text = stderr.read.strip
151
153
  end
152
154
  end
153
- print_readme(error, error_text)
155
+ print_readme(error, error_text, command)
154
156
  end
155
157
 
156
158
  def remove_goodhost_entries(ip_address, hostnames)
157
159
  cli = get_cli
158
- clean = "\"--clean\","
159
- if disable_clean(ip_address)
160
- clean = ''
161
- end
162
160
  if cli.include? ".exe"
163
- stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
161
+ clean = get_clean_parameter_by_system(ip_address, true)
162
+ command = "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs"
163
+ stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", command)
164
164
  else
165
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}")
165
+ clean = get_clean_parameter_by_system(ip_address, false)
166
+ command = "sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}"
167
+ stdin, stdout, stderr, wait_thr = Open3.popen3(command)
166
168
  end
167
- return stdin, stdout, stderr, wait_thr
169
+ return stdin, stdout, stderr, wait_thr, command
168
170
  end
169
171
 
170
172
  def remove_host_entries
171
173
  error = false
172
- error_text = ""
174
+ error_text = ''
175
+ command = ''
173
176
  hostnames_by_ips = generate_hostnames_by_ips
174
177
 
175
178
  return if hostnames_by_ips.none?
@@ -182,22 +185,36 @@ module VagrantPlugins
182
185
  next
183
186
  end
184
187
 
185
- _stdin, _stdout, stderr, wait_thr = remove_goodhost_entries(ip_address, hostnames)
188
+ _stdin, _stdout, stderr, wait_thr, command = remove_goodhost_entries(ip_address, hostnames)
186
189
  unless wait_thr.value.success?
187
190
  error = true
188
191
  error_text = stderr.read.strip
189
192
  end
190
193
  end
191
- print_readme(error, error_text)
194
+ print_readme(error, error_text, command)
195
+ end
196
+
197
+ def get_clean_parameter_by_system(ip_address, is_win)
198
+ clean = "--clean"
199
+ if is_win
200
+ clean = "\"--clean\","
201
+ end
202
+
203
+ if disable_clean(ip_address)
204
+ clean = ''
205
+ end
206
+ return clean
192
207
  end
193
208
 
194
- def print_readme(error, error_text)
209
+ def print_readme(error, error_text, command)
195
210
  unless error
211
+ @ui.info "[vagrant-goodhosts] Finished processing"
196
212
  return false
197
213
  end
198
214
 
199
215
  cli = get_cli
200
216
  @ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{error_text}"
217
+ @ui.error "[vagrant-goodhosts] Command: #{command}"
201
218
  @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
202
219
  if cli.include? ".exe"
203
220
  @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#windows-uac-prompt"
@@ -207,6 +224,18 @@ module VagrantPlugins
207
224
  end
208
225
  end
209
226
 
227
+ def append_hostsnames_by_ips(hostnames_by_ips, hostnames, ip_address, ip_index)
228
+ if hostnames[ip_index].count() > 0
229
+ hostnames[ip_index].each do |hostname|
230
+ unless ip_address.nil?
231
+ @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
232
+ end
233
+ end
234
+ hostnames_by_ips = { ip_address => hostnames[ip_index].join(" ") }
235
+ end
236
+ return hostnames_by_ips
237
+ end
238
+
210
239
  def generate_hostnames_by_ips
211
240
  hostnames_by_ips = []
212
241
  ips = get_ips
@@ -218,25 +247,11 @@ module VagrantPlugins
218
247
  if ips.count() > 1
219
248
  ips.each do |ip|
220
249
  ip_address = ip
221
- if hostnames[ip].count() > 0
222
- hostnames[ip].each do |hostname|
223
- unless ip_address.nil?
224
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
225
- end
226
- end
227
- hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
228
- end
250
+ hostnames_by_ips = append_hostsnames_by_ips(hostnames_by_ips, hostnames, ip_address, ip)
229
251
  end
230
252
  else
231
253
  ip_address = ips[0]
232
- if hostnames[ip_address].count() > 0
233
- hostnames[ip_address].each do |hostname|
234
- unless ip_address.nil?
235
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
236
- end
237
- end
238
- hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
239
- end
254
+ hostnames_by_ips = append_hostsnames_by_ips(hostnames_by_ips, hostnames, ip_address, ip_address)
240
255
  end
241
256
 
242
257
  return hostnames_by_ips
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.1.0beta'
3
+ VERSION = '1.1.2'
4
4
  end
5
5
  end
data/package.sh CHANGED
@@ -5,9 +5,10 @@ cd ./lib/vagrant-goodhosts/bundle
5
5
  # Download
6
6
  curl -s https://api.github.com/repos/goodhosts/cli/releases/latest | jq --raw-output '.assets[] | .browser_download_url' | xargs wget -i
7
7
  # Extract
8
- tar -zxvf goodhosts_darwin_amd64.tar.gz goodhosts && mv goodhosts cli_osx
9
- tar -zxvf goodhosts_linux_amd64.tar.gz goodhosts && mv goodhosts cli
10
- tar -zxvf goodhosts_windows_amd64.tar.gz goodhosts.exe && mv goodhosts.exe cli.exe
8
+ tar -zxvf goodhosts-1.1.0-darwin-amd64.tar.gz goodhosts && mv goodhosts cli_amd64_osx
9
+ tar -zxvf goodhosts-1.1.0-darwin-arm64.tar.gz goodhosts && mv goodhosts cli_arm64_osx
10
+ tar -zxvf goodhosts-1.1.0-linux-amd64.tar.gz goodhosts && mv goodhosts cli
11
+ tar -zxvf goodhosts-1.1.0-windows-amd64.tar.gz goodhosts.exe && mv goodhosts.exe cli.exe
11
12
  rm -f ./*.tar.gz
12
13
  rm -f ./*.txt
13
14
  # Generate
@@ -6,6 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = 'vagrant-goodhosts'
7
7
  s.version = VagrantPlugins::GoodHosts::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
+ s.required_ruby_version = '>= 2.5'
9
10
  s.authors = ['Daniele Scasciafratte']
10
11
  s.email = ['mte90net@gmail.com']
11
12
  s.description = "Enables Vagrant to update hosts file on the host machine with goodhosts"
@@ -19,7 +20,7 @@ Gem::Specification.new do |s|
19
20
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
21
  s.require_paths = ['lib']
21
22
 
22
- s.add_development_dependency 'bundler', '~> 1.3'
23
+ s.add_development_dependency 'bundler', '>= 2.2.10'
23
24
  s.add_development_dependency 'rake'
24
25
 
25
26
  s.add_runtime_dependency "os"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-goodhosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0beta
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniele Scasciafratte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-13 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: 2.2.10
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +73,8 @@ files:
73
73
  - lib/vagrant-goodhosts/GoodHosts.rb
74
74
  - lib/vagrant-goodhosts/bundle/cli
75
75
  - lib/vagrant-goodhosts/bundle/cli.exe
76
- - lib/vagrant-goodhosts/bundle/cli_osx
76
+ - lib/vagrant-goodhosts/bundle/cli_amd64_osx
77
+ - lib/vagrant-goodhosts/bundle/cli_arm64_osx
77
78
  - lib/vagrant-goodhosts/config.rb
78
79
  - lib/vagrant-goodhosts/plugin.rb
79
80
  - lib/vagrant-goodhosts/version.rb
@@ -91,12 +92,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
92
  requirements:
92
93
  - - ">="
93
94
  - !ruby/object:Gem::Version
94
- version: '0'
95
+ version: '2.5'
95
96
  required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  requirements:
97
- - - ">"
98
+ - - ">="
98
99
  - !ruby/object:Gem::Version
99
- version: 1.3.1
100
+ version: '0'
100
101
  requirements: []
101
102
  rubygems_version: 3.2.27
102
103
  signing_key:
Binary file