Compare commits

..
Author SHA1 Message Date
joshuaandClaude Opus 5.5 8899c97a9c Agent 1.5.0 + contracts 1.16.0: uninstall, export and purge one product of a church
crosscode uninstall/export/purge <church> [product ...]: with products named only those
go and the church keeps the others; naming every product it still has removes the church
(folder and app user), so the last product to go takes the church with it. The report
gives products and remaining. Uninstalling cross-events-demo's Events removed its Accounts
too, which the Hub still showed as live.

Contracts 1.16.0: optional products on export/uninstall/purge, PRODUCT_UNINSTALL_MIN_AGENT.
Agent 1.5.0 passes them to crosscode. The Website plan moves to contracts 1.17.0 / Hub 2.13.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 09:17:32 +02:00
joshua e04bfac208 Merge branch 'docs/deployed-frp-release' 2026-11-21 11:13:40 +02:00
17 changed files with 364 additions and 78 deletions
+17
View File
@@ -2,6 +2,23 @@
Each package and app has its own section and its own tags (`contracts@1.0.0`, `accounts@1.0.0`, …).
## agent@1.5.0 + contracts@1.16.0 + crosscode script - 2026-11-23
- **Fix: uninstalling one product removed the whole church.** `crosscode uninstall <church>` only
knew whole churches, while the Hub uninstalls per product: uninstalling cross-events-demo's
Events also removed its Accounts, which the Hub still showed as live, and its own uninstall
failed later ("No church cross-events-demo on this server").
- **`crosscode uninstall|export|purge <church> [product …]`.** With products named, only those
are backed up, kept (`.removed/<church>-<date>/<product>`) and removed; the church keeps the
others in church.env. Naming every product it still has removes the church (folder and app
user), so the last product to go always takes the church with it. The report gives `products`
and `remaining`. `purge` with products deletes only what was kept of those, also while the
church still has others. Without products, as before.
- **Agent 1.5.0** passes `products` through. **Contracts 1.16.0:** optional `products` on the
`export`, `uninstall` and `purge` job arguments, and `PRODUCT_UNINSTALL_MIN_AGENT` (an older
agent refuses the key). Hub 2.12.0 uses them.
- The Church Website plan's versions move up one again: contracts 1.17.0, Hub 2.13.0.
## agent@1.4.0 + contracts@1.15.0 - 2026-11-21
- **Agent 1.4.0: frp's config, wherever it is.** The agent no longer assumes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/agent",
"version": "1.4.0",
"version": "1.5.0",
"private": true,
"description": "The server agent: runs the crosscode script for signed jobs from Cross Code Hub, reports stats (docs/AGENT-1.0-PLAN.md)",
"license": "UNLICENSED",
+4 -3
View File
@@ -62,11 +62,12 @@ export function crosscodeArgs(job: agent.AgentJob, opts: { exportFile?: string }
return ["demo", job.args.church, "--profile", job.args.profile, ...(job.args.adminEmail ? ["--admin-email", job.args.adminEmail] : [])];
case "export":
if (!opts.exportFile) throw new Error("export needs a file to write");
return ["export", job.args.church, "--out", opts.exportFile];
return ["export", job.args.church, ...(job.args.products ?? []), "--out", opts.exportFile];
case "uninstall":
return ["uninstall", job.args.church, "--confirm", job.args.church];
// 1.5.0: only the products named go (the church keeps its others); none named: the church.
return ["uninstall", job.args.church, ...(job.args.products ?? []), "--confirm", job.args.church];
case "purge":
return ["purge", job.args.church, "--confirm", job.args.church];
return ["purge", job.args.church, ...(job.args.products ?? []), "--confirm", job.args.church];
case "status":
return ["status", ...(job.args.church ? [job.args.church] : []), "--no-fetch"];
case "update-agent":
+1 -1
View File
@@ -12,7 +12,7 @@ import { paths } from "./paths";
* the tools that are there; anything missing is null rather than an error.
*/
export const AGENT_VERSION = "1.4.0";
export const AGENT_VERSION = "1.5.0";
function run(cmd: string, args: string[], timeoutMs = 10_000): Promise<string | null> {
return new Promise((resolve) => {
+4
View File
@@ -36,6 +36,10 @@ describe("crosscode arguments for each job", () => {
expect(crosscodeArgs(parsed({ type: "restart", args: { church: "hope" } }))).toEqual(["restart", "hope"]);
expect(crosscodeArgs(parsed({ type: "uninstall", args: { church: "hope" } }))).toEqual(["uninstall", "hope", "--confirm", "hope"]);
expect(crosscodeArgs(parsed({ type: "purge", args: { church: "hope" } }))).toEqual(["purge", "hope", "--confirm", "hope"]);
// 1.5.0: one product of the church.
expect(crosscodeArgs(parsed({ type: "uninstall", args: { church: "hope", products: ["events"] } }))).toEqual(["uninstall", "hope", "events", "--confirm", "hope"]);
expect(crosscodeArgs(parsed({ type: "purge", args: { church: "hope", products: ["events"] } }))).toEqual(["purge", "hope", "events", "--confirm", "hope"]);
expect(crosscodeArgs(parsed({ type: "export", args: { church: "hope", exportId: "exp_abcdefgh", products: ["accounts"] } }), { exportFile: "/x/e.zip" })).toEqual(["export", "hope", "accounts", "--out", "/x/e.zip"]);
expect(crosscodeArgs(parsed({ type: "status", args: {} }))).toEqual(["status", "--no-fetch"]);
});
+1 -1
View File
@@ -85,7 +85,7 @@ Everything up to and including the 2026-11-20 releases is deployed, rolled out a
1. **Phase 5, Church Website 1.0.0** (ROADMAP §6, §9). Planned in
[WEBSITE-1.0-PLAN.md](./WEBSITE-1.0-PLAN.md): decisions all confirmed 2026-11-21. Order:
contracts 1.16.0 → Accounts 1.7.0 → Events 3.7.0 (shared fonts and footer) → Hub 2.12.0 →
contracts 1.17.0 → Accounts 1.7.0 → Events 3.7.0 (shared fonts and footer) → Hub 2.13.0 →
`website@1.0.0` → Hope Family Church → a second church → crosscode-site 1.7.0.
2. **Archive `hope-events`** if it isn't yet (every install now reports 2.2.0 or later;
EVENTS-2.2-PLAN §7).
+1 -1
View File
@@ -641,7 +641,7 @@ Planned in [AGENT-1.0-PLAN.md](./AGENT-1.0-PLAN.md). In short:
| 2 | **Cross Events 2.4.0** | Reports `product: "events"` (protocol v2), **Linked products**, the event feed (publish + show events from siblings), `packages/seo` (§11) with canonical links for imported events. **Planned and built 2026-11-18:** [EVENTS-2.4-PLAN.md](./EVENTS-2.4-PLAN.md) (also needs contracts 1.4.0 and Hub 2.2.0, for a public key in the v2 heartbeat); not tagged yet | Small; ready for when the Website exists |
| 3 | **Accounts 1.0.0** | OIDC provider, sign-in, 2FA (email, WhatsApp, authenticator app), password reset, consent and notice, export / delete fan-out, admin, install script. [ACCOUNTS-1.0-PLAN.md](./ACCOUNTS-1.0-PLAN.md) (with contracts 1.5.0, `packages/auth-client`, Hub 2.3.0). **Released 2026-11-18** (`accounts@1.0.0`, 1.0.1 on 2026-11-19); the VM test and a run on real Postgres are still to do before a church gets it | Every later product signs in through it |
| 4 | **Cross Events 3.0.0** | Sign-in moves to Accounts; user migration keeping password hashes; migration guide. **Planned 2026-11-19:** [EVENTS-3.0-PLAN.md](./EVENTS-3.0-PLAN.md) (with contracts 1.8.0, Accounts 1.1.0, Hub 2.5.0; decisions confirmed 2026-11-19) | Breaking change, so a major version. **Moved before the Website on 2026-11-19** (decision 38): Events is the product churches use today, so Accounts is proven on real users first, and the Website then starts with a church whose people already have accounts |
| 5 | **Church Website 1.0.0** | Public site with the **four templates** (§6), admin, simple events + feed, SEO (§11), Hope Family Church as the first church, then a second test church on a different template to prove it repeats. **Planned 2026-11-21:** [WEBSITE-1.0-PLAN.md](./WEBSITE-1.0-PLAN.md) (with contracts 1.16.0, Accounts 1.7.0, Events 3.7.0 for the shared fonts and footer, Hub 2.12.0) | More churches need a website than an app; it also covers the "website only" case. Built on Accounts from day one |
| 5 | **Church Website 1.0.0** | Public site with the **four templates** (§6), admin, simple events + feed, SEO (§11), Hope Family Church as the first church, then a second test church on a different template to prove it repeats. **Planned 2026-11-21:** [WEBSITE-1.0-PLAN.md](./WEBSITE-1.0-PLAN.md) (with contracts 1.17.0, Accounts 1.7.0, Events 3.7.0 for the shared fonts and footer, Hub 2.13.0) | More churches need a website than an app; it also covers the "website only" case. Built on Accounts from day one |
| 6 | **Church App 1.0.0** | Foundation (PWA, branding, Accounts), House of Prayer, announcements, devotionals, events (simple + feed) | Starts with shared users and the feed already in place |
| 7 | Church App 1.x | Reading plans, sermons, groups, pastoral care, serving, giving links, directory | After House of Prayer is in use |
+15 -5
View File
@@ -1,6 +1,6 @@
# Versions — the latest release of everything
Last updated: 2026-11-21. Taken from the git tags, which is what a release is here (branch → merge →
Last updated: 2026-11-23. Taken from the git tags, which is what a release is here (branch → merge →
tag → push, see [HANDOVER.md](./HANDOVER.md) "Releasing"). **Update this file with every release.**
"Released" means tagged and pushed. Whether a release is **deployed** or rolled out is recorded
@@ -12,11 +12,11 @@ separately below; the two often differ.
|------|------|--------|-----|----------|
| Cross Events | `crosscode-platform` (`apps/events`) | **3.6.1** | `events@3.6.1` | 2026-11-20 |
| Accounts | `crosscode-platform` (`apps/accounts`) | **1.6.0** | `accounts@1.6.0` | 2026-11-20 |
| Server agent | `crosscode-platform` (`apps/agent`) | **1.4.0** | `agent@1.4.0` | 2026-11-21 |
| Contracts | `crosscode-platform` (`packages/contracts`) | **1.15.0** | `contracts@1.15.0` | 2026-11-21 |
| Cross Code Hub | `events-hub` | **2.11.0** | `v2.11.0` | 2026-11-21 |
| Server agent | `crosscode-platform` (`apps/agent`) | **1.5.0** | `agent@1.5.0` | 2026-11-23 |
| Contracts | `crosscode-platform` (`packages/contracts`) | **1.16.0** | `contracts@1.16.0` | 2026-11-23 |
| Cross Code Hub | `events-hub` | **2.12.0** | `v2.12.0` | 2026-11-23 |
| crosscode.co.za | `crosscode-site` | **1.6.0** | `v1.6.0` | 2026-11-19 |
| `crosscode` script | `crosscode-platform` (`scripts/`) | `main` | none | 2026-11-20 (last change: Accounts' pre-deploy dumps don't stop a deploy) |
| `crosscode` script | `crosscode-platform` (`scripts/`) | `main` | none | 2026-11-23 (last change: uninstall, export and purge one product of a church) |
The `crosscode` script has no version: every server's copy (`/opt/crosscode/tools`) pulls `main`
on each run, so merging to `main` and pushing releases it. Its changes are listed in
@@ -37,6 +37,16 @@ need their own tags until something outside this repo depends on them.
## What each latest release was for
- **Agent 1.5.0 + contracts 1.16.0 + Hub 2.12.0 + `crosscode` script (2026-11-23):** uninstalling
one product no longer removes the whole church (it removed cross-events-demo's Accounts with its
Events, which the Hub still showed as live). `crosscode uninstall|export|purge <church>
[product …]`; the last product to go removes the church. On the Hub: a second product's
uninstall can join one already planned or get its own time; Accounts goes last; a stale install
(no heartbeat for 24 hours) can be removed from the Hub; customers can be archived; a customer's
email and billing email take several addresses; statements show R0 invoices' amounts. **Update
the agents first** (the Hub refuses a one-product uninstall on an older agent while the church
has other products), then deploy the Hub (migration `20261123090000_customer_archive`).
- **Agent 1.4.0 + contracts 1.15.0 + Hub 2.11.0:** the agent finds frps's / frpc's config wherever
it is (the path set on the Hub, the systemd unit's `-c`, the usual places) and reads TOML too;
each server's Hub page reads and changes that config (secrets stay on the server, `verify`,
+7 -7
View File
@@ -17,7 +17,7 @@ prove it repeats. Then it goes on sale (crosscode-site, ROADMAP §9).
**Done when:**
- `website@1.0.0`, `contracts@1.16.0`, `accounts@1.7.0`, `events@3.7.0` and Hub `v2.12.0` are
- `website@1.0.0`, `contracts@1.17.0`, `accounts@1.7.0`, `events@3.7.0` and Hub `v2.13.0` are
tagged; the Hub installs the Website from New install (after Accounts) and lists its releases.
- All four templates pass the same checks (§13) at phone, tablet and desktop sizes: layout, axe, the
§11 SEO checks, and Lighthouse (SEO 100, accessibility 95+, performance 90+).
@@ -88,7 +88,7 @@ them (phase 6–7).
| Shared: `crosscode.church/1` | Website-only |
|---|---|
| Already there: name, short name, logo, icon, colours, campuses, service times, contact, social, links | Template, section variants, style settings other than fonts and corners (§3), homepage order |
| **New in contracts 1.16.0:** `branding.style`: `fontPairing` (an id from the shared list, §3) and `corners` (`sharp` / `soft` / `round`). Optional and additive, so a minor version | Pages, sections and blocks, navigation, custom pages |
| **New in contracts 1.17.0:** `branding.style`: `fontPairing` (an id from the shared list, §3) and `corners` (`sharp` / `soft` / `round`). Optional and additive, so a minor version | Pages, sections and blocks, navigation, custom pages |
| | About (story, mission, vision, values, beliefs), Plan your visit, Leaders, Ministries, Give |
| | Messages and series (§7), simple events (§8), media library, per-page SEO |
| | Drafts, published versions, preview links |
@@ -293,7 +293,7 @@ only freed when neither the working copy nor the last 10 published versions use
- **Hub protocol v2, product `website`.** The heartbeat's `websiteStatsSchema` is already in the
contracts (pages, messages, events, editors, storage). A Website licence needs the church's
Accounts, installed first (as Events 3.x).
- **Hub 2.12.0:** New install offers the Website; release sync for `website@` tags and
- **Hub 2.13.0:** New install offers the Website; release sync for `website@` tags and
`apps/website/WHATS-NEW.md`; its env template; the Website's price (R99) and the storage add-on
(R20 per extra 5 GB, sent to the site with the licence as its storage limit, and the "Get more storage"
request with its email to Joshua) in `frontend/src/lib/tiers.ts` and `backend/src/utils/billing/tiers.js`, in
@@ -317,13 +317,13 @@ only freed when neither the working copy nor the last 10 published versions use
| Repo | Change | Version |
|------|--------|---------|
| `crosscode-platform` `apps/website` | New (§1–§11), with `CHANGELOG.md`, `WHATS-NEW.md`, `env.template.json`, e2e, demo data | `website@1.0.0` |
| `crosscode-platform` `packages/contracts` | `branding.style` (`fontPairing`, `corners`) on `crosscode.church/1`, the font pairing ids, a `website` part of the church export | `contracts@1.16.0` |
| `crosscode-platform` `packages/contracts` | `branding.style` (`fontPairing`, `corners`) on `crosscode.church/1`, the font pairing ids, a `website` part of the church export | `contracts@1.17.0` |
| `crosscode-platform` `packages/ui` | Fonts (self-hosted), the theme from the profile (colours, fonts, corners as CSS variables), `ChurchFooter`, links between products, the public site's building blocks | workspace |
| `crosscode-platform` `packages/seo` | `Church`, `VideoObject`, `PodcastEpisode`, `BreadcrumbList` builders, the generated share image | workspace |
| `crosscode-platform` `apps/accounts` | `branding.style` in the church profile, the shared fonts and footer, the Website's admins saving the profile | `accounts@1.7.0` |
| `crosscode-platform` `apps/events` | Public pages with the shared fonts, corners and footer | `events@3.7.0` |
| `crosscode-platform` `scripts/` | `products/website.sh`, `website.env.template.json`, bats tests | — |
| `events-hub` | Website in New install, its releases, env template, prices and storage add-on, FastPanel email | Hub `v2.12.0` |
| `events-hub` | Website in New install, its releases, env template, prices and storage add-on, FastPanel email | Hub `v2.13.0` |
| `crosscode-site` | Church Website on sale (ROADMAP §9): its page, prices, a page per template, screenshots of the demo church, FAQ, `SoftwareApplication` JSON-LD | `v1.7.0` |
## 13. Testing
@@ -349,8 +349,8 @@ only freed when neither the working copy nor the last 10 published versions use
## 14. Releasing and rolling it out
1. `contracts@1.16.0`, then `accounts@1.7.0` (the profile's brand style), then `events@3.7.0`.
2. Hub `v2.12.0` (vendored contracts 1.16.0) deployed.
1. `contracts@1.17.0`, then `accounts@1.7.0` (the profile's brand style), then `events@3.7.0`.
2. Hub `v2.13.0` (vendored contracts 1.17.0) deployed.
3. `website@1.0.0` tagged after the e2e, Lighthouse and VM runs.
4. **Hope Family Church:** Accounts 1.7.0 and Events 3.7.0 first, then New install → Website. The
site shows Coming soon while the church builds it, and goes live with its first publish.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/contracts",
"version": "1.15.0",
"version": "1.16.0",
"description": "The shared JSON formats used by every Cross Code product: zod schemas, JSON Schema, TypeScript types and sample payloads",
"license": "UNLICENSED",
"type": "commonjs",
+42
View File
@@ -1177,6 +1177,20 @@
"exportId": {
"type": "string",
"pattern": "^exp_[A-Za-z0-9_-]{8,64}$"
},
"products": {
"minItems": 1,
"maxItems": 4,
"type": "array",
"items": {
"type": "string",
"enum": [
"events",
"website",
"app",
"accounts"
]
}
}
},
"required": [
@@ -1273,6 +1287,20 @@
"church": {
"type": "string",
"pattern": "^[a-z][a-z0-9-]{1,30}$"
},
"products": {
"minItems": 1,
"maxItems": 4,
"type": "array",
"items": {
"type": "string",
"enum": [
"events",
"website",
"app",
"accounts"
]
}
}
},
"required": [
@@ -1368,6 +1396,20 @@
"church": {
"type": "string",
"pattern": "^[a-z][a-z0-9-]{1,30}$"
},
"products": {
"minItems": 1,
"maxItems": 4,
"type": "array",
"items": {
"type": "string",
"enum": [
"events",
"website",
"app",
"accounts"
]
}
}
},
"required": [
+17 -6
View File
@@ -84,6 +84,13 @@ export const ENV_SET_MAX = 50;
/** The first agent that runs `frp-read`, `frp-write` and `probe-ports` jobs (an older one refuses the unknown types). */
export const FRP_JOBS_MIN_AGENT = "1.4.0";
/**
* The first agent that takes `products` on `export`, `uninstall` and `purge` (only those products
* go; the church keeps its others). An older one refuses the key, and uninstalls the whole church
* without it.
*/
export const PRODUCT_UNINSTALL_MIN_AGENT = "1.5.0";
/**
* Where frps (central server) or frpc (church server) keeps its config: an absolute path to a file
* whose name starts with `frp` and ends in `.ini` or `.toml` (`/etc/frp/frps.toml`).
@@ -162,12 +169,16 @@ export const jobArgsSchemas = {
if (secret) issue(`${secret} is a secret: it can't be changed from the Hub`);
if (a.unset.some((n) => Object.prototype.hasOwnProperty.call(a.set, n))) issue("A name can't be both set and removed");
}),
/** `crosscode export <church> --out <zip> --json`; the agent encrypts the ZIP and uploads it under `exportId`. */
export: z.strictObject({ church: shortNameSchema, exportId: z.string().regex(/^exp_[A-Za-z0-9_-]{8,64}$/) }),
/** `crosscode uninstall <church> --json` */
uninstall: z.strictObject({ church: shortNameSchema }),
/** `crosscode purge <church> --json` (deletes what uninstall kept for 30 days) */
purge: z.strictObject({ church: shortNameSchema }),
/** `crosscode export <church> [products] --out <zip> --json`; the agent encrypts the ZIP and uploads it under `exportId`. */
export: z.strictObject({ church: shortNameSchema, exportId: z.string().regex(/^exp_[A-Za-z0-9_-]{8,64}$/), products: z.array(productSchema).min(1).max(4).optional() }),
/**
* `crosscode uninstall <church> [products] --json`. With `products` (agent 1.5.0, {@link
* PRODUCT_UNINSTALL_MIN_AGENT}) only those go and the church keeps its others; without it, or
* naming every product, the whole church goes.
*/
uninstall: z.strictObject({ church: shortNameSchema, products: z.array(productSchema).min(1).max(4).optional() }),
/** `crosscode purge <church> [products] --json` (deletes what uninstall kept for 30 days: with `products`, only what was kept of those) */
purge: z.strictObject({ church: shortNameSchema, products: z.array(productSchema).min(1).max(4).optional() }),
/** The agent updates itself to that tag. */
"update-agent": z.strictObject({ version: agentTagSchema }),
/**
+14
View File
@@ -275,3 +275,17 @@ describe("frp config and free ports (1.15.0)", () => {
expect(agent.probePortsResultSchema.safeParse({ ports: [{ port: 20000, free: false, reason: "in use" }], configPath: null }).success).toBe(true);
});
});
describe("uninstalling one product (contracts 1.16.0)", () => {
const ok = (type: "export" | "uninstall" | "purge", args: unknown) => agent.jobArgsSchemas[type].safeParse(args).success;
it("export, uninstall and purge take the products, or none (the whole church)", () => {
for (const type of ["uninstall", "purge"] as const) {
expect(ok(type, { church: "hope" })).toBe(true);
expect(ok(type, { church: "hope", products: ["events"] })).toBe(true);
expect(ok(type, { church: "hope", products: [] })).toBe(false);
expect(ok(type, { church: "hope", products: ["everything"] })).toBe(false);
}
expect(ok("export", { church: "hope", exportId: "exp_abcdefgh", products: ["accounts"] })).toBe(true);
expect(agent.PRODUCT_UNINSTALL_MIN_AGENT).toBe("1.5.0");
});
});
+5 -3
View File
@@ -98,9 +98,11 @@ crosscode: Cross Code installs on this server ($(git -C "${CROSSCODE_FROM:-.}" r
crosscode restart <church> [events] reload the PM2 processes
crosscode demo <church> --profile <profile> replace Events' data with a demo set
crosscode env <church> <product> [--set NAME=value] show or change a product's .env values
crosscode export <church> --out <file.zip> the church's data and uploads
crosscode uninstall <church> --confirm <church> remove it (a final backup is kept 30 days)
crosscode purge <church> --confirm <church> delete what uninstall kept
crosscode export <church> [product …] --out <zip> the church's data and uploads
crosscode uninstall <church> [product …] --confirm <church>
remove it, or only those products (a final
backup is kept 30 days)
crosscode purge <church> [product …] --confirm <church> delete what uninstall kept
crosscode help [<command>] this, or a command's options
Every command takes --json (a report at the end) and --config <file> (settings from the Hub).
+131 -48
View File
@@ -15,12 +15,18 @@ crosscode env <church> <product> [--file backend/.env] --set NAME=value … [--u
change values (a copy is kept; never secrets or
generated values). The frontend's file rebuilds it.
If it doesn't start again, the file is put back.
crosscode export <church> --out <file.zip> the church's data (crosscode.church-export/1) and uploads
crosscode uninstall <church> --confirm <church>
crosscode export <church> [product …] --out <file.zip>
the church's data (crosscode.church-export/1) and
uploads: every product, or only those named
crosscode uninstall <church> [product …] --confirm <church>
final backup and uploads kept in
/var/www/sites/.removed/<church>-<date>/ (30 days),
then PM2, tunnels, database and folders removed
crosscode purge <church> --confirm <church> delete what uninstall kept
then PM2, tunnels, database and folders removed.
With products named only those go, and the church
keeps its others (naming every one = the church)
crosscode purge <church> [product …] --confirm <church>
delete what uninstall kept (with products named:
only what was kept of those)
All take --json (a report at the end; the log goes to stderr).
EOF
@@ -36,6 +42,21 @@ manage_products() {
return 0
}
# manage_check_named <product …>: stops unless the church (loaded) has each product named. Call it
# directly, not in $(…): die only stops the shell it runs in.
manage_check_named() {
local p
for p in "$@"; do
is_supported_product "$p" || die "Unknown product \"$p\" (this version handles: ${SUPPORTED_PRODUCTS[*]})."
church_has_product "$p" || die "$(cenv CHURCH) has no $p (its products: $(cenv PRODUCTS))."
done
}
# manage_named [product …]: those products in deploy order; none named: every product.
manage_named() {
if [ $# -gt 0 ]; then in_product_order "$@"; else manage_products; fi
}
cmd_restart() {
local church="" p
local -a named=()
@@ -198,14 +219,22 @@ cmd_env() {
die "$product didn't start with the new values, so $file was put back as it was."
}
# json_words <word …>: a JSON array of plain words (product names), e.g. ["accounts","events"].
json_words() {
local w out=""
for w in "$@"; do out+="${out:+,}\"$w\""; done
printf '[%s]' "$out"
}
cmd_export() {
local church="" out="" p tmp dir user bytes
local -a named=() products=()
while [ $# -gt 0 ]; do
case "$1" in
--out) [ $# -ge 2 ] || die "--out needs a file."; out="$2"; shift 2 ;;
-h|--help) manage_usage; return 0 ;;
-*) die "Unknown option $1 (crosscode help export)." ;;
*) [ -z "$church" ] || die "One church at a time."; church="$1"; shift ;;
*) if [ -z "$church" ]; then church="$1"; else named+=("$1"); fi; shift ;;
esac
done
[ -n "$church" ] || die "Name the church."
@@ -213,6 +242,9 @@ cmd_export() {
[ ! -e "$out" ] || die "$out exists already."
require_root
load_church "$church"
manage_check_named "${named[@]}"
mapfile -t products < <(manage_named "${named[@]}")
[ "${#products[@]}" -gt 0 ] || die "$church has nothing to export."
command -v zip >/dev/null || die "zip isn't installed (apt-get install zip)."
tmp="$(mktemp -d)"
chmod 755 "$tmp"
@@ -220,7 +252,7 @@ cmd_export() {
set +e
(
set -e
for p in $(manage_products); do
for p in "${products[@]}"; do
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/$p.sh"
dir="$(pvar "$p" DIR)"; user="$(pvar "$p" USER)"
@@ -233,8 +265,8 @@ cmd_export() {
done
step "Zipping"
# One product: its folder is the ZIP's top level (export.json, uploads/, README.txt).
if [ "$(manage_products | wc -l)" = 1 ]; then
(cd "$tmp/$(manage_products)" && zip -qr "$out" .)
if [ "${#products[@]}" = 1 ]; then
(cd "$tmp/${products[0]}" && zip -qr "$out" .)
else
(cd "$tmp" && zip -qr "$out" .)
fi
@@ -247,31 +279,71 @@ cmd_export() {
bytes="$(stat -c %s "$out")"
report_result file "$out"
report_result_json bytes "$bytes"
step "Exported $church to $out ($bytes bytes)"
report_result_json products "$(json_words "${products[@]}")"
step "Exported $church (${products[*]}) to $out ($bytes bytes)"
}
# uninstall_product <church> <product>: stops and removes one product, once its final backup is
# kept: PM2, frpc tunnels, nginx site, database, and the old folder from an adopt.
uninstall_product() {
local church="$1" p="$2" user db old name
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/$p.sh"
user="$(pvar "$p" USER)"; db="$(pvar "$p" DB)"
step "$p: stopping and removing the PM2 processes"
# shellcheck disable=SC2046 # the PM2 names are a space-separated list
run_as "$user" / pm2 delete $("${p}_pm2_names") >/dev/null 2>&1 || true
run_as "$user" / pm2 save --force >/dev/null 2>&1 || true
if [ -f "$FRPC_INI" ] && frpc_has_block "$church" "$p"; then
step "$p: removing the frpc tunnels"
frpc_remove "$church" "$p"
frpc_reload
fi
name="$church-$p"
if [ -f "/etc/nginx/sites-available/$name" ]; then
step "$p: removing the nginx site"
rm -f "/etc/nginx/sites-enabled/$name" "/etc/nginx/sites-available/$name"
if nginx -t >/dev/null 2>&1; then systemctl reload nginx; else warn "nginx didn't reload: check nginx -t."; fi
fi
if [ -n "$db" ]; then
step "$p: dropping the database $db"
db_drop "$db"
fi
old="$(pvar "$p" OLD_DIR)"
if [ -n "$old" ] && [ -d "$old" ]; then rm -rf -- "$old"; info "Removed the old folder $old."; fi
}
cmd_uninstall() {
local church="" confirm="" p dir user db kept old name
local church="" confirm="" p dir user kept key
local -a named=() products=() order=() left=()
while [ $# -gt 0 ]; do
case "$1" in
--confirm) [ $# -ge 2 ] || die "--confirm needs the church's name."; confirm="$2"; shift 2 ;;
-h|--help) manage_usage; return 0 ;;
-*) die "Unknown option $1 (crosscode help uninstall)." ;;
*) [ -z "$church" ] || die "One church at a time."; church="$1"; shift ;;
*) if [ -z "$church" ]; then church="$1"; else named+=("$1"); fi; shift ;;
esac
done
[ -n "$church" ] || die "Name the church."
[ "$confirm" = "$church" ] || die "Uninstalling removes $church's sites and databases: add --confirm $church."
require_root
load_church "$church"
manage_check_named "${named[@]}"
mapfile -t products < <(manage_named "${named[@]}")
# What the church keeps: every product of it not named (also ones this version can't handle).
for p in $(cenv PRODUCTS); do
[[ " ${products[*]} " == *" $p "* ]] || left+=("$p")
done
kept="$CROSSCODE_REMOVED/$church-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$kept"
chmod 700 "$CROSSCODE_REMOVED" "$kept"
report_result kept "$kept"
report_result_json products "$(json_words "${products[@]}")"
report_result_json remaining "$(json_words "${left[@]}")"
# 1. Keep a final backup, the uploads and the .env files (the backup needs JWT_SECRET to read
# stored secrets) for 30 days. Nothing is removed until this has worked for every product.
for p in $(manage_products); do
for p in "${products[@]}"; do
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/$p.sh"
dir="$(pvar "$p" DIR)"; user="$(pvar "$p" USER)"
@@ -282,37 +354,30 @@ cmd_uninstall() {
done
# 2. Remove, last product first.
local -a order
mapfile -t order < <(manage_products | tac)
for p in "${order[@]}"; do
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/$p.sh"
dir="$(pvar "$p" DIR)"; user="$(pvar "$p" USER)"; db="$(pvar "$p" DB)"
step "$p: stopping and removing the PM2 processes"
# shellcheck disable=SC2046 # the PM2 names are a space-separated list
run_as "$user" / pm2 delete $("${p}_pm2_names") >/dev/null 2>&1 || true
run_as "$user" / pm2 save --force >/dev/null 2>&1 || true
if [ -f "$FRPC_INI" ] && frpc_has_block "$church" "$p"; then
step "$p: removing the frpc tunnels"
frpc_remove "$church" "$p"
frpc_reload
fi
name="$church-$p"
if [ -f "/etc/nginx/sites-available/$name" ]; then
step "$p: removing the nginx site"
rm -f "/etc/nginx/sites-enabled/$name" "/etc/nginx/sites-available/$name"
if nginx -t >/dev/null 2>&1; then systemctl reload nginx; else warn "nginx didn't reload: check nginx -t."; fi
fi
if [ -n "$db" ]; then
step "$p: dropping the database $db"
db_drop "$db"
fi
old="$(pvar "$p" OLD_DIR)"
if [ -n "$old" ] && [ -d "$old" ]; then rm -rf -- "$old"; info "Removed the old folder $old."; fi
done
mapfile -t order < <(printf '%s\n' "${products[@]}" | tac)
for p in "${order[@]}"; do uninstall_product "$church" "$p"; done
# 3a. The church keeps other products: only the removed ones' folders and church.env lines go.
if [ "${#left[@]}" -gt 0 ]; then
for p in "${order[@]}"; do
dir="$(pvar "$p" DIR)"
if [ -n "$dir" ] && [ "$(dirname "$dir")" = "$(church_dir "$church")" ] && [ -d "$dir" ]; then
step "$p: removing $dir"
rm -rf -- "$dir"
fi
for key in "${!CENV[@]}"; do
[[ "$key" == "$(upper "$p")_"* ]] && church_env_unset "$key"
done
done
church_env_set PRODUCTS "${left[*]}"
church_env_write "$(church_env_path "$church")"
step "Uninstalled ${products[*]} of $church, which keeps ${left[*]}. Kept until purged (30 days): $kept"
return 0
fi
# 3b. Nothing is left: the church goes.
step "Removing $(church_dir "$church")"
user="$(pvar events USER)"
user="$(pvar events USER "$(pvar accounts USER)")"
rm -rf -- "$(church_dir "$church")"
# The app user goes too when crosscode made it for this church (cc-<church>).
if [ "$user" = "cc-$church" ] && id "$user" >/dev/null 2>&1; then
@@ -325,27 +390,45 @@ cmd_uninstall() {
}
cmd_purge() {
local church="" confirm="" d n=0
local church="" confirm="" d p n=0
local -a named=()
while [ $# -gt 0 ]; do
case "$1" in
--confirm) [ $# -ge 2 ] || die "--confirm needs the church's name."; confirm="$2"; shift 2 ;;
-h|--help) manage_usage; return 0 ;;
-*) die "Unknown option $1 (crosscode help purge)." ;;
*) [ -z "$church" ] || die "One church at a time."; church="$1"; shift ;;
*) if [ -z "$church" ]; then church="$1"; else named+=("$1"); fi; shift ;;
esac
done
[ -n "$church" ] || die "Name the church."
valid_slug "$church" || die "\"$church\" isn't a church name."
for p in "${named[@]}"; do is_known_product "$p" || die "Unknown product \"$p\"."; done
[ "$confirm" = "$church" ] || die "Purging deletes $church's last backup for good: add --confirm $church."
require_root
[ ! -f "$(church_env_path "$church")" ] || die "$church is still installed here; purge only deletes what uninstall kept."
if [ "${#named[@]}" -eq 0 ]; then
[ ! -f "$(church_env_path "$church")" ] || die "$church is still installed here; purge only deletes what uninstall kept (name the products that were uninstalled)."
elif church_env_read "$(church_env_path "$church")"; then
for p in "${named[@]}"; do
! church_has_product "$p" || die "$church still has $p here; purge only deletes what uninstall kept."
done
fi
for d in "$CROSSCODE_REMOVED/$church"-*; do
[ -d "$d" ] || continue
[[ "$(basename "$d")" =~ ^${church}-[0-9]{8}-[0-9]{6}$ ]] || continue
step "Deleting $d"
rm -rf -- "$d"
n=$((n + 1))
if [ "${#named[@]}" -eq 0 ]; then
step "Deleting $d"
rm -rf -- "$d"
n=$((n + 1))
continue
fi
for p in "${named[@]}"; do
[ -d "$d/$p" ] || continue
step "Deleting $d/$p"
rm -rf -- "${d:?}/$p"
n=$((n + 1))
done
rmdir -- "$d" 2>/dev/null || true
done
report_result_json deleted "$n"
[ "$n" -gt 0 ] || info "Nothing kept for $church."
[ "$n" -gt 0 ] || info "Nothing kept for $church${named[*]:+ (${named[*]})}."
}
+1 -1
View File
@@ -62,7 +62,7 @@ json() { node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const
@test "help lists the new commands" {
run bash "$CC" help
[[ "$output" == *"crosscode uninstall <church> --confirm <church>"* ]]
[[ "$output" == *"crosscode uninstall <church> [product …] --confirm <church>"* ]]
[[ "$output" == *"--json"* ]]
run bash "$CC" help export
[[ "$output" == *"crosscode.church-export/1"* ]]
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env bats
# crosscode uninstall / purge (lib/manage.sh) with products named: only those go, and the church
# keeps the others in church.env. Naming every product removes the church, as before.
setup() {
export CROSSCODE_NO_UPDATE=1 CROSSCODE_TEST=1
TMP="$BATS_TEST_TMPDIR"
CALLS="$TMP/calls"
: > "$CALLS"
export CROSSCODE_SITES="$TMP/sites" FRPC_INI="$TMP/frpc.ini"
# shellcheck source=../lib/common.sh
source "$BATS_TEST_DIRNAME/../lib/common.sh"
# shellcheck source=../lib/frpc.sh
source "$BATS_TEST_DIRNAME/../lib/frpc.sh"
# shellcheck source=../lib/manage.sh
source "$BATS_TEST_DIRNAME/../lib/manage.sh"
# A church with Accounts and Events, and the products' hooks recording what they'd do.
export CROSSCODE_HOME="$TMP/home"
mkdir -p "$CROSSCODE_HOME/products" "$TMP/sites/hope/accounts" "$TMP/sites/hope/events"
for p in accounts events; do
cat > "$CROSSCODE_HOME/products/$p.sh" <<EOF
${p}_backup() { echo "backup $p" >> "$CALLS"; }
${p}_keep() { mkdir -p "\$2"; echo "keep $p" >> "$CALLS"; }
${p}_pm2_names() { echo "hope-$p-backend hope-$p-frontend"; }
EOF
done
cat > "$TMP/sites/hope/church.env" <<EOF
CHURCH=hope
PRODUCTS="accounts events"
ADDRESS=hope.co.za
ACCOUNTS_DIR=$TMP/sites/hope/accounts
ACCOUNTS_DB=hope_accounts
ACCOUNTS_DOMAIN=accounts.hope.co.za
ACCOUNTS_USER=cc-hope
EVENTS_DIR=$TMP/sites/hope/events
EVENTS_DB=hope_events
EVENTS_DOMAIN=events.hope.co.za
EVENTS_USER=cc-hope
EOF
run_as() { echo "run $3 $4" >> "$CALLS"; }
db_drop() { echo "drop $1" >> "$CALLS"; }
}
@test "one product named: only it goes, the church keeps the other" {
run cmd_uninstall hope events --confirm hope
[ "$status" -eq 0 ]
grep -q "backup events" "$CALLS"
! grep -q "backup accounts" "$CALLS"
grep -q "drop hope_events" "$CALLS"
! grep -q "drop hope_accounts" "$CALLS"
[ ! -e "$TMP/sites/hope/events" ]
[ -d "$TMP/sites/hope/accounts" ]
grep -q '^PRODUCTS=accounts$' "$TMP/sites/hope/church.env"
! grep -q '^EVENTS_' "$TMP/sites/hope/church.env"
grep -q '^ACCOUNTS_DB=hope_accounts$' "$TMP/sites/hope/church.env"
[[ "$output" == *"which keeps accounts"* ]]
ls -d "$TMP/sites/.removed"/hope-*/events
}
@test "then the other: the church goes" {
run cmd_uninstall hope events --confirm hope
[ "$status" -eq 0 ]
run cmd_uninstall hope accounts --confirm hope
[ "$status" -eq 0 ]
[ ! -e "$TMP/sites/hope" ]
[[ "$output" == *"Uninstalled hope."* ]]
}
@test "no product named: the whole church, as before" {
run cmd_uninstall hope --confirm hope
[ "$status" -eq 0 ]
grep -q "drop hope_events" "$CALLS"
grep -q "drop hope_accounts" "$CALLS"
[ ! -e "$TMP/sites/hope" ]
}
@test "a product the church doesn't have is refused before anything happens" {
sed -i 's/^PRODUCTS=.*/PRODUCTS=accounts/' "$TMP/sites/hope/church.env"
run cmd_uninstall hope events --confirm hope
[ "$status" -eq 1 ]
[[ "$output" == *"hope has no events"* ]]
[ ! -s "$CALLS" ]
run cmd_uninstall hope website2 --confirm hope
[ "$status" -eq 1 ]
}
@test "purge with a product: only what was kept of it, also while the church is still here" {
run cmd_uninstall hope events --confirm hope
[ "$status" -eq 0 ]
kept="$(ls -d "$TMP/sites/.removed"/hope-*)"
mkdir -p "$kept/accounts"
run cmd_purge hope events --confirm hope
[ "$status" -eq 0 ]
[ ! -e "$kept/events" ]
[ -d "$kept/accounts" ]
# Accounts is still installed: its kept copy isn't purged, nor the whole church.
run cmd_purge hope accounts --confirm hope
[ "$status" -eq 1 ]
run cmd_purge hope --confirm hope
[ "$status" -eq 1 ]
}