Proof of concept mechanical port of ircnet/ircd to Rust as part of a bit about C being insecure for network services
1#!/usr/bin/env bash
2# Build the leveva docs site and publish it to the root of the `www` branch.
3# The `www` branch is an orphan that contains ONLY the built site files.
4set -euo pipefail
5
6REMOTE="${1:-origin}"
7BRANCH="www"
8
9REPO_ROOT="$(git rev-parse --show-toplevel)"
10SITE_DIR="$REPO_ROOT/docs/site"
11PUBLIC_DIR="$SITE_DIR/public"
12
13# 1. Build the site fresh.
14rm -rf "$PUBLIC_DIR"
15( cd "$SITE_DIR" && zola build )
16# Disable Jekyll processing on static hosts that run it (keeps _-prefixed paths).
17touch "$PUBLIC_DIR/.nojekyll"
18
19# 2. Check out `www` into a throwaway worktree (created as an orphan if absent).
20# Drop any worktree admin entries left dangling by a previously-failed run.
21git -C "$REPO_ROOT" worktree prune
22WORKTREE="$(mktemp -d)"
23cleanup() {
24 git -C "$REPO_ROOT" worktree remove --force "$WORKTREE" 2>/dev/null || rm -rf "$WORKTREE"
25 git -C "$REPO_ROOT" worktree prune
26}
27trap cleanup EXIT
28
29# Resolve the base for `www`, preferring the REMOTE tip so repeated deploys from a
30# dev machine never build on (or try to fast-forward over) a stale local `www`:
31# - remote branch exists → fetch it and reset local `www` to the remote tip;
32# - only a local branch → build on it (a first push will create the remote);
33# - neither exists → start a fresh orphan (first-ever deploy).
34if git -C "$REPO_ROOT" ls-remote --exit-code --heads "$REMOTE" "$BRANCH" >/dev/null 2>&1; then
35 git -C "$REPO_ROOT" fetch "$REMOTE" "$BRANCH"
36 git -C "$REPO_ROOT" worktree add --force -B "$BRANCH" "$WORKTREE" "$REMOTE/$BRANCH"
37elif git -C "$REPO_ROOT" show-ref --verify --quiet "refs/heads/$BRANCH"; then
38 git -C "$REPO_ROOT" worktree add --force "$WORKTREE" "$BRANCH"
39else
40 git -C "$REPO_ROOT" worktree add --detach "$WORKTREE"
41 git -C "$WORKTREE" checkout --orphan "$BRANCH"
42fi
43
44# 3. Replace the worktree's entire contents with the freshly built site.
45git -C "$WORKTREE" rm -rf --quiet . >/dev/null 2>&1 || true
46find "$WORKTREE" -mindepth 1 -maxdepth 1 -not -name '.git' -exec rm -rf {} +
47cp -a "$PUBLIC_DIR/." "$WORKTREE/"
48
49# 4. Commit and push only if something changed.
50git -C "$WORKTREE" add -A
51if git -C "$WORKTREE" diff --cached --quiet; then
52 echo "www: already up to date, nothing to publish."
53else
54 git -C "$WORKTREE" commit -m "Deploy docs site: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
55 git -C "$WORKTREE" push "$REMOTE" "$BRANCH"
56 echo "www: published to $REMOTE/$BRANCH."
57fi