mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 15:46:18 +01:00
Compare commits
No commits in common. "e262ea1d35c06f63a9400ca4732752b92727dd16" and "8aa3e7d9622d22cefc01fa8022bf9f2cd79f670a" have entirely different histories.
e262ea1d35
...
8aa3e7d962
@ -1,402 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Adding SyncYomi to a one-edge home server</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #ffffff; --fg: #1b1f24; --muted: #5b6470; --card: #f6f8fa;
|
||||
--border: #d8dee4; --accent: #4f46e5; --accent-soft: #eef0ff;
|
||||
--ok: #1a7f37; --ok-soft: #e6f4ea; --bad: #b42318; --bad-soft: #fdecea;
|
||||
--code: #0b1020; --code-fg: #e6e6e6; --pill: #eaeef2;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #0d1117; --fg: #e6edf3; --muted: #9aa5b1; --card: #161b22;
|
||||
--border: #2a323c; --accent: #a5b4fc; --accent-soft: #1c2030;
|
||||
--ok: #4ac776; --ok-soft: #12261a; --bad: #ff7b72; --bad-soft: #2a1615;
|
||||
--code: #010409; --code-fg: #e6edf3; --pill: #1c2430;
|
||||
}
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #0d1117; --fg: #e6edf3; --muted: #9aa5b1; --card: #161b22;
|
||||
--border: #2a323c; --accent: #a5b4fc; --accent-soft: #1c2030;
|
||||
--ok: #4ac776; --ok-soft: #12261a; --bad: #ff7b72; --bad-soft: #2a1615;
|
||||
--code: #010409; --code-fg: #e6edf3; --pill: #1c2430;
|
||||
}
|
||||
:root[data-theme="light"] {
|
||||
--bg: #ffffff; --fg: #1b1f24; --muted: #5b6470; --card: #f6f8fa;
|
||||
--border: #d8dee4; --accent: #4f46e5; --accent-soft: #eef0ff;
|
||||
--ok: #1a7f37; --ok-soft: #e6f4ea; --bad: #b42318; --bad-soft: #fdecea;
|
||||
--code: #0b1020; --code-fg: #e6e6e6; --pill: #eaeef2;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0; background: var(--bg); color: var(--fg);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.65; font-size: 17px;
|
||||
}
|
||||
.wrap { max-width: min(48rem, 92vw); margin: 0 auto; padding: 2.2rem 0 5rem; }
|
||||
h1 { font-size: 1.85rem; line-height: 1.2; margin: 0 0 .3rem; }
|
||||
h2 { font-size: 1.35rem; margin: 2.6rem 0 .7rem; padding-top: .4rem; }
|
||||
h3 { font-size: 1.05rem; margin: 1.6rem 0 .4rem; }
|
||||
p { margin: .7rem 0; }
|
||||
a { color: var(--accent); }
|
||||
.sub { color: var(--muted); font-size: 1.02rem; margin-top: 0; }
|
||||
code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: .88em;
|
||||
background: var(--pill); padding: .1em .38em; border-radius: 5px; }
|
||||
pre { background: var(--code); color: var(--code-fg); border-radius: 10px;
|
||||
padding: 1rem 1.1rem; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
|
||||
font-size: .82rem; line-height: 1.55; border: 1px solid var(--border); }
|
||||
pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
|
||||
.toc { background: var(--card); border: 1px solid var(--border); border-radius: 12px;
|
||||
padding: 1rem 1.2rem; margin: 1.6rem 0; }
|
||||
.toc ol { margin: .3rem 0 0; padding-left: 1.2rem; }
|
||||
.toc li { margin: .2rem 0; }
|
||||
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px;
|
||||
padding: 1.1rem 1.2rem; margin: 1.1rem 0; }
|
||||
.note { border-left: 4px solid var(--accent); background: var(--accent-soft);
|
||||
border-radius: 0 10px 10px 0; padding: .7rem 1rem; margin: 1.1rem 0; }
|
||||
.pill { display: inline-block; background: var(--pill); border: 1px solid var(--border);
|
||||
border-radius: 999px; padding: .12em .7em; font-size: .8rem; color: var(--muted);
|
||||
margin: .15rem .2rem .15rem 0; font-family: ui-monospace, monospace; }
|
||||
/* diagram */
|
||||
.diagram { display: flex; flex-direction: column; gap: .55rem; align-items: stretch;
|
||||
margin: 1rem 0; }
|
||||
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
|
||||
.box { border: 1px solid var(--border); border-radius: 10px; padding: .55rem .8rem;
|
||||
background: var(--bg); font-size: .86rem; }
|
||||
.box b { display: block; font-size: .8rem; }
|
||||
.box small { color: var(--muted); font-family: ui-monospace, monospace; }
|
||||
.edge { border-color: var(--accent); background: var(--accent-soft); }
|
||||
.new { border-color: var(--ok); background: var(--ok-soft); }
|
||||
.arrow { color: var(--muted); font-weight: 700; }
|
||||
/* router widget */
|
||||
.router { background: var(--card); border: 1px solid var(--border); border-radius: 12px;
|
||||
padding: 1.1rem 1.2rem; margin: 1.2rem 0; }
|
||||
.router label { font-size: .85rem; color: var(--muted); display: block; margin-bottom: .3rem; }
|
||||
.router select, .router button { font-size: .95rem; padding: .5rem .7rem; border-radius: 8px;
|
||||
border: 1px solid var(--border); background: var(--bg); color: var(--fg); }
|
||||
.router button { background: var(--accent); color: #fff; border: none; cursor: pointer; font-weight: 600; }
|
||||
.router button:hover { filter: brightness(1.08); }
|
||||
.trace { margin-top: 1rem; display: flex; flex-direction: column; gap: .4rem; }
|
||||
.step { opacity: 0; transform: translateY(4px); transition: opacity .35s, transform .35s;
|
||||
border: 1px solid var(--border); border-radius: 9px; padding: .5rem .75rem; font-size: .87rem;
|
||||
background: var(--bg); }
|
||||
.step.show { opacity: 1; transform: none; }
|
||||
.step.hit { border-color: var(--ok); background: var(--ok-soft); }
|
||||
.step.miss { border-color: var(--bad); background: var(--bad-soft); }
|
||||
.step small { color: var(--muted); font-family: ui-monospace, monospace; }
|
||||
/* quiz */
|
||||
.q { border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.2rem; margin: 1rem 0;
|
||||
background: var(--card); }
|
||||
.q .stem { font-weight: 600; margin-bottom: .6rem; }
|
||||
.opt { display: block; width: 100%; text-align: left; border: 1px solid var(--border);
|
||||
background: var(--bg); color: var(--fg); border-radius: 9px; padding: .6rem .8rem;
|
||||
margin: .4rem 0; cursor: pointer; font-size: .93rem; line-height: 1.4; }
|
||||
.opt:hover { border-color: var(--accent); }
|
||||
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
|
||||
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
|
||||
.opt:disabled { cursor: default; }
|
||||
.why { margin-top: .5rem; font-size: .87rem; color: var(--muted); display: none; }
|
||||
.why.show { display: block; }
|
||||
.score { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--border);
|
||||
padding: .6rem 0; font-weight: 600; }
|
||||
.foot { color: var(--muted); font-size: .85rem; margin-top: 3rem; border-top: 1px solid var(--border);
|
||||
padding-top: 1rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
|
||||
<h1>Adding SyncYomi to a one-edge home server</h1>
|
||||
<p class="sub">How <code>setup_syncyomi.sh</code> stands up a manga-sync server that a phone can reach over the public internet — by slotting into infrastructure that already existed, rather than building a new stack.</p>
|
||||
|
||||
<div class="toc">
|
||||
<strong>Contents</strong>
|
||||
<ol>
|
||||
<li><a href="#background">Background — the pieces already on the box</a></li>
|
||||
<li><a href="#intuition">Intuition — one door, three rooms</a></li>
|
||||
<li><a href="#code">Code — a walkthrough by concern</a></li>
|
||||
<li><a href="#quiz">Quiz — check your understanding</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<h2 id="background">1 · Background</h2>
|
||||
|
||||
<p><strong>SyncYomi</strong> is a small self-hosted server. The manga reader app <strong>TachiyomiSY</strong> on a phone talks to it to keep its library and reading progress in sync across devices — the phone uploads a blob of its library, the server stores it, and other devices download it. The phone authenticates with a single <em>API key</em>, and it needs to reach the server from anywhere, including mobile data.</p>
|
||||
|
||||
<p>The interesting part isn't SyncYomi itself — it's that this PC was <em>already</em> a public server for two other things, and the new script had to fit into that without disturbing them. Three existing facts shaped every decision:</p>
|
||||
|
||||
<div class="card">
|
||||
<h3>a. There is exactly one front door</h3>
|
||||
<p>A single <strong>Caddy</strong> container (named <code>gitea-caddy</code>) owns the public ports <code>80</code> and <code>443</code>. It terminates TLS and forwards each request to a small backend that listens only on <code>127.0.0.1</code> (loopback — unreachable from the network). Two tenants already live behind it:</p>
|
||||
<p>
|
||||
<span class="pill">kuhy.duckdns.org → 127.0.0.1:3000 (Gitea)</span>
|
||||
<span class="pill">kuhy-cloud.duckdns.org → 127.0.0.1:5000 (dufs)</span>
|
||||
</p>
|
||||
<p>Caddy tells them apart by the <em>hostname</em> in the request. It also fetches and renews a free Let's Encrypt TLS certificate for each hostname automatically.</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3>b. DuckDNS gives every service the same public IP</h3>
|
||||
<p>The home connection has one changing public IP. A cron job (<code>~/.joplin-server/duckdns-update.sh</code>) tells DuckDNS "these labels all point at my current IP". Adding a service means adding its label to that one updater — not creating a second updater.</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3>c. The firewall silently kills bridged containers</h3>
|
||||
<p>This host's <code>nftables</code> has a default-drop <em>FORWARD</em> chain. A normal Docker bridge network routes through FORWARD, so a bridged container's traffic gets dropped with no error. The existing services dodge this by using <code>network_mode: host</code> and binding to <code>127.0.0.1</code>. The new service must do the same.</p>
|
||||
</div>
|
||||
|
||||
<p>So the change is not "install a server." It's "add a third tenant to a shared, hostname-routed edge, reusing its TLS, its DNS updater, and its firewall posture."</p>
|
||||
|
||||
<h2 id="intuition">2 · Intuition — one door, three rooms</h2>
|
||||
|
||||
<p>Picture the whole public surface as a single reception desk. Everything from the outside world arrives at that one desk (port 443 on <code>gitea-caddy</code>). The desk reads the name on the envelope — the hostname — and walks it to the right internal room. The rooms themselves have no external doors at all.</p>
|
||||
|
||||
<div class="diagram">
|
||||
<div class="row">
|
||||
<div class="box"><b>📱 Phone</b><small>https://kuhy-sync.duckdns.org</small></div>
|
||||
<span class="arrow">→</span>
|
||||
<div class="box edge"><b>gitea-caddy</b><small>:443 · TLS · host-net</small></div>
|
||||
</div>
|
||||
<div class="row" style="padding-left:1rem">
|
||||
<span class="arrow">routes by hostname ↓</span>
|
||||
</div>
|
||||
<div class="row" style="padding-left:1rem">
|
||||
<div class="box"><b>Gitea</b><small>127.0.0.1:3000</small></div>
|
||||
<div class="box"><b>dufs</b><small>127.0.0.1:5000</small></div>
|
||||
<div class="box new"><b>SyncYomi ⭐ new</b><small>127.0.0.1:8282</small></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Adding SyncYomi is therefore four small edits, not a new stack:</p>
|
||||
<ul>
|
||||
<li><strong>A new room:</strong> a SyncYomi container on <code>127.0.0.1:8282</code>.</li>
|
||||
<li><strong>A new name plate at the desk:</strong> one <code>kuhy-sync.duckdns.org { … }</code> block appended to the shared Caddyfile.</li>
|
||||
<li><strong>A new label on the DNS updater</strong> so the name resolves to home.</li>
|
||||
<li><strong>An API key,</strong> minted automatically so you can hand it to the phone.</li>
|
||||
</ul>
|
||||
|
||||
<div class="note">
|
||||
<strong>Why loopback matters.</strong> If SyncYomi listened on <code>0.0.0.0</code>, it would have an external door of its own — bypassing the TLS desk entirely and serving your library in plaintext. Binding <code>127.0.0.1</code> forces every request to go through Caddy. SyncYomi actually defaults to <code>0.0.0.0</code>, so the script <em>rewrites</em> that after first launch.</p>
|
||||
</div>
|
||||
|
||||
<h3>Try it: how the desk routes a request</h3>
|
||||
<p>Pick a hostname and watch Caddy decide where it goes. This mirrors the real site blocks in <code>~/gitea/Caddyfile</code>.</p>
|
||||
|
||||
<div class="router">
|
||||
<label for="host">Incoming request hostname</label>
|
||||
<div class="row">
|
||||
<select id="host">
|
||||
<option value="kuhy-sync.duckdns.org">kuhy-sync.duckdns.org</option>
|
||||
<option value="kuhy.duckdns.org">kuhy.duckdns.org</option>
|
||||
<option value="kuhy-cloud.duckdns.org">kuhy-cloud.duckdns.org</option>
|
||||
<option value="kuhy-unknown.duckdns.org">kuhy-unknown.duckdns.org</option>
|
||||
</select>
|
||||
<button id="routeBtn" type="button">Route it →</button>
|
||||
</div>
|
||||
<div class="trace" id="trace"></div>
|
||||
</div>
|
||||
|
||||
<h2 id="code">3 · Code — a walkthrough by concern</h2>
|
||||
<p>The script is one file, <code>setup_syncyomi.sh</code>, with <code>setup</code> / <code>status</code> / <code>help</code> subcommands. Here are the parts that carry the design, grouped by what they achieve.</p>
|
||||
|
||||
<h3>Reuse, don't rebuild: preflight</h3>
|
||||
<p>It refuses to invent infrastructure. It hard-requires the existing edge to be present and bails with a pointer if not — so it can never accidentally spin up a competing proxy.</p>
|
||||
<pre><code>has_cmd docker || die "docker not found — run setup_gitea.sh first."
|
||||
docker ps --format '{{.Names}}' | grep -qx "${CADDY_CONTAINER}" ||
|
||||
die "Caddy container '${CADDY_CONTAINER}' not running — run setup_gitea.sh first."
|
||||
[[ -f ${CADDYFILE} ]] || die "Caddyfile ${CADDYFILE} missing — run setup_gitea.sh first."
|
||||
[[ -x ${DUCKDNS_UPDATER} ]] || die "DuckDNS updater missing — run install_joplin.sh first."</code></pre>
|
||||
|
||||
<h3>The container: host networking, loopback bind</h3>
|
||||
<p><code>network_mode: host</code> sidesteps the FORWARD-chain trap; the loopback bind (enforced just below) keeps it private.</p>
|
||||
<pre><code>services:
|
||||
syncyomi:
|
||||
image: ghcr.io/syncyomi/syncyomi:v1.1.11 # pinned, not :latest
|
||||
restart: unless-stopped # ← survives reboot
|
||||
network_mode: host
|
||||
volumes: [ ./config:/config ]</code></pre>
|
||||
<p><code>restart: unless-stopped</code> plus the enabled Docker service is the entire "auto-start after reboot" story — no bespoke systemd unit needed.</p>
|
||||
|
||||
<h3>Readiness + the loopback rewrite</h3>
|
||||
<p>SyncYomi v1.1.x has <em>no</em> public health route (<code>/api/healthz</code> is a 404). The script instead treats <code>GET /api/auth/onboard</code> as "up" — it answers <code>204</code> when no account exists yet, or <code>403</code> once one does. Either means the API is serving.</p>
|
||||
<pre><code>syncyomi_ready() {
|
||||
code="$(curl -sS -o /dev/null -w '%{http_code}' "${base}/api/auth/onboard" ...)"
|
||||
[[ ${code} == "204" || ${code} == "403" ]]
|
||||
}</code></pre>
|
||||
<p>Once it's up, the script patches the generated config from the insecure default and restarts:</p>
|
||||
<pre><code>sed -i -E 's|^\s*host\s*=.*|host = "127.0.0.1"|' "${CONFIG_TOML}" # was 0.0.0.0</code></pre>
|
||||
|
||||
<h3>Minting the API key — the deliverable</h3>
|
||||
<p>This is the part that lets the script hand you a key instead of making you click through a web UI. It onboards the first account (only if none exists), logs in for a session cookie, then reuses or creates a key. Two gotchas discovered live are baked in:</p>
|
||||
<ul>
|
||||
<li>It <strong>reuses</strong> an existing <code>tachiyomisy</code> key so repeated runs don't pile up keys.</li>
|
||||
<li>The create call <strong>must send a non-empty <code>scopes</code></strong> array — SyncYomi returns <code>HTTP 500</code> on a null.</li>
|
||||
</ul>
|
||||
<pre><code>key="$(curl -sS -b "${jar}" "${SYNCYOMI_LOCAL}/api/keys" \
|
||||
| jq -r '[.[] | select(.name=="tachiyomisy")][0].key // empty')"
|
||||
if [[ -z ${key} ]]; then
|
||||
key="$(curl -sS -b "${jar}" \
|
||||
-d '{"name":"tachiyomisy","scopes":["read","write"]}' \
|
||||
"${SYNCYOMI_LOCAL}/api/keys" | jq -r '.key // empty')"
|
||||
fi</code></pre>
|
||||
|
||||
<h3>Joining the shared edge: Caddy + DuckDNS</h3>
|
||||
<p>One site block appended to the shared Caddyfile, then an in-container reload. Caddy issues the TLS cert on its own once the name resolves.</p>
|
||||
<pre><code>printf '\n%s {\n\treverse_proxy 127.0.0.1:%s\n}\n' \
|
||||
"${SYNCYOMI_SUBDOMAIN}" "${SYNCYOMI_PORT}" >>"${CADDYFILE}"
|
||||
docker exec "${CADDY_CONTAINER}" caddy reload --config "${CADDYFILE_IN_CONTAINER}"</code></pre>
|
||||
<p>And one label spliced into the existing updater's <code>domains=</code> list — no second cron job:</p>
|
||||
<pre><code>sed -i -E "s|(domains=)([^&\"']*)|\1\2,${label}|" "${DUCKDNS_UPDATER}"</code></pre>
|
||||
|
||||
<div class="note">
|
||||
<strong>The one fragility.</strong> That Caddy block lives in a file <em>owned</em> by <code>setup_gitea.sh</code>, which rewrites it from scratch when re-run. If that happens, SyncYomi's block vanishes — the fix is simply to re-run <code>setup_syncyomi.sh setup</code>, which idempotently re-appends it. This is a known, documented trade-off inherited from the sibling <code>setup_dufs_cloud.sh</code>.
|
||||
</div>
|
||||
|
||||
<h2 id="quiz">4 · Quiz</h2>
|
||||
<p>Five questions on the <em>reasoning</em> behind the change. Click an option to check it.</p>
|
||||
<div id="quiz"></div>
|
||||
<div class="score" id="score">Score: 0 / 0</div>
|
||||
|
||||
<div class="foot">
|
||||
Generated by <code>/explain-diff</code> for commit <code>59430f9</code> ·
|
||||
<code>linux_configuration/scripts/single_use/features/setup_syncyomi.sh</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ---------- router micro-world ----------
|
||||
const ROUTES = {
|
||||
"kuhy.duckdns.org": { port: 3000, name: "Gitea" },
|
||||
"kuhy-cloud.duckdns.org": { port: 5000, name: "dufs" },
|
||||
"kuhy-sync.duckdns.org": { port: 8282, name: "SyncYomi" },
|
||||
};
|
||||
const traceEl = document.getElementById("trace");
|
||||
function step(html, cls) {
|
||||
const d = document.createElement("div");
|
||||
d.className = "step " + (cls || "");
|
||||
d.innerHTML = html;
|
||||
traceEl.appendChild(d);
|
||||
requestAnimationFrame(() => setTimeout(() => d.classList.add("show"), 10));
|
||||
return d;
|
||||
}
|
||||
document.getElementById("routeBtn").addEventListener("click", () => {
|
||||
traceEl.innerHTML = "";
|
||||
const host = document.getElementById("host").value;
|
||||
const seq = [
|
||||
() => step(`DNS: <b>${host}</b> resolves to the home public IP <small>(one IP for all labels)</small>`),
|
||||
() => step(`Arrives at <b>gitea-caddy</b> on <small>:443</small>, TLS terminated`, "edge"),
|
||||
() => {
|
||||
const r = ROUTES[host];
|
||||
if (r) return step(`Host matches a site block → forward to <b>127.0.0.1:${r.port}</b> <small>(${r.name})</small>`, "hit");
|
||||
return step(`No site block matches <b>${host}</b> → Caddy has no cert/route, TLS alert <small>(request refused)</small>`, "miss");
|
||||
},
|
||||
];
|
||||
seq.forEach((fn, i) => setTimeout(fn, i * 480));
|
||||
});
|
||||
|
||||
// ---------- quiz ----------
|
||||
// correct positions chosen to span A/B/C/D: [B, A, C, D, B]
|
||||
const QUIZ = [
|
||||
{
|
||||
stem: "Why does the SyncYomi container bind to 127.0.0.1:8282 rather than 0.0.0.0?",
|
||||
options: [
|
||||
"Because Docker host networking is unable to bind to the 0.0.0.0 wildcard address.",
|
||||
"So every request must pass through Caddy, which terminates TLS for the service.",
|
||||
"Because the Gitea container is already holding on to TCP port 8282 on this host.",
|
||||
"To make SyncYomi skip writing its generated config.toml file on first boot.",
|
||||
],
|
||||
correct: 1,
|
||||
why: "A 0.0.0.0 bind would expose an external door with no TLS, bypassing Caddy and serving the library in plaintext.",
|
||||
},
|
||||
{
|
||||
stem: "Why must the create-key request send a non-empty scopes array?",
|
||||
options: [
|
||||
"SyncYomi's store rejects a null scopes value and answers with HTTP 500.",
|
||||
"TachiyomiSY on the phone will not accept a key that grants no permissions.",
|
||||
"Caddy strips any scopes field out of the body before SyncYomi receives it.",
|
||||
"The onboarding call consumes the default scopes, leaving none for the key.",
|
||||
],
|
||||
correct: 0,
|
||||
why: "Discovered live: POST /api/keys with no scopes returned 500; adding [\"read\",\"write\"] returned 201 with the key.",
|
||||
},
|
||||
{
|
||||
stem: "Why doesn't the script start its own Caddy container for SyncYomi?",
|
||||
options: [
|
||||
"Because DuckDNS permits only a single reverse proxy per user account.",
|
||||
"Because a Caddy instance can serve at most one TLS certificate at a time.",
|
||||
"Because Gitea's Caddy already owns ports 80 and 443; a second would collide.",
|
||||
"Because SyncYomi already bundles its own reverse proxy that Caddy would duplicate.",
|
||||
],
|
||||
correct: 2,
|
||||
why: "One host has one :443. The design is a single shared edge that routes to many loopback backends by hostname.",
|
||||
},
|
||||
{
|
||||
stem: "What does the script poll to decide SyncYomi is 'up', and why that?",
|
||||
options: [
|
||||
"The container's exit code, which turns non-zero only after startup fails.",
|
||||
"GET /api/healthz, the documented health endpoint that returns 200 when ready.",
|
||||
"A TLS handshake against the public subdomain to confirm the cert is live.",
|
||||
"GET /api/auth/onboard, because v1.1.x exposes no public health route.",
|
||||
],
|
||||
correct: 3,
|
||||
why: "/api/healthz is a 404 in v1.1.x; onboard answers 204 (no user) or 403 (user exists), both meaning the API serves.",
|
||||
},
|
||||
{
|
||||
stem: "If setup_gitea.sh is re-run later, what happens to SyncYomi's exposure?",
|
||||
options: [
|
||||
"Nothing: each service keeps its exposure in a separate, private Caddyfile.",
|
||||
"Its Caddy block is wiped, so re-running setup_syncyomi.sh restores it.",
|
||||
"The kuhy-sync DuckDNS label is deleted and must be registered again by hand.",
|
||||
"SyncYomi's container is stopped until the Gitea setup finishes running.",
|
||||
],
|
||||
correct: 1,
|
||||
why: "setup_gitea.sh regenerates the shared Caddyfile from scratch; the appended block is lost until setup_syncyomi.sh re-adds it idempotently.",
|
||||
},
|
||||
];
|
||||
|
||||
const quizEl = document.getElementById("quiz");
|
||||
const scoreEl = document.getElementById("score");
|
||||
let answered = 0, correctCount = 0;
|
||||
|
||||
QUIZ.forEach((q, qi) => {
|
||||
const card = document.createElement("div");
|
||||
card.className = "q";
|
||||
const stem = document.createElement("div");
|
||||
stem.className = "stem";
|
||||
stem.textContent = (qi + 1) + ". " + q.stem;
|
||||
card.appendChild(stem);
|
||||
const why = document.createElement("div");
|
||||
why.className = "why";
|
||||
why.textContent = "Why: " + q.why;
|
||||
let done = false;
|
||||
q.options.forEach((opt, oi) => {
|
||||
const b = document.createElement("button");
|
||||
b.className = "opt";
|
||||
b.type = "button";
|
||||
b.textContent = opt;
|
||||
b.addEventListener("click", () => {
|
||||
if (done) return;
|
||||
done = true;
|
||||
answered++;
|
||||
const isRight = oi === q.correct;
|
||||
if (isRight) correctCount++;
|
||||
Array.from(card.querySelectorAll(".opt")).forEach((el, ei) => {
|
||||
el.disabled = true;
|
||||
if (ei === q.correct) el.classList.add("correct");
|
||||
else if (ei === oi) el.classList.add("wrong");
|
||||
});
|
||||
why.classList.add("show");
|
||||
scoreEl.textContent = `Score: ${correctCount} / ${answered}`;
|
||||
});
|
||||
card.appendChild(b);
|
||||
});
|
||||
card.appendChild(why);
|
||||
quizEl.appendChild(card);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>testsAndMisc — change explanations</title>
|
||||
<title>explanations — change explanations</title>
|
||||
<style>
|
||||
:root{--bg:#fbfbfd;--fg:#1a1a1f;--muted:#5b5b6b;--card:#fff;--line:#e4e4ec;
|
||||
--accent:#6b4fd6;--accent-soft:#efeaff;--shadow:0 1px 3px rgba(0,0,0,.08),0 8px 24px rgba(0,0,0,.05);}
|
||||
@ -28,18 +28,14 @@
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<div class="kicker">testsAndMisc</div>
|
||||
<div class="kicker">explanations</div>
|
||||
<h1>Change explanations</h1>
|
||||
<p class="lead">4 explanations · interactive walkthroughs of notable changes, newest first.</p>
|
||||
<p class="lead">3 explanations · interactive walkthroughs of notable changes, newest first.</p>
|
||||
<div class="grid">
|
||||
<a class="card" href="2026-07-13-explanation-tether-hotspot-block.html">
|
||||
<span class="date">2026-07-13</span>
|
||||
<span class="title">Explaining: the hotspot / tethering block</span>
|
||||
</a>
|
||||
<a class="card" href="2026-07-13-explanation-setup-syncyomi.html">
|
||||
<span class="date">2026-07-13</span>
|
||||
<span class="title">Adding SyncYomi to a one-edge home server</span>
|
||||
</a>
|
||||
<a class="card" href="2026-07-12-explanation-dufs-cloud.html">
|
||||
<span class="date">2026-07-12</span>
|
||||
<span class="title">Self-hosted dufs cloud + KeePass WebDAV sync — explained</span>
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
{
|
||||
"intent": "Add a self-contained setup_syncyomi.sh that stands up a self-hosted SyncYomi manga-sync server (for TachiyomiSY) reachable from a mobile network, auto-starting after reboot, and hands back the host address + API key.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/single_use/features/setup_syncyomi.sh (new)",
|
||||
"Non-goal: no second reverse proxy, no second DuckDNS cron, no hand-edited nftables — reuses the existing gitea-caddy edge + DuckDNS updater",
|
||||
"Runtime side effects (live host): ~/syncyomi/ data dir, one appended block in the shared ~/gitea/Caddyfile, kuhy-sync added to ~/.joplin-server/duckdns-update.sh"
|
||||
],
|
||||
"changes": [
|
||||
"SyncYomi runs as a Docker container (ghcr.io/syncyomi/syncyomi:v1.1.11), network_mode: host, patched to bind 127.0.0.1:8282 only (dodges the default-drop nftables FORWARD chain and stays behind Caddy).",
|
||||
"Public HTTPS by appending a kuhy-sync.duckdns.org site block to the shared gitea-caddy Caddyfile and reloading in-container; Caddy auto-issues the Let's Encrypt cert.",
|
||||
"Auto-generates a stored 0600 credential set, then onboards the first account and mints/reuses a 'tachiyomisy' API key over the local REST API (scopes required non-empty), printing host + key.",
|
||||
"Extends the existing DuckDNS updater with the kuhy-sync label; ensures 80/443 open via setup_wireguard_ssh.sh allow-web; idempotent setup/status/help subcommands."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "shellcheck -x setup_syncyomi.sh; shfmt -d setup_syncyomi.sh",
|
||||
"result": "pass",
|
||||
"evidence": "shellcheck clean; shfmt no diff."
|
||||
},
|
||||
{
|
||||
"command": "pre-commit run --files linux_configuration/scripts/single_use/features/setup_syncyomi.sh",
|
||||
"result": "pass",
|
||||
"evidence": "All hooks Passed (shellcheck, AI-evidence, secret scans); Python hooks skipped (no .py)."
|
||||
},
|
||||
{
|
||||
"command": "./setup_syncyomi.sh setup && ./setup_syncyomi.sh status",
|
||||
"result": "pass",
|
||||
"evidence": "Container up (restart=unless-stopped), local API 403, Caddy block present, kuhy-sync resolves, external HTTPS 403 after Let's Encrypt cert obtained. Gitea(3000)/dufs(5000) unaffected. Re-runs idempotent."
|
||||
},
|
||||
{
|
||||
"command": "sqlite3 ~/syncyomi/config/syncyomi.db 'SELECT length(data),updated_at FROM sync_data;'",
|
||||
"result": "pass",
|
||||
"evidence": "After a TachiyomiSY sync over cellular: sync_data row = 13914937 bytes, updated_at 2026-07-13 17:17:06 — library round-tripped and is stored server-side."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"The SyncYomi block lives in the shared ~/gitea/Caddyfile, which setup_gitea.sh regenerates from scratch; re-running that drops the block. Mitigation: re-run setup_syncyomi.sh setup to restore it (documented in-code, same as setup_dufs_cloud.sh).",
|
||||
"Docker json-file logs at SyncYomi's default DEBUG level grow over time; not bounded by this script."
|
||||
],
|
||||
"rollback": [
|
||||
"docker compose -f ~/syncyomi/docker-compose.yml down; rm -rf ~/syncyomi; remove the kuhy-sync.duckdns.org block from ~/gitea/Caddyfile and 'docker exec gitea-caddy caddy reload --config /etc/caddy/Caddyfile'; drop kuhy-sync from ~/.joplin-server/duckdns-update.sh.",
|
||||
"Validate after rollback: ./setup_syncyomi.sh status shows no container; Gitea and dufs still reachable (curl 127.0.0.1:3000 / :5000)."
|
||||
]
|
||||
}
|
||||
@ -1,408 +0,0 @@
|
||||
#!/bin/bash
|
||||
# setup_syncyomi.sh — Self-hosted SyncYomi manga-sync server on this Arch PC.
|
||||
#
|
||||
# Stands up SyncYomi (github.com/SyncYomi/SyncYomi) in Docker, bound to
|
||||
# 127.0.0.1:8282, and fronts it with the EXISTING Caddy reverse proxy (from
|
||||
# setup_gitea.sh) for automatic public HTTPS at a new DuckDNS subdomain, so
|
||||
# TachiyomiSY on the phone can sync its library from a mobile network.
|
||||
#
|
||||
# It reuses the host's existing exposure stack — it does NOT add a second Caddy,
|
||||
# a second DuckDNS updater, or hand-edit /etc/nftables.conf. It also creates the
|
||||
# first SyncYomi account and mints an API key over the local REST API, then
|
||||
# prints the host address + API key ready to paste into TachiyomiSY.
|
||||
#
|
||||
# Run as your normal user (NOT root). It uses sudo only for pacman, the firewall
|
||||
# flag and enabling docker. Idempotent — safe to re-run.
|
||||
#
|
||||
# Usage:
|
||||
# ./setup_syncyomi.sh Install / update everything (default)
|
||||
# ./setup_syncyomi.sh setup Same as above
|
||||
# ./setup_syncyomi.sh status Show health / exposure diagnostics
|
||||
# ./setup_syncyomi.sh help Show this help
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# --- Pinned SyncYomi image ---------------------------------------------------
|
||||
readonly SYNCYOMI_IMAGE="ghcr.io/syncyomi/syncyomi:v1.1.11"
|
||||
readonly SYNCYOMI_PORT=8282
|
||||
readonly SYNCYOMI_LOCAL="http://127.0.0.1:${SYNCYOMI_PORT}"
|
||||
|
||||
# --- Data dir + secrets (outside the git repo, like ~/gitea) -----------------
|
||||
readonly DATA_DIR="${HOME}/syncyomi"
|
||||
readonly COMPOSE_FILE="${DATA_DIR}/docker-compose.yml"
|
||||
readonly CONFIG_TOML="${DATA_DIR}/config/config.toml"
|
||||
readonly CONF_FILE="${DATA_DIR}/.syncyomi.conf"
|
||||
readonly TOKEN_FILE="${DATA_DIR}/.api_token"
|
||||
|
||||
# --- Existing host infrastructure (from setup_gitea.sh / install_joplin.sh) --
|
||||
readonly CADDY_CONTAINER="gitea-caddy"
|
||||
readonly CADDYFILE="${HOME}/gitea/Caddyfile"
|
||||
readonly CADDYFILE_IN_CONTAINER="/etc/caddy/Caddyfile"
|
||||
readonly DUCKDNS_UPDATER="${HOME}/.joplin-server/duckdns-update.sh"
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||
readonly SCRIPT_DIR
|
||||
readonly WG_SCRIPT="${SCRIPT_DIR}/setup_wireguard_ssh.sh"
|
||||
|
||||
# shellcheck source=../../lib/common.sh
|
||||
# shellcheck disable=SC1091
|
||||
source "${SCRIPT_DIR}/../../lib/common.sh"
|
||||
|
||||
# Config values (populated from CONF_FILE / defaults).
|
||||
SYNCYOMI_USER=""
|
||||
SYNCYOMI_PASSWORD=""
|
||||
SYNCYOMI_SUBDOMAIN=""
|
||||
|
||||
# Local timezone for the container (falls back if timedatectl is unavailable).
|
||||
TZ_VALUE="$(timedatectl show -p Timezone --value 2>/dev/null || echo 'Europe/Warsaw')"
|
||||
readonly TZ_VALUE
|
||||
|
||||
die() {
|
||||
log_error "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
grep -E '^#( |$)' "$0" | sed -E 's/^# ?//'
|
||||
exit 0
|
||||
}
|
||||
|
||||
# --- Step 1: preflight -------------------------------------------------------
|
||||
preflight() {
|
||||
log_info "Preflight checks"
|
||||
[[ ${EUID} -ne 0 ]] || die "Run as your normal user, not root (it will sudo where needed)."
|
||||
|
||||
# Runtime deps; install any that are missing from the official repos.
|
||||
install_missing_pacman_packages docker docker-compose jq curl openssl
|
||||
|
||||
# Ensure the docker daemon is enabled+running (auto-start after reboot). Only
|
||||
# touch systemd via sudo when it is not already active, to stay a no-op on the
|
||||
# common case where docker is already up (Gitea/dufs run on it).
|
||||
has_cmd docker || die "docker not found — run setup_gitea.sh first."
|
||||
if ! is_service_active docker; then
|
||||
log_info "Enabling and starting docker.service"
|
||||
sudo systemctl enable --now docker
|
||||
fi
|
||||
|
||||
# The public-exposure stack must already exist (Caddy from setup_gitea.sh).
|
||||
docker ps --format '{{.Names}}' | grep -qx "${CADDY_CONTAINER}" ||
|
||||
die "Caddy container '${CADDY_CONTAINER}' not running — run setup_gitea.sh first."
|
||||
[[ -f ${CADDYFILE} ]] || die "Caddyfile ${CADDYFILE} missing — run setup_gitea.sh first."
|
||||
[[ -x ${DUCKDNS_UPDATER} ]] || die "DuckDNS updater ${DUCKDNS_UPDATER} missing — run install_joplin.sh first."
|
||||
log_ok "Host exposure stack present (docker + ${CADDY_CONTAINER} + DuckDNS updater)"
|
||||
}
|
||||
|
||||
# --- Step 2: config (auto-generate credentials, store 0600) ------------------
|
||||
load_config() {
|
||||
ensure_dir "${DATA_DIR}"
|
||||
chmod 700 "${DATA_DIR}"
|
||||
if [[ -f ${CONF_FILE} ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "${CONF_FILE}"
|
||||
fi
|
||||
SYNCYOMI_USER="${SYNCYOMI_USER:-$(get_actual_user)}"
|
||||
SYNCYOMI_SUBDOMAIN="${SYNCYOMI_SUBDOMAIN:-kuhy-sync.duckdns.org}"
|
||||
# Generate the web/API password once; never regenerate on re-run.
|
||||
if [[ -z ${SYNCYOMI_PASSWORD:-} ]]; then
|
||||
SYNCYOMI_PASSWORD="$(openssl rand -base64 24)"
|
||||
fi
|
||||
save_config
|
||||
}
|
||||
|
||||
save_config() {
|
||||
# 0600 — holds the plaintext SyncYomi password so re-runs stay
|
||||
# non-interactive. Lives under ~/syncyomi (outside the git repo).
|
||||
umask 077
|
||||
{
|
||||
printf 'SYNCYOMI_USER=%q\n' "${SYNCYOMI_USER}"
|
||||
printf 'SYNCYOMI_PASSWORD=%q\n' "${SYNCYOMI_PASSWORD}"
|
||||
printf 'SYNCYOMI_SUBDOMAIN=%q\n' "${SYNCYOMI_SUBDOMAIN}"
|
||||
} >"${CONF_FILE}"
|
||||
chmod 600 "${CONF_FILE}"
|
||||
log_ok "Saved config to ${CONF_FILE} (0600)"
|
||||
}
|
||||
|
||||
# --- Step 3: docker-compose stack (host networking, loopback bind) -----------
|
||||
write_compose() {
|
||||
ensure_dir "${DATA_DIR}/config"
|
||||
# network_mode: host + SyncYomi's host=127.0.0.1 keeps it loopback-only
|
||||
# (reached by the host-networked Caddy) and dodges this host's default-drop
|
||||
# nftables FORWARD chain that would kill a bridge-networked container.
|
||||
umask 077
|
||||
cat >"${COMPOSE_FILE}" <<EOF
|
||||
# Generated by setup_syncyomi.sh — do not edit by hand.
|
||||
services:
|
||||
syncyomi:
|
||||
container_name: syncyomi
|
||||
image: ${SYNCYOMI_IMAGE}
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
environment:
|
||||
- TZ=${TZ_VALUE}
|
||||
volumes:
|
||||
- ./config:/config
|
||||
EOF
|
||||
log_ok "Wrote ${COMPOSE_FILE}"
|
||||
}
|
||||
|
||||
start_containers() {
|
||||
log_info "Starting SyncYomi container"
|
||||
docker compose -f "${COMPOSE_FILE}" up -d
|
||||
}
|
||||
|
||||
# Readiness probe. SyncYomi (v1.1.x) has no public /healthz, but GET
|
||||
# /api/auth/onboard answers 204 (no user yet) or 403 (a user exists) once the
|
||||
# API is serving — either means "up". Echoes the HTTP code; returns 0 if ready.
|
||||
# Usage: syncyomi_ready "http://127.0.0.1:8282"
|
||||
syncyomi_ready() {
|
||||
local base="$1" code
|
||||
code="$(curl -sS -o /dev/null -w '%{http_code}' "${base}/api/auth/onboard" 2>/dev/null || true)"
|
||||
echo "${code}"
|
||||
[[ ${code} == "204" || ${code} == "403" ]]
|
||||
}
|
||||
|
||||
# --- Step 4: wait until the local API answers --------------------------------
|
||||
wait_for_syncyomi() {
|
||||
log_info "Waiting for SyncYomi to come up on ${SYNCYOMI_LOCAL}"
|
||||
local i
|
||||
for ((i = 0; i < 60; i++)); do
|
||||
if syncyomi_ready "${SYNCYOMI_LOCAL}" >/dev/null; then
|
||||
log_ok "SyncYomi is up (API answering)"
|
||||
return 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
die "SyncYomi did not become healthy in 120s — check 'docker logs syncyomi'."
|
||||
}
|
||||
|
||||
# Defensive: SyncYomi generates config/config.toml on first run. Ensure it binds
|
||||
# loopback-only (never 0.0.0.0, which would bypass Caddy/TLS) and serves at root.
|
||||
ensure_local_config() {
|
||||
[[ -f ${CONFIG_TOML} ]] || return 0
|
||||
local changed=0
|
||||
if grep -qE '^\s*host\s*=' "${CONFIG_TOML}"; then
|
||||
if ! grep -qE '^\s*host\s*=\s*"127\.0\.0\.1"' "${CONFIG_TOML}"; then
|
||||
sed -i -E 's|^\s*host\s*=.*|host = "127.0.0.1"|' "${CONFIG_TOML}"
|
||||
changed=1
|
||||
fi
|
||||
fi
|
||||
# Force an empty baseUrl (dedicated subdomain, not a sub-path).
|
||||
if grep -qE '^\s*baseUrl\s*=' "${CONFIG_TOML}" &&
|
||||
! grep -qE '^\s*baseUrl\s*=\s*""' "${CONFIG_TOML}"; then
|
||||
sed -i -E 's|^\s*baseUrl\s*=.*|baseUrl = ""|' "${CONFIG_TOML}"
|
||||
changed=1
|
||||
fi
|
||||
if [[ ${changed} -eq 1 ]]; then
|
||||
log_info "Patched ${CONFIG_TOML} (host=127.0.0.1, baseUrl empty) — restarting"
|
||||
docker compose -f "${COMPOSE_FILE}" restart
|
||||
wait_for_syncyomi
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Step 5: create first account + mint API key over the local REST API -----
|
||||
mint_api_key() {
|
||||
if [[ -f ${TOKEN_FILE} ]]; then
|
||||
log_ok "API key already minted ($(<"${TOKEN_FILE}") stored in ${TOKEN_FILE})"
|
||||
return 0
|
||||
fi
|
||||
log_info "Creating SyncYomi account and minting API key"
|
||||
|
||||
local jar body http key
|
||||
jar="$(mktemp)"
|
||||
# shellcheck disable=SC2064
|
||||
trap "rm -f '${jar}'" RETURN
|
||||
|
||||
# JSON with proper escaping (password may contain +,/,= from base64).
|
||||
body="$(jq -n --arg u "${SYNCYOMI_USER}" --arg p "${SYNCYOMI_PASSWORD}" \
|
||||
'{username:$u,password:$p}')"
|
||||
|
||||
# Onboard the first user only if none exists yet (GET returns 204 when empty).
|
||||
http="$(curl -fsS -o /dev/null -w '%{http_code}' "${SYNCYOMI_LOCAL}/api/auth/onboard" 2>/dev/null || true)"
|
||||
if [[ ${http} == "204" ]]; then
|
||||
http="$(curl -sS -o /dev/null -w '%{http_code}' \
|
||||
-H 'Content-Type: application/json' -d "${body}" \
|
||||
"${SYNCYOMI_LOCAL}/api/auth/onboard" 2>/dev/null || true)"
|
||||
[[ ${http} =~ ^2 ]] || die "Onboard failed (HTTP ${http}) — check 'docker logs syncyomi'."
|
||||
log_ok "Created first account '${SYNCYOMI_USER}'"
|
||||
else
|
||||
log_warn "An account already exists (onboard HTTP ${http}); trying stored credentials"
|
||||
fi
|
||||
|
||||
# Log in to get a session cookie.
|
||||
http="$(curl -sS -c "${jar}" -o /dev/null -w '%{http_code}' \
|
||||
-H 'Content-Type: application/json' -d "${body}" \
|
||||
"${SYNCYOMI_LOCAL}/api/auth/login" 2>/dev/null || true)"
|
||||
if [[ ! ${http} =~ ^2 ]]; then
|
||||
log_warn "Login failed (HTTP ${http}). A different account may already own this server."
|
||||
log_warn "Create an API key manually at ${SYNCYOMI_LOCAL} → Settings → API Keys."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Reuse an existing 'tachiyomisy' key if one exists (idempotent); otherwise
|
||||
# create one. scopes must be a non-empty array — SyncYomi rejects a null.
|
||||
key="$(curl -sS -b "${jar}" "${SYNCYOMI_LOCAL}/api/keys" 2>/dev/null |
|
||||
jq -r '[.[] | select(.name=="tachiyomisy")][0].key // empty')"
|
||||
if [[ -n ${key} ]]; then
|
||||
log_ok "Reusing existing 'tachiyomisy' API key"
|
||||
else
|
||||
key="$(curl -sS -b "${jar}" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"name":"tachiyomisy","scopes":["read","write"]}' \
|
||||
"${SYNCYOMI_LOCAL}/api/keys" 2>/dev/null | jq -r '.key // empty')"
|
||||
[[ -n ${key} ]] || die "API key creation returned no key — check 'docker logs syncyomi'."
|
||||
fi
|
||||
|
||||
umask 077
|
||||
printf '%s\n' "${key}" >"${TOKEN_FILE}"
|
||||
chmod 600 "${TOKEN_FILE}"
|
||||
log_ok "Minted API key and stored it in ${TOKEN_FILE} (0600)"
|
||||
}
|
||||
|
||||
# --- Step 6: Caddy reverse-proxy block (append + reload) ---------------------
|
||||
configure_caddy() {
|
||||
if grep -qE "^${SYNCYOMI_SUBDOMAIN} \{" "${CADDYFILE}"; then
|
||||
log_ok "Caddyfile already has a block for ${SYNCYOMI_SUBDOMAIN}"
|
||||
else
|
||||
log_info "Adding Caddy block for ${SYNCYOMI_SUBDOMAIN}"
|
||||
# NOTE: appended to the shared Gitea Caddyfile. Re-running setup_gitea.sh
|
||||
# regenerates that file and drops this block — re-run setup_syncyomi.sh
|
||||
# to restore it. Caddyfile uses tab indentation.
|
||||
printf '\n%s {\n\treverse_proxy 127.0.0.1:%s\n}\n' "${SYNCYOMI_SUBDOMAIN}" "${SYNCYOMI_PORT}" \
|
||||
>>"${CADDYFILE}"
|
||||
fi
|
||||
docker exec "${CADDY_CONTAINER}" caddy reload --config "${CADDYFILE_IN_CONTAINER}" ||
|
||||
die "caddy reload failed — check 'docker logs ${CADDY_CONTAINER}'."
|
||||
log_ok "Caddy reloaded (auto-HTTPS will be issued once the subdomain resolves)"
|
||||
}
|
||||
|
||||
# --- Step 7: DuckDNS subdomain (extend existing updater; no new cron) --------
|
||||
configure_duckdns() {
|
||||
local label="${SYNCYOMI_SUBDOMAIN%.duckdns.org}"
|
||||
if grep -qE "domains=[^&\"']*${label}([,&\"']|$)" "${DUCKDNS_UPDATER}"; then
|
||||
log_ok "DuckDNS updater already includes '${label}'"
|
||||
else
|
||||
log_info "Adding '${label}' to the existing DuckDNS updater"
|
||||
sed -i -E "s|(domains=)([^&\"']*)|\1\2,${label}|" "${DUCKDNS_UPDATER}"
|
||||
fi
|
||||
# Refresh now (harmless if the subdomain isn't registered yet).
|
||||
bash "${DUCKDNS_UPDATER}" >/dev/null 2>&1 || log_warn "DuckDNS update returned non-zero (register the subdomain first)."
|
||||
if getent hosts "${SYNCYOMI_SUBDOMAIN}" >/dev/null 2>&1; then
|
||||
log_ok "${SYNCYOMI_SUBDOMAIN} resolves"
|
||||
else
|
||||
log_warn "${SYNCYOMI_SUBDOMAIN} does not resolve yet — create the '${label}' subdomain in the DuckDNS dashboard."
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Step 8: firewall (open 80/443 via the owning script, idempotent) -------
|
||||
ensure_firewall() {
|
||||
if sudo nft list ruleset 2>/dev/null | grep -qE 'dport \{[^}]*80[^}]*443'; then
|
||||
log_ok "Firewall already allows tcp/80 + tcp/443"
|
||||
elif [[ -f ${WG_SCRIPT} ]]; then
|
||||
log_info "Opening 80/443 via setup_wireguard_ssh.sh allow-web"
|
||||
sudo bash "${WG_SCRIPT}" allow-web
|
||||
else
|
||||
log_warn "setup_wireguard_ssh.sh not found — ensure tcp/80+443 are open."
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Step 9: report ----------------------------------------------------------
|
||||
print_report() {
|
||||
local url="https://${SYNCYOMI_SUBDOMAIN}"
|
||||
local key="(create one in the web UI)"
|
||||
[[ -f ${TOKEN_FILE} ]] && key="$(<"${TOKEN_FILE}")"
|
||||
cat <<EOF
|
||||
|
||||
============================================================================
|
||||
SyncYomi is up.
|
||||
Host address : ${url}
|
||||
API key : ${key}
|
||||
Web UI login : ${SYNCYOMI_USER} / (password in ${CONF_FILE})
|
||||
|
||||
TachiyomiSY setup (on the phone):
|
||||
Settings → Data & storage → Sync → SyncYomi
|
||||
Host : ${url}
|
||||
API key : ${key}
|
||||
Use the SAME API key on every device you want to sync.
|
||||
|
||||
If the subdomain is new, create it once in the DuckDNS dashboard
|
||||
(label: ${SYNCYOMI_SUBDOMAIN%.duckdns.org}) so Caddy can issue TLS.
|
||||
|
||||
Acceptance test: on your phone with Wi-Fi OFF (cellular), configure the
|
||||
sync above and confirm the library round-trips.
|
||||
============================================================================
|
||||
EOF
|
||||
}
|
||||
|
||||
# --- status subcommand -------------------------------------------------------
|
||||
status_cmd() {
|
||||
print_setup_header "SyncYomi status"
|
||||
echo
|
||||
if [[ -f ${COMPOSE_FILE} ]]; then
|
||||
docker compose -f "${COMPOSE_FILE}" ps
|
||||
else
|
||||
log_warn "No compose file at ${COMPOSE_FILE}"
|
||||
fi
|
||||
echo
|
||||
|
||||
local code
|
||||
code="$(syncyomi_ready "${SYNCYOMI_LOCAL}" || true)"
|
||||
if [[ ${code} == "204" || ${code} == "403" ]]; then
|
||||
log_ok "Local API answering (${SYNCYOMI_LOCAL}, HTTP ${code})"
|
||||
else
|
||||
log_warn "Local API not answering (HTTP ${code:-none})"
|
||||
fi
|
||||
|
||||
local sub="${SYNCYOMI_SUBDOMAIN:-kuhy-sync.duckdns.org}"
|
||||
if [[ -f ${CONF_FILE} ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "${CONF_FILE}"
|
||||
sub="${SYNCYOMI_SUBDOMAIN}"
|
||||
fi
|
||||
|
||||
if grep -qE "^${sub} \{" "${CADDYFILE}" 2>/dev/null; then
|
||||
log_ok "Caddy block present for ${sub}"
|
||||
else
|
||||
log_warn "No Caddy block for ${sub}"
|
||||
fi
|
||||
|
||||
if getent hosts "${sub}" >/dev/null 2>&1; then
|
||||
log_ok "${sub} resolves"
|
||||
else
|
||||
log_warn "${sub} does not resolve"
|
||||
fi
|
||||
|
||||
code="$(syncyomi_ready "https://${sub}" || true)"
|
||||
if [[ ${code} == "204" || ${code} == "403" ]]; then
|
||||
log_ok "External HTTPS reachable (https://${sub}, HTTP ${code})"
|
||||
else
|
||||
log_warn "External HTTPS not reachable yet (HTTP ${code:-none})"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- main --------------------------------------------------------------------
|
||||
setup_cmd() {
|
||||
print_setup_header "Self-hosted SyncYomi manga sync"
|
||||
preflight
|
||||
load_config
|
||||
write_compose
|
||||
start_containers
|
||||
wait_for_syncyomi
|
||||
ensure_local_config
|
||||
mint_api_key
|
||||
configure_caddy
|
||||
configure_duckdns
|
||||
ensure_firewall
|
||||
print_report
|
||||
}
|
||||
|
||||
main() {
|
||||
local cmd="${1:-setup}"
|
||||
case "${cmd}" in
|
||||
setup) setup_cmd ;;
|
||||
status) status_cmd ;;
|
||||
help | -h | --help) usage ;;
|
||||
*) die "Unknown command '${cmd}' (use: setup | status | help)" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Loading…
Reference in New Issue
Block a user