初始化奇妙小屏幕控制器项目
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from pathlib import Path
|
||||
import importlib.util, json, os, shutil, subprocess, sys
|
||||
ROOT=Path(__file__).resolve().parent
|
||||
seed=ROOT/'seed/software'
|
||||
sys.path.insert(0,str(seed))
|
||||
spec=importlib.util.spec_from_file_location('latest_components',ROOT/'latest/ota_components.py')
|
||||
c=importlib.util.module_from_spec(spec);spec.loader.exec_module(c)
|
||||
for root in (Path('/opt'),Path('/var/lib'),Path('/run'),Path('/usr/local/bin'),Path('/etc/systemd/system')):
|
||||
for path in root.iterdir():
|
||||
if path.is_dir() and not path.is_symlink(): shutil.rmtree(path)
|
||||
else: path.unlink()
|
||||
c.DATA.mkdir();c.TARGET.mkdir();c.RELEASES.mkdir();c.RUNTIME.mkdir(parents=True)
|
||||
(c.TARGET/'VERSION').write_text('1.0.6',encoding='utf-8')
|
||||
for name in ('app-unit','ota-unit'): c.FILES[name].write_bytes(('old '+name).encode())
|
||||
source=c.RELEASES/'1.1.0-supplement'
|
||||
shutil.copytree(seed,source)
|
||||
for name in ('ota_components.py','install_frpc_system.sh'):
|
||||
shutil.copy2(ROOT/'latest'/name,source/'scripts'/name)
|
||||
env=os.environ.copy();env['FRPC_RUN_USER']=c.account();env['FRPC_BUNDLE']=str(source/'system-dependencies/frpc')
|
||||
installer=['/bin/sh',str(source/'scripts/install_frpc_system.sh')]
|
||||
subprocess.run(installer,env=env,check=True,capture_output=True)
|
||||
active=c.DATA/'frp/active.env';active.write_bytes(b'# isolated fixture\n');active.chmod(0o600)
|
||||
state=Path('/run/fake-systemctl.json');state.write_text(json.dumps({c.FRP:{'active':True,'enabled':True}}),encoding='utf-8')
|
||||
before=c.FILES['frpc'].stat().st_mtime_ns
|
||||
subprocess.run(installer,env=env,check=True,capture_output=True)
|
||||
assert before==c.FILES['frpc'].stat().st_mtime_ns
|
||||
c.check_installed(source,'1.1.0')
|
||||
assert active.stat().st_mode & 0o777 == 0o600
|
||||
assert json.loads(state.read_text(encoding='utf-8'))[c.FRP]=={'active':True,'enabled':True}
|
||||
print('PASS: final installer idempotence, active.env 0600, active/enabled state preserved')
|
||||
original=c.FILES['frpc'].read_bytes()
|
||||
c.FILES['frpc'].write_bytes(b'corrupt-before-OTA')
|
||||
candidate=c.DATA.with_name('matrix-screen-controller.ota.supplement');shutil.copytree(c.DATA,candidate)
|
||||
request={'schema_version':1,'job_id':'supplement','current_version':'1.0.6','target_version':'1.1.0','accepted_at':'2026-09-07T00:00:00Z'}
|
||||
(c.RUNTIME/'ota-request.json').write_text(json.dumps(request),encoding='utf-8')
|
||||
c.begin(source,candidate)
|
||||
assert c.FILES['frpc'].read_bytes()==original
|
||||
c.finish(boot=True)
|
||||
assert c.FILES['frpc'].read_bytes()==b'corrupt-before-OTA'
|
||||
assert active.read_bytes()==b'# isolated fixture\n'
|
||||
assert active.stat().st_mode & 0o777 == 0o600
|
||||
assert json.loads(state.read_text(encoding='utf-8'))[c.FRP]=={'active':True,'enabled':True}
|
||||
assert not (c.DATA/c.JOURNAL).exists()
|
||||
print('PASS: final component transaction repairs then exactly restores preinstalled FRP and permissions on failure')
|
||||
Reference in New Issue
Block a user