vagrant-hostsupdater 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +3 -0
- data/lib/vagrant-hostsupdater/HostsUpdater.rb +25 -26
- data/lib/vagrant-hostsupdater/version.rb +1 -1
- metadata +1 -1
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:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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 "
|
37
|
+
@ui.info "adding to (#@@hosts_path) : #{hostEntry}"
|
40
38
|
entries.push(hostEntry)
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
44
|
-
|
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(
|
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
|
-
|
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?(
|
89
|
-
sudo(%Q(sed -i -e '/#{hashedId}/ d'
|
84
|
+
if !File.writable?(@@hosts_path)
|
85
|
+
sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
|
90
86
|
else
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
106
|
+
if Vagrant::Util::Platform.windows?
|
107
|
+
`#{command}`
|
108
|
+
else
|
110
109
|
`sudo #{command}`
|
111
|
-
|
110
|
+
end
|
112
111
|
end
|
113
112
|
end
|
114
113
|
end
|