buildhosts 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 221c73813e4781338e4a66d5ec3cce48b07559ea
4
+ data.tar.gz: 95df595ecfec9bc4db1685c86a50356a055ac205
5
+ SHA512:
6
+ metadata.gz: 4c50b83175c36cfb7523898ef68d3bb01da46c48e72a0e04839f1f68fb0b4674871c7dfc8c44db9097f28ead0f1e81a44f5fc17215922775a43a668a9a2363aa
7
+ data.tar.gz: bf9b2a7c95d6ec818f9a2c9d6dca19f5b86f78dd2d67f9c47a53785c7d1e25fcbf1d201e72ff72d75dcf2f4aa316b7c37a35f1bd51a93929af14ecca4d0b209f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ buildhosts
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in buildhosts.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mike Anderson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,110 @@
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;
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Buildhosts
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'buildhosts'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install buildhosts
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/buildhosts ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'buildhosts'
4
+
5
+ case ARGV[0]
6
+ when "-e"
7
+ system("vim config")
8
+ when "-c"
9
+ system("vim custom")
10
+ when "-ec"
11
+ system("vim config ; vim custom")
12
+ when "-ce"
13
+ system("vim custom ; vim config")
14
+ when "-l"
15
+ system("grep 127.0.0.1 /etc/hosts | grep -Ev 'xip.io|localhost' | awk '{print $2}'")
16
+ exit
17
+ when "--nginx", "-nginx"
18
+ puts "Will run manginx"
19
+ puts "Then reload nginx"
20
+ exit
21
+ else
22
+ puts "Usage: "
23
+ exit
24
+ end
25
+
26
+ puts "Building..."
27
+ Buildhosts::Main.build
28
+ system("")
29
+ system("cat header custom newhosts > temp")
30
+ system("sudo cp temp /etc/hosts")
31
+ system("rm newhosts temp")
32
+ 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
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'buildhosts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "buildhosts"
8
+ spec.version = Buildhosts::VERSION
9
+ spec.authors = ["Mike Anderson"]
10
+ spec.email = ["athaeryn@me.com"]
11
+ spec.description = "Buildhosts."
12
+ spec.summary = "A utiliy for managing hosts (and IPs for xip.io)."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/config ADDED
@@ -0,0 +1,13 @@
1
+ [hosts]
2
+ macmurray.local
3
+ allegheny.local
4
+ ecochair.local
5
+ echair2013.local
6
+ usb.local
7
+ blp.local
8
+ hdvisa.local
9
+ indian.local
10
+ gitlife.mrmikea.local
11
+ [ips]
12
+ 192.168.200.110
13
+
data/custom ADDED
File without changes
data/header ADDED
@@ -0,0 +1,11 @@
1
+ ##
2
+ # Host Database
3
+ #
4
+ # localhost is used to configure the loopback interface
5
+ # when the system is booting. Do not change this entry.
6
+ ##
7
+ 127.0.0.1 localhost
8
+ 255.255.255.255 broadcasthost
9
+ ::1 localhost
10
+ fe80::1%lo0 localhost
11
+
@@ -0,0 +1,25 @@
1
+ module Buildhosts
2
+ class ConfigParser
3
+ def self.parse file
4
+ if !File.exists? file
5
+ puts "Error: File does not exist."
6
+ return false
7
+ end
8
+ conf = Hash.new
9
+ last_key = String.new
10
+ raw = File.open(file, "r")
11
+ raw.each_line do |line|
12
+ match = line.match(/\[(\w*)\]/)
13
+ if !match.nil?
14
+ key = match.to_a[1..-1][0]
15
+ conf [key] = Array.new
16
+ last_key = key
17
+ else
18
+ conf[last_key] << line.strip if (!line.strip.empty?)
19
+ end
20
+ end
21
+ raw.close
22
+ return conf
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,56 @@
1
+ # Start by load the config parser
2
+ require './ConfigParser.rb'
3
+
4
+ # Helper methods to print common messages
5
+ def configuring what
6
+ puts "Configuring: #{what}..."
7
+ end
8
+
9
+ def done next_step=''
10
+ puts "Done! #{next_step}"
11
+ end
12
+
13
+ # Set up teh parser and parse with it
14
+ parser = ConfigParser.new
15
+ conf = parser.parse 'config'
16
+
17
+ # If you don't have any IP addresses in your config, what are you doing here?
18
+ if conf['ips'].nil? || conf['ips'].empty?
19
+ puts 'What\'s the point?'
20
+ exit
21
+ end
22
+
23
+ # Let's find out what nginx is expecting from us...
24
+ expected = Array.new
25
+ n = File.open('/usr/local/etc/nginx/nginx.conf', 'r')
26
+ n.each_line do |line|
27
+ # So basically, if the line goes "include xip/derp.local;", we want to
28
+ # set up a file with that name with the appropriate server_name directives.
29
+ match = line.match(/include\s+xip\/([\w\.]+);/)
30
+ if !match.nil? # We don't want to try to convert nil to an array...
31
+ expected << match.to_a[1..-1][0]
32
+ end
33
+ end
34
+
35
+ # This is where the files will be stored.
36
+ base_path = '/usr/local/etc/nginx/xip'
37
+ `rm #{base_path}/*`
38
+
39
+ # Le bread and buttere
40
+ expected.each do |file|
41
+ configuring file
42
+ out = File.open("#{base_path}/#{file}", 'w+')
43
+ conf['ips'].each do |ip|
44
+ # Simple. Just put a line in there for each IP in our config file.
45
+ out.write "server_name #{file}.#{ip}.xip.io;\n"
46
+ end
47
+ out.close
48
+ end
49
+
50
+ # Now we just reload nginx and apologize if something goes rotten.
51
+ done 'Reloading nginx...'
52
+ if system('nginx -s reload')
53
+ done
54
+ else
55
+ puts "Oops!\nSomething went wrong... Sorry."
56
+ end
@@ -0,0 +1,3 @@
1
+ module Buildhosts
2
+ VERSION = "0.0.1"
3
+ end
data/lib/buildhosts.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "buildhosts/version"
2
+ require "buildhosts/ConfigParser"
3
+
4
+ module Buildhosts
5
+ class Main
6
+ def self.build
7
+ # Prefixy strings
8
+ ipv6 = '::1 '
9
+ home = '127.0.0.1 '
10
+
11
+ # Grab that parser and parse
12
+
13
+ conf = Buildhosts::ConfigParser.parse 'config'
14
+
15
+ # Write the lines to a "newhosts" file
16
+ out = File.open('newhosts', 'w+')
17
+ conf['hosts'].each do |host|
18
+ out.write "#{ipv6}#{host}\n"
19
+ out.write "#{home}#{host}\n"
20
+ conf['ips'].each do |ip|
21
+ out.write "#{ipv6}#{host}.#{ip}.xip.io\n"
22
+ out.write "#{home}#{host}.#{ip}.xip.io\n"
23
+ end
24
+ end
25
+ out.close
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
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 ADDED
@@ -0,0 +1,15 @@
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
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildhosts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Anderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Buildhosts.
42
+ email:
43
+ - athaeryn@me.com
44
+ executables:
45
+ - buildhosts
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - .ruby-gemset
51
+ - .ruby-version
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.markdown
55
+ - README.md
56
+ - Rakefile
57
+ - bin/buildhosts
58
+ - buildhosts.gemspec
59
+ - config
60
+ - custom
61
+ - header
62
+ - lib/buildhosts.rb
63
+ - lib/buildhosts/ConfigParser.rb
64
+ - lib/buildhosts/manginx.rb
65
+ - lib/buildhosts/version.rb
66
+ - lib/old.buildhosts.rb
67
+ - sample-config
68
+ homepage: ''
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.0.3
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: A utiliy for managing hosts (and IPs for xip.io).
92
+ test_files: []