45 lines
2.0 KiB
Bash
45 lines
2.0 KiB
Bash
set -eu
|
|
ROOT=/var/tmp/matrix-ota110-validation
|
|
export ROOT
|
|
mkdir -p "$ROOT/fs/sudoers"
|
|
python3 - "$ROOT/fs/sudoers/90-matrix-screen-controller-account" <<'PY'
|
|
from pathlib import Path
|
|
import re,pwd,sys
|
|
text=Path('/etc/systemd/system/matrix-screen-frpc.service.d/user.conf').read_text(encoding='utf-8')
|
|
users=re.findall(r'^User=([a-zA-Z0-9_-]+)$',text,re.M)
|
|
assert len(users)==1 and pwd.getpwnam(users[0]).pw_uid!=0
|
|
Path(sys.argv[1]).write_text(users[0]+' ALL=(ALL:ALL) ALL'+chr(10),encoding='utf-8')
|
|
PY
|
|
mkdir -p "$ROOT/fs/opt" "$ROOT/fs/varlib" "$ROOT/fs/run" "$ROOT/fs/bin" "$ROOT/fs/units" "$ROOT/fake-bin"
|
|
cat > "$ROOT/fake-bin/systemctl" <<'PY'
|
|
#!/usr/bin/python3
|
|
import sys,json
|
|
from pathlib import Path
|
|
if Path(sys.argv[0]).name=='systemd-run': sys.exit(0)
|
|
args=sys.argv[1:];state_path=Path('/run/fake-systemctl.json')
|
|
state=json.loads(state_path.read_text()) if state_path.exists() else {}
|
|
cmd=args[0] if args else '';unit=args[-1] if args else ''
|
|
if cmd in ('is-active','is-enabled'): sys.exit(0 if state.get(unit,{}).get('active' if cmd=='is-active' else 'enabled',False) else 1)
|
|
if cmd=='show': print('inactive')
|
|
if cmd in ('enable','disable','start','stop'):
|
|
if cmd=='start' and state.get('start_fail_once')==unit:
|
|
del state['start_fail_once'];state_path.write_text(json.dumps(state));sys.exit(1)
|
|
entry=state.setdefault(unit,{})
|
|
entry['active' if cmd in ('start','stop') else 'enabled']=cmd in ('start','enable')
|
|
state_path.write_text(json.dumps(state))
|
|
sys.exit(0)
|
|
PY
|
|
cp "$ROOT/fake-bin/systemctl" "$ROOT/fake-bin/systemd-run"
|
|
chmod 755 "$ROOT/fake-bin/systemctl" "$ROOT/fake-bin/systemd-run"
|
|
export PATH="$ROOT/fake-bin:$PATH"
|
|
unshare --mount --propagation private /bin/sh -c '
|
|
set -eu
|
|
mount --bind "$ROOT/fs/opt" /opt
|
|
mount --bind "$ROOT/fs/varlib" /var/lib
|
|
mount --bind "$ROOT/fs/run" /run
|
|
mount --bind "$ROOT/fs/bin" /usr/local/bin
|
|
mount --bind "$ROOT/fs/units" /etc/systemd/system
|
|
mount --bind "$ROOT/fs/sudoers" /etc/sudoers.d
|
|
python3 "$ROOT/${TEST_SCRIPT:-ota110_integration.py}" ${TEST_ARG:-}
|
|
'
|