#!/usr/bin/env bash set -euo pipefail REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}" ssh "$REMOTE_HOST" 'sudo -n python3 -' <<'PY' from pathlib import Path import os, shutil source = Path('/etc/shine/shine-t2.env') target = Path('/etc/shine/shine-main.env') if target.exists(): raise SystemExit('Main environment file already exists; refusing to overwrite') key_lines = [l for l in source.read_text().splitlines() if l.startswith('RESEND_API_KEY=')] if len(key_lines) != 1 or not key_lines[0].split('=', 1)[1].strip(): raise SystemExit('Resend API key not available on t2') fd = os.open(target, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600) with os.fdopen(fd, 'w') as stream: stream.write(key_lines[0] + '\n') os.chown(target, 0, 0) props = Path('/home/player/SHiNE/main/server/application.properties') backup = props.with_name('application.properties.before-external-registrar') if backup.exists(): raise SystemExit('Registrar backup already exists; refusing to overwrite') text = props.read_text() required = { 'freeRegistration.enabled': 'true', 'freeRegistration.namespace': 'free', 'freeRegistration.signerMode': 'external', 'freeRegistration.email.allowTestCode': 'false', 'freeRegistration.email.allowReuse': 'false', 'server.SHiNE.login': 'shineupme@shine', } shutil.copy2(props, backup) lines = [] seen = set() for line in text.splitlines(): name = line.split('=', 1)[0].strip() if name in required: lines.append(name + '=' + required[name]) seen.add(name) else: lines.append(line) for name, value in required.items(): if name not in seen: lines.append(name + '=' + value) props.write_text('\n'.join(lines) + '\n') props.chmod(0o600) print('External registrar configuration prepared') PY ssh "$REMOTE_HOST" 'sudo -n mkdir -p /etc/systemd/system/shine-main.service.d; sudo -n tee /etc/systemd/system/shine-main.service.d/registrar-env.conf >/dev/null' <<'EOF' [Service] EnvironmentFile=/etc/shine/shine-main.env EOF ssh "$REMOTE_HOST" 'sudo -n systemctl daemon-reload'