/
check_n_update.py
executable file
·74 lines (62 loc) · 2.24 KB
/
check_n_update.py
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
71
72
73
74
#!/usr/bin/python -u
# -*- coding: utf-8 -*-
# vim: set ts=2 sw=2 et sts=2 ai:
"""
Script to update the DS keys on dlv.isc.org "look asside" DNSSEC system.
"""
import ConfigParser
import color
import os
import subprocess
root = os.path.dirname(__file__)
if not root:
root = "."
root = os.path.realpath(root)
print root
# Load the configuration
configfile = os.path.join(root, 'config.ini')
config = ConfigParser.ConfigParser()
config.readfp(open(configfile))
curdir = os.path.realpath(os.curdir)
for domain in sorted(config.sections()):
if not config.has_option(domain, "publish"):
continue
if not os.path.exists(domain):
print "Could not find directory for %s" % (domain,)
continue
if not os.path.isdir(domain):
print "%s is not a directory!" % (domain,)
continue
print domain
publish_to = config.get(domain, "publish").split(',')
os.chdir(domain)
dnskey_prog = "%s/powerdns_generate_files.py" % (root,)
assert os.path.exists(dnskey_prog)
g = subprocess.Popen("python -u %s %s" % (dnskey_prog, domain), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
for line in g.stdout.xreadlines():
print " ", line.strip()
assert g.wait() == 0
for publisher in publish_to:
check_prog = "%s/check_%s.py" % (root, publisher)
if not os.path.exists(check_prog):
check_prog = "%s/check_root.py" % (root,)
update_prog = "%s/update_%s.py" % (root, publisher)
assert os.path.exists(update_prog), update_prog
print " Checking", publisher
c = subprocess.Popen("python -u %s %s" % (check_prog, domain), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
for line in c.stdout.xreadlines():
print " ", line.strip()
retcode = c.wait()
if retcode != 0:
print color.yellow(" Need to update!")
u = subprocess.Popen("python -u %s %s" % (update_prog, domain), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
for line in u.stdout.xreadlines():
print " ", line.strip()
retcode = u.wait()
if retcode != 0:
print color.red(" Update failed!")
else:
print color.green(" Update successful!")
else:
print color.green(" Everything up to date!")
os.chdir(curdir)