Skip to content

Instantly share code, notes, and snippets.

@hisui
Last active September 7, 2016 05:45
Show Gist options
  • Save hisui/2c9e9fe859a7b35404bb0e4ac67983af to your computer and use it in GitHub Desktop.
Save hisui/2c9e9fe859a7b35404bb0e4ac67983af to your computer and use it in GitHub Desktop.
#!/bin/sh
DNS_SERVER=127.0.0.1
# Appends $DNS_SERVER to the DNS server list.
cat /etc/resolv.conf | awk '/^\s*nameserver\W/ { print $2 }' | xargs -J '%' sudo networksetup -setdnsservers 'Wi-Fi' '%' $DNS_SERVER
# Flushes DNS resolver caches.
sudo killall -HUP mDNSResponder
#!/usr/local/bin/ruby
##
## Get host name and IP address pairs from GCP
##
GCP_APPS = %w(compute sql)
hosts = GCP_APPS.flat_map do |app|
`gcloud #{app} instances list 2>&- | tail -n +2`.lines.map { |e|
e.split(/\s+/).values_at(0, 3)
}
end
##
## Setup zone records
##
ZoneRecord = Struct.new :name, :ttl, :record_class, :record_type, :data
records = []
records << ZoneRecord.new("@", "", "IN", "SOA", %q(local. root.local. (
2002122001 ; Serial
3600 ; Refresh
900 ; Retry
604800 ; Expire
86400 ; Minimum
)))
LOCAL_IP_ADDR = "127.0.0.1"
records << ZoneRecord.new( "", "", "IN", "NS", "dns.local.")
records << ZoneRecord.new("dns", "", "IN", "A", LOCAL_IP_ADDR)
records.concat(hosts.map { |name, ip_addr|
ZoneRecord.new(name, "", "IN", "A", ip_addr)
})
##
## Output zone config
##
rows = records.map(&:to_a)
cols = (0...rows.map(&:size).max).map do |col|
rows.map { |r| (r[col] || "").size }.max
end
puts "$TTL 86400"
rows.each do |r|
puts r.zip(cols).map { |e, n| "%- #{n + 4}s" % e }.join("").rstrip
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment