MC/website/ops/oscommerce/setup-osc-account.py

14 lines
1.3 KiB
Python

from pathlib import Path
import subprocess
app=Path('/home/dunerealms/apps/oscommerce')
sql="""CREATE TABLE IF NOT EXISTS dunerealms_oscommerce.dune_account_links(account_id CHAR(36) PRIMARY KEY,customer_id INT NOT NULL UNIQUE);
CREATE TABLE IF NOT EXISTS dunerealms_oscommerce.dune_sso_states(state_hash CHAR(64) PRIMARY KEY,nonce_hash CHAR(64) NOT NULL,next_path VARCHAR(2048) NOT NULL,expires_at BIGINT NOT NULL);
CREATE TABLE IF NOT EXISTS dunerealms_oscommerce.dune_sso_sessions(token_hash CHAR(64) PRIMARY KEY,account_id CHAR(36) NOT NULL,session_ref CHAR(64) NOT NULL,expires_at BIGINT NOT NULL);
"""
subprocess.run(['mysql'],input=sql,text=True,capture_output=True,check=True)
entry=app/'lib/frontend/web/index.php';s=entry.read_text()
if 'DuneAccount' not in s:s=s.replace('$application->run();',"require __DIR__.'/../components/DuneAccount.php';\n(new \\frontend\\components\\DuneAccount())->bootstrap($application);\n$application->run();")
entry.write_text(s)
(app/'dune-login.php').write_text("<?php\n$_SERVER['SCRIPT_NAME']='/catalog/index.php';\n$_SERVER['PHP_SELF']='/catalog/index.php';\nrequire __DIR__.'/index.php';\n")
subprocess.run(['chown','dunerealms:dunerealms',str(entry),str(app/'dune-login.php')],check=True)
print('Frontend account linking installed; backend roles and permissions unchanged')