crosscode: --json reports, --config, env templates, frpc tunnels, restart/export/uninstall/purge

- Every command takes --json (crosscode.script-report/1 on stdout, the
  log on stderr) and --config (the .env values by layer, from the agent).
- .env files come from the release's env.template.json (lib/envtpl.js):
  written whole on install; on deploy only new variables are appended,
  and a new required one with no value stops the deploy at the checks.
- install --frp: Hub-given ports, a marked frpc.ini block (backup,
  frpc verify, reload; [common] admin lines added once), no nginx.
  A database on another server via DB_ADMIN_URL. Refuses an existing
  database or role. Everything the run made is removed if it fails.
- restart, export (crosscode.church-export/1 ZIP), uninstall (final
  backup, uploads and .env kept 30 days) and purge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 12:50:19 +02:00
co-authored by Claude Opus 5.5
parent 350ab9f4e8
commit e9e9b5a97f
17 changed files with 1308 additions and 88 deletions
+57 -6
View File
@@ -24,13 +24,30 @@ if [ -z "${CROSSCODE_HOME:-}" ]; then
CROSSCODE_HOME="$copy" CROSSCODE_FROM="$root" exec bash "$copy/crosscode" "$@"
fi
# Running from the copy: remove it afterwards (only ever a mktemp folder, never a checkout).
if [[ "$CROSSCODE_HOME" == /tmp/crosscode.* ]]; then
trap 'rm -rf "$CROSSCODE_HOME"' EXIT
fi
# Options for every command, taken out of the arguments here: --json (a crosscode.script-report/1
# on stdout at the end, the log on stderr) and --config <file> (the .env values by layer, from
# the agent).
CROSSCODE_JSON=0
CROSSCODE_CONFIG="${CROSSCODE_CONFIG:-}"
args=()
while [ $# -gt 0 ]; do
case "$1" in
--json) CROSSCODE_JSON=1; shift ;;
--config)
[ $# -ge 2 ] || { echo '!!> --config needs a file.' >&2; exit 1; }
CROSSCODE_CONFIG="$2"; shift 2 ;;
*) args+=("$1"); shift ;;
esac
done
set -- "${args[@]+"${args[@]}"}"
export CROSSCODE_CONFIG
# shellcheck source=lib/common.sh
source "$CROSSCODE_HOME/lib/common.sh"
# shellcheck source=lib/env.sh
source "$CROSSCODE_HOME/lib/env.sh"
# shellcheck source=lib/frpc.sh
source "$CROSSCODE_HOME/lib/frpc.sh"
# shellcheck source=lib/deploy.sh
source "$CROSSCODE_HOME/lib/deploy.sh"
# shellcheck source=lib/status.sh
@@ -39,6 +56,32 @@ source "$CROSSCODE_HOME/lib/status.sh"
source "$CROSSCODE_HOME/lib/install.sh"
# shellcheck source=lib/adopt.sh
source "$CROSSCODE_HOME/lib/adopt.sh"
# shellcheck source=lib/manage.sh
source "$CROSSCODE_HOME/lib/manage.sh"
# At the end: the report (with --json), and the copy this runs from is removed (only ever a
# mktemp folder, never a checkout).
on_exit() {
local rc=$?
[ "$CROSSCODE_JSON" != 1 ] || report_emit "$rc"
if [[ "$CROSSCODE_HOME" == /tmp/crosscode.* ]]; then rm -rf "$CROSSCODE_HOME"; fi
return "$rc"
}
trap on_exit EXIT
command="${1:-help}"
[ $# -gt 0 ] && shift
if [ "$CROSSCODE_JSON" = 1 ]; then
# The report goes to the real stdout (fd 3); everything else to stderr.
exec 3>&1 1>&2
report_init "$command"
fi
if [ -n "$CROSSCODE_CONFIG" ]; then
[ -f "$CROSSCODE_CONFIG" ] || die "--config: there's no file $CROSSCODE_CONFIG."
node -e 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))' "$CROSSCODE_CONFIG" 2>/dev/null ||
die "--config: $CROSSCODE_CONFIG isn't JSON."
fi
usage() {
cat <<EOF
@@ -51,19 +94,26 @@ crosscode: Cross Code installs on this server ($(git -C "${CROSSCODE_FROM:-.}" r
crosscode install <church> --products events --domain <address> a new church
crosscode adopt <church> --events-dir <old folder> move an existing Cross Events install here
crosscode adopt <church> --undo go back to the old folder (within 14 days)
crosscode restart <church> [events] reload the PM2 processes
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 help [<command>] this, or a command's options
Every command takes --json (a report at the end) and --config <file> (settings from the Hub).
Churches live in $CROSSCODE_SITES/<church>/ (church.env, one checkout per product).
EOF
}
command="${1:-help}"
[ $# -gt 0 ] && shift
case "$command" in
deploy) cmd_deploy "$@" ;;
status) cmd_status "$@" ;;
install) cmd_install "$@" ;;
adopt) cmd_adopt "$@" ;;
restart) cmd_restart "$@" ;;
export) cmd_export "$@" ;;
uninstall) cmd_uninstall "$@" ;;
purge) cmd_purge "$@" ;;
add) die "\`crosscode add\` comes with the second product (phase 3)." ;;
help|-h|--help)
case "${1:-}" in
@@ -71,6 +121,7 @@ case "$command" in
status) status_usage ;;
install) install_usage ;;
adopt) adopt_usage ;;
restart|export|uninstall|purge) manage_usage ;;
*) usage ;;
esac ;;
*) usage; die "Unknown command \"$command\"." ;;