36 lines
1.8 KiB
Bash
36 lines
1.8 KiB
Bash
set -eu
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
import hashlib,os,ast,json
|
|
root=Path('/opt/matrix-screen-controller')
|
|
p=root/'scripts/ota_worker.py'
|
|
original=p.read_bytes()
|
|
assert hashlib.sha256(original).hexdigest()=='3eec0eab7b2ce2bd43f11cccb0ba3063b2c820532d78abc2e06ba3823f8c33e5', 'worker changed; re-inspect before patching'
|
|
status=Path('/run/matrix-screen-controller/ota-status.json')
|
|
assert not status.exists() or not json.loads(status.read_text()).get('active'), 'OTA currently active'
|
|
s=original.decode('utf-8')
|
|
old=' frpc_bundle = self.extract_root / "system-dependencies/frpc"'
|
|
new=' frpc_bundle = software / "system-dependencies/frpc"\n if not frpc_bundle.is_dir():\n frpc_bundle = self.extract_root / "system-dependencies/frpc"'
|
|
assert s.count(old)==1
|
|
s=s.replace(old,new)
|
|
start=s.index(' self.backup_frpc_system()')
|
|
end=s.index(' self.run(["systemctl", "daemon-reload"]',start)
|
|
legacy=s[start:end]
|
|
replacement=' if (self.release / "scripts/ota_components.py").is_file():\n # Candidate migration has already prepared the durable transaction.\n pass\n else:\n'
|
|
replacement += ''.join(' '+line+'\n' for line in legacy.splitlines())
|
|
s=s[:start]+replacement+s[end:]
|
|
ast.parse(s)
|
|
backup=Path('/var/tmp/matrix-ota110-validation/development-worker-before.py')
|
|
backup.write_bytes(original)
|
|
body=s.encode('utf-8')
|
|
temp=p.with_name('.ota_worker.compat.tmp')
|
|
with temp.open('wb') as f:
|
|
f.write(body);f.flush();os.fsync(f.fileno())
|
|
os.chmod(temp,p.stat().st_mode & 0o777)
|
|
os.replace(temp,p)
|
|
print('development_worker_compatibility_patched=true')
|
|
print('software_version='+ (root/'VERSION').read_text().strip())
|
|
print('worker_sha256='+hashlib.sha256(p.read_bytes()).hexdigest())
|
|
print('FRP binary/config and running services unchanged')
|
|
PY
|