1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-12-23 07:39:23 +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 $@
}
pushd dns
pushd generated/dns
check 'neo' neonetwork
check '127.10.in-addr.arpa' db.10.127

View file

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