Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (25 sloc) 805 Bytes
#!/usr/bin/env ruby
require 'yaml'
require 'resolv'
require 'json'
require 'open-uri'
HOSTNAME = "home.hollensbe.org"
JSONIP_SERVICE = "http://jsonip.hollensbe.org"
DNS_INFO = YAML.load_file(ENV["TEST"] ? "dns_info.yaml" : "/etc/dns_info.yaml")
ip = JSON.load(open(JSONIP_SERVICE).read)["ip"] rescue nil
resolved_ip = Resolv.getaddress(HOSTNAME) rescue nil
if ip.nil? or resolved_ip.nil? or ip != resolved_ip
puts "Updating #{HOSTNAME} to be ip '#{ip}' (previously '#{resolved_ip}')"
IO.popen("nsupdate -y #{DNS_INFO["key"]}:#{DNS_INFO["secret"]} -v", 'r+') do |f|
f << <<-EOF
server #{DNS_INFO["server"]}
zone #{DNS_INFO["key"]}
update delete #{HOSTNAME} A
update add #{HOSTNAME} 60 A #{ip}
show
send
EOF
f.close_write
puts f.read
end
end