summaryrefslogtreecommitdiff
path: root/tools/copland/scripts
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-09-04 09:05:24 +0200
committercashmere <cashmere@autistici.org>2026-09-04 09:05:24 +0200
commit4f49b16079b27d7ce633619e4cddfdf2bffbc952 (patch)
treec296c1e7f3c3e2f6859c6d3a1b1b208779b89679 /tools/copland/scripts
downloadrelic-master.tar.gz
initial commitHEADmaster
Diffstat (limited to 'tools/copland/scripts')
-rw-r--r--tools/copland/scripts/build-config.mjs30
-rwxr-xr-xtools/copland/scripts/create-demo.sh113
-rwxr-xr-xtools/copland/scripts/fossil-env.sh42
-rwxr-xr-xtools/copland/scripts/install-repolist.sh34
-rwxr-xr-xtools/copland/scripts/install.sh24
-rwxr-xr-xtools/copland/scripts/preview.sh31
6 files changed, 274 insertions, 0 deletions
diff --git a/tools/copland/scripts/build-config.mjs b/tools/copland/scripts/build-config.mjs
new file mode 100644
index 0000000..0a24317
--- /dev/null
+++ b/tools/copland/scripts/build-config.mjs
@@ -0,0 +1,30 @@
+import { mkdir, readFile, writeFile } from "node:fs/promises";
+import { dirname, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
+const skinDir = resolve(projectRoot, "../../skins/copland");
+const outputPath = resolve(projectRoot, "dist/copland-skin.config");
+const parts = ["css", "header", "footer", "details", "js"];
+
+function fossilQuote(value) {
+ return `'${value.replaceAll("'", "''")}'`;
+}
+
+const records = [];
+for (const name of parts) {
+ const value = await readFile(resolve(skinDir, `${name}.txt`), "utf8");
+ const record = `1 ${fossilQuote(name)} value ${fossilQuote(value)}`;
+ records.push(`config /config ${Buffer.byteLength(record, "utf8")}\n${record}\n`);
+}
+
+const header = [
+ "# Copland Fossil skin configuration",
+ "# Generated deterministically by tools/copland/scripts/build-config.mjs.",
+ "# Import with: fossil configuration import dist/copland-skin.config -R REPOSITORY",
+ "",
+].join("\n");
+
+await mkdir(dirname(outputPath), { recursive: true });
+await writeFile(outputPath, header + records.join(""), "utf8");
+console.log(`Wrote ${outputPath}`);
diff --git a/tools/copland/scripts/create-demo.sh b/tools/copland/scripts/create-demo.sh
new file mode 100755
index 0000000..7027e48
--- /dev/null
+++ b/tools/copland/scripts/create-demo.sh
@@ -0,0 +1,113 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+root_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+source "$root_dir/scripts/fossil-env.sh"
+
+if [[ $# -ne 1 ]]; then
+ printf 'Usage: %s TARGET_DIRECTORY\n' "$0" >&2
+ exit 2
+fi
+
+target_dir=$1
+mkdir -p "$target_dir/repositories" "$target_dir/checkouts"
+
+create_repository() {
+ local slug=$1
+ local title=$2
+ local repository="$target_dir/repositories/$slug.fossil"
+ local checkout="$target_dir/checkouts/$slug"
+
+ local is_new=0
+ if [[ ! -f "$repository" ]]; then
+ is_new=1
+ "$FOSSIL" init \
+ --admin-user copland \
+ --date-override 2024-01-01T12:00:00Z \
+ --project-name "$title" \
+ "$repository" >/dev/null
+ fi
+ "$FOSSIL" user default copland -R "$repository"
+ mkdir -p "$checkout"
+ if [[ ! -f "$checkout/.fslckout" && ! -f "$checkout/_FOSSIL_" ]]; then
+ (
+ cd /tmp
+ "$FOSSIL" open --nested --workdir "$checkout" "$repository" >/dev/null
+ )
+ fi
+ (
+ cd "$checkout"
+ "$FOSSIL" user default copland
+ if [[ "$is_new" -eq 1 ]]; then
+ mkdir -p src
+ printf '#+title: %s\n\nA small repository used to preview the Copland Fossil skin.\n\n* Usage\n\nRun the example from a C compiler.\n' "$title" > README.org
+ printf '#include <stdio.h>\n\nint main(void) {\n puts("hello from %s");\n return 0;\n}\n' "$slug" > src/main.c
+ fi
+ if [[ ! -f docs/org-support.org ]]; then
+ mkdir -p docs
+ printf '%s\n' \
+ '#+title: Native Org preview' \
+ '#+author: Copland' \
+ '#+date: 2026-08-21' \
+ '#+options: toc:2' \
+ '' \
+ '* Overview' \
+ '' \
+ 'This public fixture demonstrates *bold*, /italic/, _underlined_,' \
+ '+struck+, ~code~, and =verbatim= text.' \
+ '' \
+ '- Rendered by Fossil' \
+ ' 1. Nested ordered item' \
+ '- [[file:../README.org][Back to the README]]' \
+ '' \
+ '* Data' \
+ '' \
+ '| Format | Native |' \
+ '|--------+--------|' \
+ '| Org | yes |' \
+ '' \
+ '#+begin_src nix' \
+ '{ pkgs ? import <nixpkgs> {} }: pkgs.hello' \
+ '#+end_src' \
+ '' \
+ '#+begin_example' \
+ '<script>alert("escaped")</script>' \
+ '#+end_example' \
+ '' \
+ '** Details' \
+ '' \
+ 'Jump [[*Overview][back to the overview]].' > docs/org-support.org
+ fi
+ "$FOSSIL" addremove >/dev/null
+ if [[ -n $("$FOSSIL" changes) ]]; then
+ "$FOSSIL" commit --no-warnings \
+ --date-override 2024-01-03T12:00:00Z \
+ --user-override copland \
+ -m "Add Org documentation fixture"
+ fi
+ if [[ "$is_new" -eq 1 ]]; then
+ "$FOSSIL" tag add release-0.1 current
+ fi
+ )
+
+ local wiki_fixture="$target_dir/$slug-org-wiki.org"
+ printf '%s\n' \
+ '#+TITLE: This title is intentionally suppressed' \
+ '#+AUTHOR: Copland' \
+ '#+OPTIONS: toc:2' \
+ '' \
+ '* Overview' \
+ '' \
+ 'Open [[wiki:Deployment Guide][the deployment guide]] or the' \
+ '[[file:docs/org-support.org][repository documentation]].' \
+ '' \
+ '** Details' \
+ '' \
+ 'Return [[*Overview][to the overview]].' >"$wiki_fixture"
+ if ! "$FOSSIL" wiki list -R "$repository" | grep -Fxq 'Org Wiki'; then
+ "$FOSSIL" wiki create 'Org Wiki' "$wiki_fixture" -R "$repository" >/dev/null
+ fi
+}
+
+create_repository alpha "Alpha"
+create_repository beta "Beta"
diff --git a/tools/copland/scripts/fossil-env.sh b/tools/copland/scripts/fossil-env.sh
new file mode 100755
index 0000000..4df9a7b
--- /dev/null
+++ b/tools/copland/scripts/fossil-env.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+
+if [[ -z "${FOSSIL:-}" ]]; then
+ FOSSIL=fossil
+fi
+export FOSSIL
+
+fossil_binary_path() {
+ if [[ "$FOSSIL" == */* ]]; then
+ if [[ ! -x "$FOSSIL" ]]; then
+ printf 'Fossil binary is not executable: %s\n' "$FOSSIL" >&2
+ return 1
+ fi
+ (CDPATH= cd -- "$(dirname -- "$FOSSIL")" && printf '%s/%s\n' "$PWD" "$(basename -- "$FOSSIL")")
+ else
+ command -v "$FOSSIL"
+ fi
+}
+
+require_org_fossil() {
+ local binary_path
+ if ! binary_path=$(fossil_binary_path); then
+ printf 'Fossil was not found. Run `make fossil` or set FOSSIL=/path/to/fossil.\n' >&2
+ return 1
+ fi
+ if ! "$FOSSIL" help test-org-render >/dev/null 2>&1; then
+ printf 'Fossil at %s has no native Org renderer. Run `make fossil` or set FOSSIL to the patched binary.\n' "$binary_path" >&2
+ return 1
+ fi
+ printf 'Fossil binary: %s\n' "$binary_path"
+}
+
+verify_org_mime() {
+ local repository=$1
+ local mime_result
+ mime_result=$("$FOSSIL" test-mimetype -R "$repository" probe.org)
+ if [[ "$mime_result" != *"text/x-org"* ]]; then
+ printf 'Selected Fossil does not map .org to text/x-org: %s\n' "$mime_result" >&2
+ return 1
+ fi
+ printf 'Org MIME check: text/x-org\n'
+}
diff --git a/tools/copland/scripts/install-repolist.sh b/tools/copland/scripts/install-repolist.sh
new file mode 100755
index 0000000..d59f688
--- /dev/null
+++ b/tools/copland/scripts/install-repolist.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+root_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+source "$root_dir/scripts/fossil-env.sh"
+config_file="$root_dir/dist/copland-skin.config"
+
+if [[ $# -ne 1 ]]; then
+ printf 'Usage: %s REPOSITORY_DIRECTORY\n' "$0" >&2
+ exit 2
+fi
+
+repository_dir=$1
+control_repository="$repository_dir/00-copland-skin.fossil"
+
+if [[ ! -d "$repository_dir" ]]; then
+ printf 'Repository directory does not exist: %s\n' "$repository_dir" >&2
+ exit 1
+fi
+if [[ ! -f "$config_file" ]]; then
+ printf 'Built skin not found. Run make build first.\n' >&2
+ exit 1
+fi
+
+if [[ ! -f "$control_repository" ]]; then
+ "$FOSSIL" init "$control_repository" >/dev/null
+fi
+
+"$FOSSIL" configuration import "$config_file" -R "$control_repository"
+"$FOSSIL" settings repolist-skin 2 --exact -R "$control_repository"
+"$FOSSIL" sql -R "$control_repository" \
+ "REPLACE INTO config(name,value,mtime) VALUES('project-name','Copland',unixepoch());"
+
+printf 'Configured hidden repository-list skin: %s\n' "$control_repository"
diff --git a/tools/copland/scripts/install.sh b/tools/copland/scripts/install.sh
new file mode 100755
index 0000000..7fe0e1c
--- /dev/null
+++ b/tools/copland/scripts/install.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+root_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+source "$root_dir/scripts/fossil-env.sh"
+config_file="$root_dir/dist/copland-skin.config"
+
+if [[ $# -ne 1 ]]; then
+ printf 'Usage: %s REPOSITORY\n' "$0" >&2
+ exit 2
+fi
+
+repository=$1
+if [[ ! -f "$repository" ]]; then
+ printf 'Repository does not exist: %s\n' "$repository" >&2
+ exit 1
+fi
+if [[ ! -f "$config_file" ]]; then
+ printf 'Built skin not found. Run make build first.\n' >&2
+ exit 1
+fi
+
+"$FOSSIL" configuration import "$config_file" -R "$repository"
+printf 'Installed Copland into %s\n' "$repository"
diff --git a/tools/copland/scripts/preview.sh b/tools/copland/scripts/preview.sh
new file mode 100755
index 0000000..c82bec8
--- /dev/null
+++ b/tools/copland/scripts/preview.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+root_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+source_root=$(CDPATH= cd -- "$root_dir/../.." && pwd)
+source "$root_dir/scripts/fossil-env.sh"
+preview_dir="$source_root/.copland-preview"
+nix_repository="$source_root/.repository/nix.fossil"
+port=${PORT:-8080}
+
+require_org_fossil
+"$root_dir/scripts/create-demo.sh" "$preview_dir"
+verify_org_mime "$preview_dir/repositories/alpha.fossil"
+
+if [[ ! -f "$nix_repository" ]]; then
+ printf 'Nix documentation repository not found: %s\n' "$nix_repository" >&2
+ exit 1
+fi
+ln -sfn "$nix_repository" "$preview_dir/repositories/nix.fossil"
+verify_org_mime "$preview_dir/repositories/nix.fossil"
+
+printf 'Copland preview: http://127.0.0.1:%s/\n' "$port"
+printf 'Nix wiki: http://127.0.0.1:%s/nix/wiki\n' "$port"
+printf 'Press Ctrl-C to stop the server.\n'
+FOSSIL_REPOLIST_TITLE=Copland exec "$FOSSIL" server \
+ --localhost \
+ --localauth \
+ --port "$port" \
+ --repolist \
+ --skin copland \
+ "$preview_dir/repositories"