mirror of
https://github.com/NeoCloud/NeoNetwork
synced 2024-11-22 06:50:41 +08:00
fix update-zone-serial.py
This commit is contained in:
parent
4362e7c6b0
commit
a4d39e8237
3 changed files with 35 additions and 28 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
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:
|
for zone in zone_files:
|
||||||
zone = Path("dns") / zone
|
gen_zone = Path("generated") / "dns" / zone
|
||||||
assert zone.exists()
|
repo_zone = Path("dns") / zone
|
||||||
p = subprocess.run(['git', 'diff', '--exit-code', str(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:
|
if p.returncode == 0:
|
||||||
print(f"skip {zone.name}")
|
print(f"skip {repo_zone.name}")
|
||||||
else:
|
else:
|
||||||
print(f"update serial {zone.name}")
|
print(f"update serial {repo_zone.name}")
|
||||||
lines = zone.read_text().split("\n")
|
update_serial_to(repo_zone, new_serial)
|
||||||
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))
|
|
||||||
|
|
Loading…
Reference in a new issue