Skip to content

Instantly share code, notes, and snippets.

@smathy
Created September 21, 2010 18:07
Show Gist options
  • Save smathy/590162 to your computer and use it in GitHub Desktop.
Save smathy/590162 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
section_start = '## devstart -- section marker - do not touch'
section_end = '## devend -- section marker - do not touch'
ips = {
:vidal => '3.141',
:jose => '3.138',
:alejandro => '3.139',
:roberto => '3.140',
:alex => '3.157',
:javier => '2.221',
:jason => '2.222',
:ian => '2.227',
:ulises => '2.224',
:juozas => '2.235'
}
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