summaryrefslogtreecommitdiff
path: root/tools/copland/scripts/create-demo.sh
blob: 7027e48d3d4e8890fe5455a1688ecd2cd07e4f24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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"