buildhosts 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +111 -8
- data/bin/buildhosts +26 -36
- data/config +5 -11
- data/lib/buildhosts.rb +3 -3
- data/lib/buildhosts/version.rb +1 -1
- metadata +1 -2
- data/README.markdown +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03ec0ab7bc45e163d3c1f018b00ca2e557136c17
|
4
|
+
data.tar.gz: 9da6efcacf54aa3940dfb4260b98e173ed1513c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a32c8a1d188a32570219591ac1511df36a8023f4bd2f95534c02bf8670c97d6d6d28b369834f186bd9f04bc3bcc2547b862fd18a62cd57de3a404d727d4a6723
|
7
|
+
data.tar.gz: 7ae6b0dc91ab805800ea12fe8575dfed806c91b74332e5f9a21b08b1c5beca7b0c385b0664b642585cfd02097b2838f52a18c3ecfc6b797b6bdd23e04641b7ec
|
data/README.md
CHANGED
@@ -1,24 +1,127 @@
|
|
1
1
|
# Buildhosts
|
2
2
|
|
3
|
-
|
3
|
+
This script will:
|
4
4
|
|
5
|
-
|
5
|
+
+ change your life
|
6
|
+
+ make you smarter
|
7
|
+
+ grant you three wishes, and
|
8
|
+
+ do none of the above.
|
6
9
|
|
7
|
-
|
10
|
+
But really, this is just a script I wrote to write my /etc/hosts file for me.
|
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.
|
8
15
|
|
9
|
-
|
16
|
+
### Manginx
|
10
17
|
|
11
|
-
|
18
|
+
Also included in `manginx`, a script that helps with using xip.io with nginx.
|
12
19
|
|
13
|
-
|
20
|
+
## Installation
|
14
21
|
|
15
|
-
|
22
|
+
That's easy:
|
16
23
|
|
17
24
|
$ gem install buildhosts
|
18
25
|
|
26
|
+
You will want to *back up your current `hosts` file*, though.
|
27
|
+
|
19
28
|
## Usage
|
20
29
|
|
21
|
-
|
30
|
+
To edit your config file, type
|
31
|
+
|
32
|
+
$ buildhosts -e
|
33
|
+
|
34
|
+
|
35
|
+
You can add custom hosts by typing
|
36
|
+
|
37
|
+
$ buildhosts -c
|
38
|
+
|
39
|
+
|
40
|
+
List your hosts with
|
41
|
+
|
42
|
+
$ buildhosts -l
|
43
|
+
|
44
|
+
|
45
|
+
Run manginx with
|
46
|
+
|
47
|
+
$ buildhosts --nginx
|
48
|
+
|
49
|
+
|
50
|
+
Just running `buildhosts` will recompile your hosts file.
|
51
|
+
|
52
|
+
|
53
|
+
About the IP Address Section
|
54
|
+
----------------------------
|
55
|
+
|
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
|
+
|
60
|
+
Configuring the Script
|
61
|
+
----------------------
|
62
|
+
|
63
|
+
If you run `buildhosts` with this `config` file:
|
64
|
+
|
65
|
+
### sample-config:
|
66
|
+
|
67
|
+
[hosts]
|
68
|
+
foobar.local
|
69
|
+
example.local
|
70
|
+
[ips]
|
71
|
+
192.168.1.1
|
72
|
+
192.168.0.1
|
73
|
+
10.0.1.1
|
74
|
+
|
75
|
+
it will produce this output:
|
76
|
+
|
77
|
+
### /etc/hosts
|
78
|
+
##
|
79
|
+
# Host Database
|
80
|
+
#
|
81
|
+
# localhost is used to configure the loopback interface
|
82
|
+
# when the system is booting. Do not change this entry.
|
83
|
+
##
|
84
|
+
127.0.0.1 localhost
|
85
|
+
255.255.255.255 broadcasthost
|
86
|
+
::1 localhost
|
87
|
+
fe80::1%lo0 localhost
|
88
|
+
|
89
|
+
::1 example.local
|
90
|
+
127.0.0.1 example.local
|
91
|
+
::1 example.local.10.0.1.1.xip.io
|
92
|
+
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
|
+
::1 example.local.192.168.1.1.xip.io
|
96
|
+
127.0.0.1 example.local.192.168.1.1.xip.io
|
97
|
+
::1 foobar.local
|
98
|
+
127.0.0.1 foobar.local
|
99
|
+
::1 foobar.local.10.0.1.1.xip.io
|
100
|
+
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
|
+
::1 foobar.local.192.168.1.1.xip.io
|
104
|
+
127.0.0.1 foobar.local.192.168.1.1.xip.io
|
105
|
+
|
106
|
+
Simple enough? I thought so.
|
107
|
+
|
108
|
+
Manginx
|
109
|
+
-------
|
110
|
+
|
111
|
+
To run manginx, just do
|
112
|
+
|
113
|
+
$ buildhosts --nginx
|
114
|
+
|
115
|
+
|
116
|
+
As far as configuring goes, just make sure you have an `xip` directory in the same directory as your `nginx.conf`.
|
117
|
+
Then just duplicate any server_name lines in your `nginx.conf` and alter them like so:
|
118
|
+
|
119
|
+
### Before:
|
120
|
+
server_name foobar.local;
|
121
|
+
|
122
|
+
### After:
|
123
|
+
server_name foobar.local;
|
124
|
+
include xip/foobar.local;
|
22
125
|
|
23
126
|
## Contributing
|
24
127
|
|
data/bin/buildhosts
CHANGED
@@ -2,53 +2,43 @@
|
|
2
2
|
|
3
3
|
require 'buildhosts'
|
4
4
|
|
5
|
+
$path = File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
$files = Hash.new
|
8
|
+
|
9
|
+
def find_files files
|
10
|
+
files.each do |f|
|
11
|
+
if (File.exist?(File.expand_path("~/.buildhosts/#{f}")))
|
12
|
+
$files[f] = File.expand_path("~/.buildhosts/#{f}").chomp
|
13
|
+
else
|
14
|
+
$files[f] = "#{$path}/#{f}".chomp
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
find_files ['config', 'custom', 'header', 'newhosts', 'temp']
|
20
|
+
|
5
21
|
case ARGV[0]
|
6
22
|
when "-e"
|
7
|
-
system("vim config")
|
23
|
+
system("vim #{$files['config']}")
|
8
24
|
when "-c"
|
9
|
-
system("vim custom")
|
25
|
+
system("vim #{$files['custom']}")
|
10
26
|
when "-ec"
|
11
|
-
system("vim config ; vim custom")
|
27
|
+
system("vim #{$files['config']} ; vim #{$files['custom']}")
|
12
28
|
when "-ce"
|
13
|
-
system("vim custom ; vim config")
|
29
|
+
system("vim #{$files['custom']} ; vim #{$files['config']}")
|
14
30
|
when "-l"
|
15
31
|
system("grep 127.0.0.1 /etc/hosts | grep -Ev 'xip.io|localhost' | awk '{print $2}'")
|
16
32
|
exit
|
17
33
|
when "--nginx", "-nginx"
|
18
|
-
puts "
|
19
|
-
puts "Then reload nginx"
|
20
|
-
exit
|
21
|
-
else
|
22
|
-
puts "Usage: "
|
34
|
+
puts "TODO: run manginx..."
|
23
35
|
exit
|
24
36
|
end
|
25
37
|
|
38
|
+
# Do all the stuff
|
26
39
|
puts "Building..."
|
27
|
-
Buildhosts::Main.build
|
28
|
-
system("")
|
29
|
-
system("
|
30
|
-
system("
|
31
|
-
system("rm newhosts temp")
|
40
|
+
Buildhosts::Main.build $files['config'], $files['newhosts']
|
41
|
+
system("cat #{$files['header']} #{$files['custom']} #{$files['newhosts']} > #{$files['temp']}")
|
42
|
+
system("sudo cp #{$files['temp']} /etc/hosts")
|
43
|
+
system("rm #{$files['newhosts']} #{$files['temp']}")
|
32
44
|
puts "Done!"
|
33
|
-
#if [ "$1" == "-e" ]; then
|
34
|
-
#vim config
|
35
|
-
#elif [ "$1" == "-c" ]; then
|
36
|
-
#vim custom
|
37
|
-
#elif [ "$1" == "-ec" ]; then
|
38
|
-
#vim config ; vim custom
|
39
|
-
#elif [ "$1" == "-ce" ]; then
|
40
|
-
#vim custom ; vim config
|
41
|
-
#elif [ "$1" == "-l" ]; then
|
42
|
-
#grep 127.0.0.1 /etc/hosts | grep -Ev 'xip.io|localhost' | awk '{print $2}'
|
43
|
-
#exit 0
|
44
|
-
#elif [ "$1" == "--nginx" ]; then
|
45
|
-
#ruby manginx.rb
|
46
|
-
#nginx -s reload
|
47
|
-
#exit 0
|
48
|
-
#fi
|
49
|
-
|
50
|
-
#ruby buildhosts.rb
|
51
|
-
|
52
|
-
#cat header custom newhosts > temp
|
53
|
-
#sudo cp temp /etc/hosts
|
54
|
-
#rm newhosts temp
|
data/config
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
[hosts]
|
2
|
-
|
3
|
-
|
4
|
-
ecochair.local
|
5
|
-
echair2013.local
|
6
|
-
usb.local
|
7
|
-
blp.local
|
8
|
-
hdvisa.local
|
9
|
-
indian.local
|
10
|
-
gitlife.mrmikea.local
|
2
|
+
foobar.local
|
3
|
+
example.local
|
11
4
|
[ips]
|
12
|
-
192.168.
|
13
|
-
|
5
|
+
192.168.1.1
|
6
|
+
192.168.0.1
|
7
|
+
10.0.1.1
|
data/lib/buildhosts.rb
CHANGED
@@ -3,17 +3,17 @@ require "buildhosts/ConfigParser"
|
|
3
3
|
|
4
4
|
module Buildhosts
|
5
5
|
class Main
|
6
|
-
def self.build
|
6
|
+
def self.build config, newhosts
|
7
7
|
# Prefixy strings
|
8
8
|
ipv6 = '::1 '
|
9
9
|
home = '127.0.0.1 '
|
10
10
|
|
11
11
|
# Grab that parser and parse
|
12
12
|
|
13
|
-
conf = Buildhosts::ConfigParser.parse
|
13
|
+
conf = Buildhosts::ConfigParser.parse config
|
14
14
|
|
15
15
|
# Write the lines to a "newhosts" file
|
16
|
-
out = File.open(
|
16
|
+
out = File.open(newhosts, 'w+')
|
17
17
|
conf['hosts'].each do |host|
|
18
18
|
out.write "#{ipv6}#{host}\n"
|
19
19
|
out.write "#{home}#{host}\n"
|
data/lib/buildhosts/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Anderson
|
@@ -51,7 +51,6 @@ files:
|
|
51
51
|
- .ruby-version
|
52
52
|
- Gemfile
|
53
53
|
- LICENSE.txt
|
54
|
-
- README.markdown
|
55
54
|
- README.md
|
56
55
|
- Rakefile
|
57
56
|
- bin/buildhosts
|
data/README.markdown
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
Buildhosts
|
2
|
-
=========
|
3
|
-
|
4
|
-
This is just some info about this script. It will:
|
5
|
-
|
6
|
-
+ change your life
|
7
|
-
+ make you smarter
|
8
|
-
+ grant you three wishes, and
|
9
|
-
+ do none of the above.
|
10
|
-
|
11
|
-
But really, this is just a script I wrote to write my /etc/hosts file for me.
|
12
|
-
Configuring all the entries was a hassle, especially when using [xip.io](http://xip.io).
|
13
|
-
This script takes your local hostnames (and the various IP address you need to pass
|
14
|
-
to xip.io) and create all the necessary entries to access any of the hosts while
|
15
|
-
passing any of the IPs to xip.io.
|
16
|
-
|
17
|
-
### Manginx
|
18
|
-
|
19
|
-
Also included in `manginx`, a script that helps with using xip.io with nginx.
|
20
|
-
|
21
|
-
Installing & Running the Script
|
22
|
-
-------------------------------
|
23
|
-
|
24
|
-
+ BACK UP YOUR CURRENT HOSTS FILE!
|
25
|
-
+ To reiterate, **BACK UP YOUR CURRENT HOSTS FILE!**
|
26
|
-
+ Set shell variable `HOSTSPATH` to the script directory (i.e. ~/git/buildhosts)
|
27
|
-
+ Symlink the `buildhosts.sh` file to `~/bin/hosts` or something
|
28
|
-
+ Use `hosts -e` to edit your config file (explained below and in the `sample-config` file)
|
29
|
-
+ Any custom hosts can be put in a file named `custom`
|
30
|
-
+ Running `hosts` will recompile your `/etc/hosts` file
|
31
|
-
+ Running `hosts -l` will list the entries in your `/etc/hosts` file
|
32
|
-
|
33
|
-
### Example installation:
|
34
|
-
mkdir -p ~/git
|
35
|
-
cd ~/git
|
36
|
-
git clone https://github.com/athaeryn/buildhosts.git
|
37
|
-
sudo cp /etc/hosts /etc/hosts.bak
|
38
|
-
export HOSTSPATH=~/git/buildhosts
|
39
|
-
ln -s ~/git/buildhosts/buildhosts.sh ~/bin/hosts
|
40
|
-
cp sample-config config
|
41
|
-
|
42
|
-
|
43
|
-
About the IP Address Section
|
44
|
-
----------------------------
|
45
|
-
|
46
|
-
The IP section is for working with xip.io, a DNS server that makes testing local
|
47
|
-
websites on mobile devices much simpler. You can read more about it [here](http://xip.io).
|
48
|
-
If you don't want to work with xip.io, don't include IP addresses in your config file (the ampersand is also not necessary).
|
49
|
-
|
50
|
-
Configuring the Script
|
51
|
-
----------------------
|
52
|
-
|
53
|
-
If you run `hosts` with this `config` file:
|
54
|
-
|
55
|
-
### sample-config:
|
56
|
-
|
57
|
-
[hosts]
|
58
|
-
foobar.local
|
59
|
-
example.local
|
60
|
-
[ips]
|
61
|
-
192.168.1.1
|
62
|
-
192.168.0.1
|
63
|
-
10.0.1.1
|
64
|
-
|
65
|
-
it will produce this output:
|
66
|
-
|
67
|
-
### /etc/hosts
|
68
|
-
##
|
69
|
-
# Host Database
|
70
|
-
#
|
71
|
-
# localhost is used to configure the loopback interface
|
72
|
-
# when the system is booting. Do not change this entry.
|
73
|
-
##
|
74
|
-
127.0.0.1 localhost
|
75
|
-
255.255.255.255 broadcasthost
|
76
|
-
::1 localhost
|
77
|
-
fe80::1%lo0 localhost
|
78
|
-
|
79
|
-
::1 example.local
|
80
|
-
127.0.0.1 example.local
|
81
|
-
::1 example.local.10.0.1.1.xip.io
|
82
|
-
127.0.0.1 example.local.10.0.1.1.xip.io
|
83
|
-
::1 example.local.192.168.0.1.xip.io
|
84
|
-
127.0.0.1 example.local.192.168.0.1.xip.io
|
85
|
-
::1 example.local.192.168.1.1.xip.io
|
86
|
-
127.0.0.1 example.local.192.168.1.1.xip.io
|
87
|
-
::1 foobar.local
|
88
|
-
127.0.0.1 foobar.local
|
89
|
-
::1 foobar.local.10.0.1.1.xip.io
|
90
|
-
127.0.0.1 foobar.local.10.0.1.1.xip.io
|
91
|
-
::1 foobar.local.192.168.0.1.xip.io
|
92
|
-
127.0.0.1 foobar.local.192.168.0.1.xip.io
|
93
|
-
::1 foobar.local.192.168.1.1.xip.io
|
94
|
-
127.0.0.1 foobar.local.192.168.1.1.xip.io
|
95
|
-
|
96
|
-
Simple enough? I thought so.
|
97
|
-
|
98
|
-
Manginx
|
99
|
-
-------
|
100
|
-
|
101
|
-
To run manginx, just do `hosts --nginx`.
|
102
|
-
As far as configuring goes, just make sure you have an `xip` directory in the same directory as your `nginx.conf`.
|
103
|
-
Then just duplicate and server_name lines and alter them like so:
|
104
|
-
|
105
|
-
### Before:
|
106
|
-
server_name foobar.local;
|
107
|
-
|
108
|
-
### After:
|
109
|
-
server_name foobar.local;
|
110
|
-
include xip/foobar.local;
|