buildhosts 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -48
- data/{config → files/config} +0 -0
- data/{custom → files/custom} +0 -0
- data/{header → files/header} +0 -0
- data/lib/buildhosts.rb +1 -1
- data/lib/buildhosts/Manginx.rb +3 -2
- data/lib/buildhosts/version.rb +1 -1
- metadata +5 -7
- data/lib/old.buildhosts.rb +0 -22
- data/sample-config +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcb1c66c0f2109dfc4acd09ef24ace9e30808a66
|
4
|
+
data.tar.gz: e49736b08f8a10917871e095f7fd7f30deee725b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 890455945cd7faea50fb2ae874789fdbbfc5521c47819784fb98b9f24f2206b1e642d90490c1db5552a443c16932ad881043e40b34ddfe0f0d6fd1f457a8e7cc
|
7
|
+
data.tar.gz: 9f193e3f2428ba0f55ba0eaed8945ad2ddf7c8c3c2c01a70d46a6c72dca5424407fe7f7410e19f4fb0eace8ccec693e76343aeb9a5ed923c43080e7dc247e70c
|
data/README.md
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
# Buildhosts
|
2
2
|
|
3
|
-
This script
|
3
|
+
This is a script I wrote to write my `/etc/hosts` file for me.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
Configuring all the entries was a hassle, especially when using
|
6
|
+
[xip.io](http://xip.io). This script takes your local hostnames (and the
|
7
|
+
various IP address you need to pass to xip.io) and creates all the necessary
|
8
|
+
entries to access any of the hosts while passing any of the IPs to xip.io.
|
9
9
|
|
10
|
-
|
11
|
-
Configuring all the entries was a hassle, especially when using [xip.io](http://xip.io).
|
12
|
-
This script takes your local hostnames (and the various IP address you need to pass
|
13
|
-
to xip.io) and create all the necessary entries to access any of the hosts while
|
14
|
-
passing any of the IPs to xip.io.
|
10
|
+
Oh, and there's really no point in using this script if you're not using xip.io.
|
15
11
|
|
16
12
|
### Manginx
|
17
13
|
|
18
|
-
Also included
|
14
|
+
Also included is `manginx`, a script that keeps xip.io and nginx in harmony.
|
15
|
+
More on that later.
|
16
|
+
|
17
|
+
|
19
18
|
|
20
19
|
## Installation
|
21
20
|
|
@@ -23,58 +22,56 @@ That's easy:
|
|
23
22
|
|
24
23
|
$ gem install buildhosts
|
25
24
|
|
26
|
-
|
25
|
+
Boom.
|
26
|
+
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
|
30
|
+
Before you do anything, *back up your current `/etc/hosts` file!*
|
31
|
+
|
32
|
+
##### To edit your config file, type
|
31
33
|
|
32
34
|
$ buildhosts -e
|
33
35
|
|
36
|
+
You should do that before doing anything else (except backing up your
|
37
|
+
`/etc/hosts` file, do that first).
|
34
38
|
|
35
|
-
|
39
|
+
|
40
|
+
##### You can add custom hosts by typing
|
36
41
|
|
37
42
|
$ buildhosts -c
|
38
43
|
|
39
44
|
|
40
|
-
List your hosts with
|
45
|
+
##### List your hosts with
|
41
46
|
|
42
47
|
$ buildhosts -l
|
43
48
|
|
44
|
-
|
45
|
-
Run manginx with
|
46
|
-
|
47
|
-
$ buildhosts --nginx
|
49
|
+
Note: this does not list the IPs, only the hosts.
|
48
50
|
|
49
51
|
|
50
|
-
|
52
|
+
##### Run manginx with
|
51
53
|
|
54
|
+
$ buildhosts --nginx
|
52
55
|
|
53
|
-
About the IP Address Section
|
54
|
-
----------------------------
|
55
56
|
|
56
|
-
The IP section is for working with xip.io, a DNS server that makes testing local
|
57
|
-
websites on mobile devices much simpler. You can read more about it [here](http://xip.io).
|
58
|
-
If you don't want to work with xip.io, don't include the IP address section in your config file.
|
59
57
|
|
60
|
-
|
61
|
-
----------------------
|
58
|
+
## Configuration
|
62
59
|
|
63
60
|
If you run `buildhosts` with this `config` file:
|
64
61
|
|
65
|
-
|
62
|
+
#### sample-config
|
66
63
|
|
67
64
|
[hosts]
|
68
65
|
foobar.local
|
69
66
|
example.local
|
70
67
|
[ips]
|
71
68
|
192.168.1.1
|
72
|
-
192.168.0.1
|
73
69
|
10.0.1.1
|
74
70
|
|
75
71
|
it will produce this output:
|
76
72
|
|
77
|
-
|
73
|
+
#### /etc/hosts
|
74
|
+
|
78
75
|
##
|
79
76
|
# Host Database
|
80
77
|
#
|
@@ -90,43 +87,46 @@ it will produce this output:
|
|
90
87
|
127.0.0.1 example.local
|
91
88
|
::1 example.local.10.0.1.1.xip.io
|
92
89
|
127.0.0.1 example.local.10.0.1.1.xip.io
|
93
|
-
::1 example.local.192.168.0.1.xip.io
|
94
|
-
127.0.0.1 example.local.192.168.0.1.xip.io
|
95
90
|
::1 example.local.192.168.1.1.xip.io
|
96
91
|
127.0.0.1 example.local.192.168.1.1.xip.io
|
97
92
|
::1 foobar.local
|
98
93
|
127.0.0.1 foobar.local
|
99
94
|
::1 foobar.local.10.0.1.1.xip.io
|
100
95
|
127.0.0.1 foobar.local.10.0.1.1.xip.io
|
101
|
-
::1 foobar.local.192.168.0.1.xip.io
|
102
|
-
127.0.0.1 foobar.local.192.168.0.1.xip.io
|
103
96
|
::1 foobar.local.192.168.1.1.xip.io
|
104
97
|
127.0.0.1 foobar.local.192.168.1.1.xip.io
|
105
98
|
|
106
|
-
Simple enough? I thought so.
|
107
99
|
|
108
|
-
Manginx
|
109
|
-
-------
|
110
100
|
|
111
|
-
|
101
|
+
## Manginx
|
102
|
+
|
103
|
+
For each host you specified in the `config`, manginx will create a file that
|
104
|
+
contains duplicate server_name directives for the host, but with all the
|
105
|
+
necessary xip.io URLs appended. You just need to include that file in your
|
106
|
+
`nginx.conf` (see below) and run
|
112
107
|
|
113
108
|
$ buildhosts --nginx
|
114
109
|
|
110
|
+
Note: make sure you have a `xip/` directory in the same directory as your
|
111
|
+
`nginx.conf`.
|
112
|
+
|
113
|
+
#### To include the file,
|
115
114
|
|
116
|
-
|
117
|
-
|
115
|
+
just duplicate any server_name lines in your
|
116
|
+
`nginx.conf` and modify them like this:
|
118
117
|
|
119
|
-
|
118
|
+
##### Before:
|
120
119
|
server_name foobar.local;
|
121
120
|
|
122
|
-
|
121
|
+
##### After:
|
123
122
|
server_name foobar.local;
|
124
123
|
include xip/foobar.local;
|
125
124
|
|
126
|
-
## Contributing
|
127
125
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
126
|
+
### Vim protip:
|
127
|
+
|
128
|
+
From a server_name line (in normal mode):
|
129
|
+
|
130
|
+
yypRinclude xip/
|
131
|
+
|
132
|
+
If you've got a lot of lines to do, make that a macro; you won't regret it.
|
data/{config → files/config}
RENAMED
File without changes
|
data/{custom → files/custom}
RENAMED
File without changes
|
data/{header → files/header}
RENAMED
File without changes
|
data/lib/buildhosts.rb
CHANGED
@@ -7,7 +7,7 @@ module Buildhosts
|
|
7
7
|
attr_reader :path
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@path = File.expand_path('../../', __FILE__)
|
10
|
+
@path = File.expand_path('../../files/', __FILE__)
|
11
11
|
@files = Hash.new
|
12
12
|
['config', 'custom', 'header', 'newhosts', 'temp'].each do |f|
|
13
13
|
if (File.exist?(File.expand_path("~/.buildhosts/#{f}")))
|
data/lib/buildhosts/Manginx.rb
CHANGED
@@ -22,6 +22,7 @@ module Buildhosts
|
|
22
22
|
puts 'What\'s the point?'
|
23
23
|
exit
|
24
24
|
end
|
25
|
+
system('mkdir -p /usr/local/etc/nginx/xip')
|
25
26
|
# Let's find out what nginx is expecting from us...
|
26
27
|
expected = Array.new
|
27
28
|
n = File.open('/usr/local/etc/nginx/nginx.conf', 'r')
|
@@ -36,7 +37,7 @@ module Buildhosts
|
|
36
37
|
|
37
38
|
# This is where the files will be stored.
|
38
39
|
base_path = '/usr/local/etc/nginx/xip'
|
39
|
-
`rm #{base_path}/*`
|
40
|
+
`rm -f #{base_path}/*`
|
40
41
|
|
41
42
|
# Le bread and buttere
|
42
43
|
expected.each do |file|
|
@@ -51,7 +52,7 @@ module Buildhosts
|
|
51
52
|
|
52
53
|
# Now we just reload nginx and apologize if something goes rotten.
|
53
54
|
done 'Reloading nginx...'
|
54
|
-
if system('nginx -s reload')
|
55
|
+
if system('sudo nginx -s reload')
|
55
56
|
done
|
56
57
|
else
|
57
58
|
puts "Oops!\nSomething went wrong... Sorry."
|
data/lib/buildhosts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buildhosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,15 +55,13 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- bin/buildhosts
|
57
57
|
- buildhosts.gemspec
|
58
|
-
- config
|
59
|
-
- custom
|
60
|
-
- header
|
58
|
+
- files/config
|
59
|
+
- files/custom
|
60
|
+
- files/header
|
61
61
|
- lib/buildhosts.rb
|
62
62
|
- lib/buildhosts/ConfigParser.rb
|
63
63
|
- lib/buildhosts/Manginx.rb
|
64
64
|
- lib/buildhosts/version.rb
|
65
|
-
- lib/old.buildhosts.rb
|
66
|
-
- sample-config
|
67
65
|
homepage: ''
|
68
66
|
licenses:
|
69
67
|
- MIT
|
data/lib/old.buildhosts.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require './ConfigParser.rb'
|
2
|
-
|
3
|
-
# Prefixy strings
|
4
|
-
ipv6 = '::1 '
|
5
|
-
home = '127.0.0.1 '
|
6
|
-
|
7
|
-
# Grab that parser and parse
|
8
|
-
p = ConfigParser.new
|
9
|
-
conf = p.parse 'config'
|
10
|
-
|
11
|
-
# Write the lines to a "newhosts" file
|
12
|
-
out = File.open('newhosts', 'w+')
|
13
|
-
conf['hosts'].each do |host|
|
14
|
-
out.write "#{ipv6}#{host}\n"
|
15
|
-
out.write "#{home}#{host}\n"
|
16
|
-
conf['ips'].each do |ip|
|
17
|
-
out.write "#{ipv6}#{host}.#{ip}.xip.io\n"
|
18
|
-
out.write "#{home}#{host}.#{ip}.xip.io\n"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
out.close
|
22
|
-
|
data/sample-config
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# Hostnames go here, one per line
|
2
|
-
foobar.local
|
3
|
-
example.local
|
4
|
-
|
5
|
-
# Don't delete the ampersand
|
6
|
-
# (unless you also delete
|
7
|
-
# everything below it).
|
8
|
-
&
|
9
|
-
|
10
|
-
# IP addresses for xip.io.
|
11
|
-
# You can just leave this blank
|
12
|
-
# if you're not using it.
|
13
|
-
192.168.1.1
|
14
|
-
192.168.0.1
|
15
|
-
10.0.1.1
|