-
Notifications
You must be signed in to change notification settings - Fork 1
/
zsync
executable file
·70 lines (56 loc) · 1.55 KB
/
zsync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
require 'yaml'
require 'open3'
require 'tempfile'
require 'optparse'
require 'pp'
options = { debug: false }
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options] [--] <domain>"
opts.separator ""
opts.separator "Specific options:"
opts.on("-d", "--debug", "Print debug messages") do |d|
options[:debug] = d
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
option_parser.parse!
unless ARGV.size == 1
raise "domain name argument is required"
end
zone = ARGV[0]
conf = YAML.load(File.read('zones.yaml'))
unless conf.has_key?('primary')
raise "zones.yaml is broken, yo"
end
unless conf['primary'].has_key?(zone)
raise "unknown domain name #{zone}"
end
unless conf['primary'][zone].has_key?('path')
raise "zones.yaml is broken, yo"
end
path = conf['primary'][zone]['path']
output, status = Open3.capture2("./cli53-linux-amd64 export #{zone}")
pp output if options[:debug]
unless status == 0
raise "#{status} output: #{output}"
end
File.open(path, 'w') {|f| f.write(output) }
generic = output.gsub(/^\$ORIGIN #{zone}./, '')
Tempfile.open("#{zone}-generic.zone") do |tmp|
tmp.write(generic)
tmp.flush
unless conf['primary'][zone].has_key?('shadow')
raise "zones.yaml is broken, yo"
end
conf['primary'][zone]['shadow'].each do |szone|
output, status = Open3.capture2("./cli53-linux-amd64 import -d --replace --file #{tmp.path} #{szone}")
pp output if options[:debug]
unless status == 0
raise "#{status} output: #{output}"
end
end
end