24 lines
1.2 KiB
Bash
24 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
# Close only this window; preserve user data and all accounting history.
|
|
set -u
|
|
BASE=/opt/cybergril-hel913
|
|
UNIT=cybergril-hel913-user
|
|
rc=0
|
|
rm -f "$BASE/window-active"
|
|
HEL913_BASE="$BASE" bash "$BASE/current/deploy/hel913-unified/force_end.template.sh" now || rc=1
|
|
systemctl stop "$UNIT.service" || rc=1
|
|
systemctl disable "$UNIT.service" || rc=1
|
|
systemctl stop "$UNIT-expiry.timer" || rc=1
|
|
systemctl disable "$UNIT-expiry.timer" || rc=1
|
|
if [ -f "$BASE/data/companion.db" ]; then
|
|
"$BASE/venv311/bin/python" "$BASE/current/tools/seal_budget_hel879.py" --db "$BASE/data/companion.db" --reason 'approved first-use window closed' || rc=1
|
|
"$BASE/venv311/bin/python" "$BASE/current/tools/release_snapshot_hel896.py" snapshot --name "user-window-$(date -u +%Y%m%dT%H%M%SZ)" --db "$BASE/data/companion.db" --file "$BASE/data" --out "$BASE/archives" || rc=1
|
|
fi
|
|
"$BASE/venv311/bin/python" - "$BASE/window.json" "$rc" <<'PY'
|
|
import datetime,json,pathlib,sys
|
|
p=pathlib.Path(sys.argv[1])
|
|
if p.exists():
|
|
w=json.loads(p.read_text());w['closed_at']=datetime.datetime.now(datetime.timezone.utc).isoformat();w['close_exit_code']=int(sys.argv[2]);p.write_text(json.dumps(w,indent=2)+'\n')
|
|
PY
|
|
exit "$rc"
|