from pathlib import Path
path = Path("/etc/caddy/Caddyfile")
text = path.read_text()
block = r"""

# private.tap365.org -> SublB privacy agreement static page
private.tap365.org {
    root * /srv/private.tap365.org
    encode zstd gzip

    @html path / /privacy.html
    header @html Cache-Control "no-cache, no-store, must-revalidate"

    handle / {
        rewrite * /privacy.html
        file_server
    }

    handle {
        try_files {path} /privacy.html
        file_server
    }

    log {
        output file /var/log/caddy/private.tap365.org.log {
            roll_size 50mb
            roll_keep 5
        }
        format json
    }
}
"""
if "private.tap365.org" not in text:
    path.write_text(text.rstrip() + block + "\n")
else:
    print("private.tap365.org already exists; no change")
