#!/usr/bin/env python3 """Align candidate EVALSHA with the installed Lua bytes actually loaded by the loader.""" import hashlib from pathlib import Path import re import sys config = Path(sys.argv[1]) script = Path('/etc/opensips/lisglosips_hotpath.lua').read_text() sha = hashlib.sha1(script.encode()).hexdigest() text = config.read_text() matches = re.findall(r'EVALSHA ([0-9a-f]{40}) 1 cfg:active_version', text) assert len(matches) == 1, 'Unexpected hotpath layout' config.write_text(text.replace('EVALSHA ' + matches[0], 'EVALSHA ' + sha)) print('Installed hotpath SHA:', sha, 'previous:', matches[0])