vagrant-hostsupdater 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 092e9d19e52604448eef2935325883f9f9a1406d
4
- data.tar.gz: df0ef378226ef4c9bdb7194546f0a8dee36aad0d
5
2
  SHA512:
6
- metadata.gz: 5403a44f9eb9389019bcfbf947b0df3a1b64abc0de2b6f7fe8f6abdfbfa2d5b0896cb1c11287b26a5baec29ce1b0e70085865abbe04c285d09fccfa47701ec45
7
- data.tar.gz: fc3bf266de0209b090151fa7dcfa56a7339da8e5e6a101fa8239d10ae667e0670f1266683604df1a1d2bf49415a5f26fd315ba7b08d9d8ea7f79854afa08c4c7
3
+ metadata.gz: c56f591feb65c66cde8837ca645e19143fcbdb3b015d726725003d7cae3df670949708cb63c5749216b5683d4e24b7d020570093a1a33245494c941c4283ef00
4
+ data.tar.gz: 958b809be3ea034db7872553836c8d232620be3677e8992202eca4975df942ef0f4bd63d2301b8c32a05939a6fe4b7c50d10c747d6cbada3ab4ebfa56555e335
5
+ SHA1:
6
+ metadata.gz: 2a7afc721f01110c8c34b3e35fb33efcf3b27893
7
+ data.tar.gz: bbc27f75779ed6de5b56f04224096d3bb40f42ff
data/README.md CHANGED
@@ -11,6 +11,9 @@ By setting the remove\_on\_suspend option, you can have them removed on **suspen
11
11
 
12
12
  ## Versions
13
13
 
14
+ ### 0.0.8
15
+ * trying to use proper windows hosts file
16
+
14
17
  ### 0.0.7
15
18
  * using hashed uids now to identify hosts entries (you might need to remove previous hostentries manually)
16
19
  * fixed removing of host entries
@@ -1,9 +1,7 @@
1
1
  module VagrantPlugins
2
2
  module HostsUpdater
3
3
  module HostsUpdater
4
- def test
5
- puts "jawoll"
6
- end
4
+ @@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
7
5
 
8
6
  def getIps
9
7
  ips = []
@@ -36,24 +34,16 @@ module VagrantPlugins
36
34
  hostEntries.each do |hostEntry|
37
35
  escapedEntry = Regexp.quote(hostEntry)
38
36
  if !hostsContents.match(/#{escapedEntry}/)
39
- @ui.info "pushing #{hostEntry}"
37
+ @ui.info "adding to (#@@hosts_path) : #{hostEntry}"
40
38
  entries.push(hostEntry)
41
39
  end
42
40
  end
43
41
  end
44
- @ui.info entries
45
- if !File.writable?("/etc/hosts")
46
- sudo(addToHosts(entries))
47
- else
48
- command = addToHosts(entries)
49
- @ui.info command
50
- `#{command}`
51
- end
52
-
42
+ addToHosts(entries)
53
43
  end
54
44
 
55
45
  def removeHostEntries
56
- file = File.open("/etc/hosts", "rb")
46
+ file = File.open(@@hosts_path, "rb")
57
47
  hostsContents = file.read
58
48
  uuid = @machine.id
59
49
  hashedId = Digest::MD5.hexdigest(uuid)
@@ -76,21 +66,30 @@ module VagrantPlugins
76
66
 
77
67
  def addToHosts(entries)
78
68
  return if entries.length == 0
79
- hosts_path = '/etc/hosts'
80
69
  content = entries.join("\n")
81
- %Q(sh -c 'echo "#{content}" >>#{hosts_path}')
70
+ if !File.writable?(@@hosts_path)
71
+ sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
72
+ else
73
+ hostsFile = File.open(@@hosts_path, "a")
74
+ hostsFile.write(content)
75
+ hostsFile.close()
76
+ end
77
+
78
+
82
79
  end
83
80
 
84
81
  def removeFromHosts(options = {})
85
- hosts_path = '/etc/hosts'
86
82
  uuid = @machine.id
87
83
  hashedId = Digest::MD5.hexdigest(uuid)
88
- if !File.writable?("/etc/hosts")
89
- sudo(%Q(sed -i -e '/#{hashedId}/ d' #{hosts_path}))
84
+ if !File.writable?(@@hosts_path)
85
+ sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
90
86
  else
91
- output = `sed -e "/#{hashedId}/ d" #{hosts_path}`
92
- hostsFile = File.open(hosts_path, "w")
93
- hostsFile.write(output)
87
+ hosts = ""
88
+ File.open(@@hosts_path).each do |line|
89
+ hosts << line unless line.include?(hashedId)
90
+ end
91
+ hostsFile = File.open(@@hosts_path, "w")
92
+ hostsFile.write(hosts)
94
93
  hostsFile.close()
95
94
  end
96
95
  end
@@ -104,11 +103,11 @@ module VagrantPlugins
104
103
 
105
104
  def sudo(command)
106
105
  return if !command
107
- # if Util::Platform.windows?
108
- # `#{command}`
109
- # else
106
+ if Vagrant::Util::Platform.windows?
107
+ `#{command}`
108
+ else
110
109
  `sudo #{command}`
111
- # end
110
+ end
112
111
  end
113
112
  end
114
113
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module HostsUpdater
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-hostsupdater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Falk K\xC3\xBChnel"