1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-22 12:40:40 +08:00

fix update-zone-serial.py

This commit is contained in:
JerryXiao 2021-04-16 14:43:50 +08:00
parent 4362e7c6b0
commit a4d39e8237
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
3 changed files with 35 additions and 28 deletions

View file

@ -16,7 +16,7 @@ check() {
PATH=/sbin:/usr/sbin:$PATH named-checkzone -i local -l 86400 $@ PATH=/sbin:/usr/sbin:$PATH named-checkzone -i local -l 86400 $@
} }
pushd dns pushd generated/dns
check 'neo' neonetwork check 'neo' neonetwork
check '127.10.in-addr.arpa' db.10.127 check '127.10.in-addr.arpa' db.10.127

View file

@ -12,7 +12,9 @@ mkdir -p generated
mkdir -p generated/dns mkdir -p generated/dns
scripts/dns-generator.py scripts/dns-generator.py
scripts/update-zone-serial.py
cp -R dns/* generated/dns cp -R dns/* generated/dns
scripts/check-named-zones.sh
scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -o generated/roa46_bird2.conf scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -o generated/roa46_bird2.conf
scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -4 -o generated/roa4_bird2.conf scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -4 -o generated/roa4_bird2.conf
@ -21,7 +23,3 @@ scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -j -o generated/roa46.json
scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -e -o generated/neonetwork.json scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -e -o generated/neonetwork.json
scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -r -o generated/rfc8416.json scripts/roa.py -m "$MAX_LEN_4" -M "$MAX_LEN_6" -r -o generated/rfc8416.json
scripts/roa.py --summary --output generated/README.md scripts/roa.py --summary --output generated/README.md
scripts/update-zone-serial.py
scripts/check-named-zones.sh

View file

@ -5,8 +5,6 @@ from time import time
from re import match from re import match
from os import chdir from os import chdir
chdir("generated")
zone_files = [ zone_files = [
'neonetwork', 'neonetwork',
'db.10.127', 'db.10.127',
@ -14,28 +12,39 @@ zone_files = [
] ]
serial_base = 1586876035 serial_base = 1586876035
new_serial = int(time()) - serial_base
for zone in zone_files: def update_serial_to(zone: Path, serial: int = 0) -> int:
zone = Path("dns") / zone
assert zone.exists()
p = subprocess.run(['git', 'diff', '--exit-code', str(zone)])
if p.returncode == 0:
print(f"skip {zone.name}")
else:
print(f"update serial {zone.name}")
lines = zone.read_text().split("\n") lines = zone.read_text().split("\n")
processed = list() processed = list()
serial = int(time()) - serial_base assert 0 <= serial <= 2**32
assert 0 < serial <= 2**32
serial = str(serial)
found = False found = False
old_serial = None
for line in lines: for line in lines:
if not found and (m := match(r"^(\s+)([0-9]+)(\s*;\s*Serial\s*)$", line)): if not found and (m := match(r"^(\s+)([0-9]+)(\s*;\s*Serial\s*)$", line)):
prefix, _serial, suffix = m.groups() prefix, old_serial, suffix = m.groups()
print(f"{_serial=} {serial=}") old_serial = int(old_serial)
plen = max(len(prefix) - len(serial) + len(_serial), 0) print(f"{old_serial=} {serial=}")
plen = max(len(prefix) - len(str(serial)) + len(str(old_serial)), 0)
processed.append(f"{' '*plen}{serial}{suffix}") processed.append(f"{' '*plen}{serial}{suffix}")
found = True found = True
else: else:
processed.append(line) processed.append(line)
if serial:
zone.write_text("\n".join(processed)) zone.write_text("\n".join(processed))
return old_serial
for zone in zone_files:
gen_zone = Path("generated") / "dns" / zone
repo_zone = Path("dns") / zone
assert gen_zone.exists()
assert repo_zone.exists()
old_serial = update_serial_to(gen_zone)
update_serial_to(repo_zone, old_serial)
gen_zone.write_text(repo_zone.read_text())
p = subprocess.run(['git', 'diff', '--exit-code', gen_zone.name], cwd=gen_zone.parent)
if p.returncode == 0:
print(f"skip {repo_zone.name}")
else:
print(f"update serial {repo_zone.name}")
update_serial_to(repo_zone, new_serial)