import importlib.util
from pathlib import Path
import subprocess,sys,base64,os
s=importlib.util.spec_from_file_location('transport','/tmp/codex/ltb1021/2026-09-27_icerti-provider-patch_r01/remote.py')
m=importlib.util.module_from_spec(s);s.loader.exec_module(m)
m.SECRET=Path(os.environ.get('CONTEXTRA_ICERTI_SUDO_FILE','/run/contextra-icerti-sudo.DTs47d/password'))
remote=m.remote
if __name__=='__main__':
    if sys.argv[1]=='--stream':
        script=Path(sys.argv[2]).read_text();m.remote('print("AUTH_CHECKED")',10)
        encoded=base64.b64encode(script.encode()).decode()
        command="sudo -S -p '' python3 -u -B -c \"import base64,os;os.close(0);exec(base64.b64decode('%s'))\""%encoded
        p=subprocess.Popen(m.SSH+[command],stdin=subprocess.PIPE)
        p.stdin.write(m.SECRET.read_bytes());p.stdin.close()
        raise SystemExit(p.wait(timeout=int(sys.argv[3])))
    print(remote(Path(sys.argv[1]).read_text(),int(sys.argv[2]) if len(sys.argv)>2 else 60))
