Created
June 21, 2010 22:36
-
-
Save smathy/447630 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
section_start = '## devstart -- section marker - do not touch' | |
section_end = '## devend -- section marker - do not touch' | |
ips = { | |
:juan => '3.40', | |
:jose => '3.138', | |
:alejandro => '3.139', | |
:roberto => '3.140', | |
:alex => '3.157', | |
:javier => '2.221', | |
:jason => '2.222', | |
:ian => '2.227', | |
:paul => '2.225', | |
:oli => '2.228' | |
} | |
apps = %w{ao av aw se th} | |
prepared_block = | |
"#{section_start}\n" + | |
ips.map do |name, ip| | |
"192.168.#{ip} " + | |
apps.map do |app| | |
"#{name}.#{app}.dev" | |
end.join(' ') | |
end.join("\n") + | |
"\n#{section_end}" | |
contents = File.read('/etc/hosts') | |
unless( contents.sub!( /#{section_start}.*#{section_end}/m, prepared_block )) | |
contents += "\n#{prepared_block}\n" | |
end | |
File.open('/etc/hosts', 'w') do |io| | |
io.puts contents | |
end | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment