#!/usr/bin/env bash set -euo pipefail REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}" ssh "$REMOTE_HOST" 'python3 -' <<'PY' from pathlib import Path import subprocess config = Path('/etc/caddy/Caddyfile') old = ''' @backend path /status /api/status /ws /ws/* /api/files/user-server /api/files/prepare /api/dm-files/prepare /files/* /dm-files/* handle @backend { reverse_proxy 127.0.0.1:7105 } handle { root * /home/player/SHiNE/main/UI try_files {path} {path}/index.html /index.html file_server } }''' new = ''' @backend path /status /api/status /ws /ws/* /api/files/user-server /api/files/prepare /api/dm-files/prepare /dm-files/* handle @backend { reverse_proxy 127.0.0.1:7105 } @publicFilesRead { method GET HEAD path_regexp public_file ^/files/[0-9a-f]{64}$ } handle @publicFilesRead { uri strip_prefix /files root * /home/player/SHiNE/main/server/data/public-files header { Cache-Control "public, max-age=31536000, immutable" Access-Control-Allow-Origin "*" Cross-Origin-Resource-Policy "cross-origin" } file_server } @publicFilesWrite { method PUT OPTIONS path /files/* } handle @publicFilesWrite { reverse_proxy 127.0.0.1:7105 } handle { root * /home/player/SHiNE/main/UI try_files {path} {path}/index.html /index.html file_server header -Etag header { Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Pragma "no-cache" Expires "0" } } }''' text = config.read_text() if text.count(old) != 1: raise SystemExit('Expected shineup.me Caddy block not found exactly once') Path('/home/player/SHiNE/main/server/data/public-files').mkdir(parents=True, exist_ok=True) subprocess.run(['sudo', '-n', 'cp', str(config), '/etc/caddy/Caddyfile.before-shine-main-align'], check=True) tmp = Path('/tmp/shine-main-Caddyfile-align') tmp.write_text(text.replace(old, new)) subprocess.run(['sudo', '-n', 'install', '-o', 'player', '-g', 'player', '-m', '0664', str(tmp), str(config)], check=True) tmp.unlink() PY ssh "$REMOTE_HOST" 'sudo -n systemctl reload caddy; sudo -n systemctl is-active --quiet caddy'