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

18 lines
1.7 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")
p=app/'lib/frontend/config/main-local.php';s=p.read_text()
if "'catalog/all-products'" not in s:s=s.replace('return $config;',"$config['defaultRoute']='catalog/all-products';\nreturn $config;")
p.write_text(s)
p=app/'includes/application_top.php';s=p.read_text();s=s.replace('error_reporting(E_ALL & ~E_NOTICE);','error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);');p.write_text(s)
subprocess.run(['chown','dunerealms:dunerealms',str(entry),str(app/'dune-login.php')],check=True)
print('Frontend account linking installed; backend roles and permissions unchanged')