41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Stdlib-only silent bootstrap; reserves a new safe receipt before imports."""
|
||
|
|
import importlib.util
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
import sys
|
||
|
|
from datetime import datetime,timezone
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
receipt=None
|
||
|
|
fd=None
|
||
|
|
try:
|
||
|
|
for index,arg in enumerate(sys.argv[1:],start=1):
|
||
|
|
if arg=='--receipt' and index+1<len(sys.argv):
|
||
|
|
receipt=Path(sys.argv[index+1])
|
||
|
|
elif arg.startswith('--receipt='):
|
||
|
|
receipt=Path(arg.split('=',1)[1])
|
||
|
|
if receipt is None or receipt.is_symlink():
|
||
|
|
return 1
|
||
|
|
fd=os.open(receipt,os.O_CREAT|os.O_EXCL|os.O_WRONLY,0o600)
|
||
|
|
result={'ok':False,'status':'started','stage':'helper_import','recorded_at':datetime.now(timezone.utc).isoformat()}
|
||
|
|
os.write(fd,json.dumps(result).encode());os.fsync(fd);os.close(fd);fd=None
|
||
|
|
spec=importlib.util.spec_from_file_location('custody_finish',Path(__file__).with_name('root_custody_finish.py'))
|
||
|
|
helper=importlib.util.module_from_spec(spec);spec.loader.exec_module(helper)
|
||
|
|
return helper.main(receipt_reserved=True)
|
||
|
|
except FileExistsError:
|
||
|
|
return 1
|
||
|
|
except BaseException:
|
||
|
|
if receipt is not None:
|
||
|
|
try:
|
||
|
|
if fd is not None:os.close(fd)
|
||
|
|
result={'ok':False,'status':'failed','stage':'helper_import','error_code':'helper_startup_failed','recorded_at':datetime.now(timezone.utc).isoformat()}
|
||
|
|
with receipt.open('w') as out:json.dump(result,out);out.flush();os.fsync(out.fileno())
|
||
|
|
except Exception:pass
|
||
|
|
return 1
|
||
|
|
|
||
|
|
|
||
|
|
if __name__=='__main__':raise SystemExit(main())
|