Login
Hex Artifact Content
Login

Artifact b5fddf9b1b7da29f73ce8e196569bd0c8d9022e05afe375b081468e2812c4d02:

Attachment "setup-confined.sh" to tech note [63f0e1ff23] added by opus-ocx2 2026-10-18 18:14:10.
0000: 23 21 2f 62 69 6e 2f 73 68 0a 23 20 73 65 74 75  #!/bin/sh.# setu
0010: 70 2e 73 68 20 44 49 52 20 50 4f 52 54 0a 23 0a  p.sh DIR PORT.#.
0020: 23 20 4d 61 6b 65 73 20 61 20 66 72 65 73 68 20  # Makes a fresh 
0030: 4f 43 58 20 74 65 73 74 20 65 6e 76 69 72 6f 6e  OCX test environ
0040: 6d 65 6e 74 20 69 6e 20 44 49 52 20 28 77 68 69  ment in DIR (whi
0050: 63 68 20 6d 75 73 74 20 6e 6f 74 20 65 78 69 73  ch must not exis
0060: 74 20 6f 72 20 62 65 0a 23 20 65 6d 70 74 79 29  t or be.# empty)
0070: 2c 20 73 65 72 76 65 64 20 6f 6e 20 31 32 37 2e  , served on 127.
0080: 30 2e 30 2e 31 3a 50 4f 52 54 2c 20 74 68 65 20  0.0.1:PORT, the 
0090: 77 61 79 20 74 72 65 65 2f 73 70 65 63 2f 73 75  way tree/spec/su
00a0: 70 70 6f 72 74 2f 73 65 72 76 65 64 5f 6e 6f 64  pport/served_nod
00b0: 65 2e 63 72 0a 23 20 73 65 72 76 65 73 20 4f 43  e.cr.# serves OC
00c0: 58 20 74 6f 20 69 74 73 20 73 70 65 63 73 2c 20  X to its specs, 
00d0: 62 75 74 20 77 69 74 68 20 46 6f 73 73 69 6c 27  but with Fossil'
00e0: 73 20 6f 77 6e 20 73 65 72 76 65 72 20 72 75 6e  s own server run
00f0: 6e 69 6e 67 20 74 68 65 20 73 74 61 67 65 64 0a  ning the staged.
0100: 23 20 70 72 6f 67 72 61 6d 20 61 73 20 69 74 73  # program as its
0110: 20 65 78 74 20 70 61 67 65 20 2f 65 78 74 2f 6f   ext page /ext/o
0120: 63 78 32 2d 63 67 69 20 28 6e 6f 20 70 72 6f 78  cx2-cgi (no prox
0130: 79 20 69 6e 20 62 65 74 77 65 65 6e 3a 20 46 6f  y in between: Fo
0140: 73 73 69 6c 20 69 74 73 65 6c 66 0a 23 20 73 69  ssil itself.# si
0150: 67 6e 73 20 74 68 65 20 76 69 65 77 65 72 20 69  gns the viewer i
0160: 6e 20 61 6e 64 20 6e 61 6d 65 73 20 69 74 20 69  n and names it i
0170: 6e 20 46 4f 53 53 49 4c 5f 55 53 45 52 20 2f 20  n FOSSIL_USER / 
0180: 46 4f 53 53 49 4c 5f 43 41 50 41 42 49 4c 49 54  FOSSIL_CAPABILIT
0190: 49 45 53 29 2e 0a 23 0a 23 20 53 63 72 61 74 63  IES)..#.# Scratc
01a0: 68 20 6f 6e 6c 79 2e 20 49 74 20 63 6f 70 69 65  h only. It copie
01b0: 73 20 74 68 65 20 73 74 61 67 65 64 20 70 72 6f  s the staged pro
01c0: 67 72 61 6d 20 28 6e 65 76 65 72 20 72 75 6e 73  gram (never runs
01d0: 20 69 74 20 69 6e 20 70 6c 61 63 65 2c 20 73 69   it in place, si
01e0: 6e 63 65 0a 23 20 61 20 70 72 6f 67 72 61 6d 20  nce.# a program 
01f0: 72 75 6e 20 66 72 6f 6d 20 73 74 61 67 65 64 2f  run from staged/
0200: 6e 65 78 74 20 74 61 6b 65 73 20 74 68 61 74 20  next takes that 
0210: 74 72 65 65 27 73 20 72 6f 6f 74 20 61 73 20 69  tree's root as i
0220: 74 73 20 72 65 6c 65 61 73 65 20 72 6f 6f 74 29  ts release root)
0230: 0a 23 20 69 6e 74 6f 20 44 49 52 2f 72 6f 6f 74  .# into DIR/root
0240: 2c 20 6c 61 69 64 20 6f 75 74 20 61 73 20 73 63  , laid out as sc
0250: 72 69 70 74 73 2f 73 74 61 72 74 2d 66 6f 73 73  ripts/start-foss
0260: 69 6c 2e 63 72 20 6c 61 79 73 20 6f 75 74 20 61  il.cr lays out a
0270: 20 72 65 6c 65 61 73 65 20 72 6f 6f 74 3a 0a 23   release root:.#
0280: 20 20 20 44 49 52 2f 72 6f 6f 74 2f 63 75 72 72     DIR/root/curr
0290: 65 6e 74 2f 6f 63 78 32 2c 20 44 49 52 2f 72 6f  ent/ocx2, DIR/ro
02a0: 6f 74 2f 73 74 61 67 65 64 2f 6e 65 78 74 2f 6f  ot/staged/next/o
02b0: 63 78 32 20 20 28 63 6f 70 69 65 73 2c 20 73 61  cx2  (copies, sa
02c0: 6d 65 20 68 61 73 68 29 0a 23 20 20 20 44 49 52  me hash).#   DIR
02d0: 2f 65 78 74 2f 6f 63 78 32 2d 63 67 69 20 20 20  /ext/ocx2-cgi   
02e0: 20 20 20 20 2d 3e 20 44 49 52 2f 72 6f 6f 74 2f      -> DIR/root/
02f0: 63 75 72 72 65 6e 74 2f 6f 63 78 32 0a 23 20 20  current/ocx2.#  
0300: 20 44 49 52 2f 65 78 74 2f 6f 63 78 32 2d 63 67   DIR/ext/ocx2-cg
0310: 69 2d 6e 65 78 74 20 20 2d 3e 20 44 49 52 2f 72  i-next  -> DIR/r
0320: 6f 6f 74 2f 73 74 61 67 65 64 2f 6e 65 78 74 2f  oot/staged/next/
0330: 6f 63 78 32 0a 23 20 20 20 44 49 52 2f 65 78 74  ocx2.#   DIR/ext
0340: 2f 77 68 6f 20 20 20 20 20 20 20 20 20 20 20 20  /who            
0350: 74 68 65 20 76 69 65 77 65 72 2d 6e 61 6d 69 6e  the viewer-namin
0360: 67 20 73 63 72 69 70 74 20 73 65 72 76 65 64 5f  g script served_
0370: 6e 6f 64 65 2e 63 72 20 77 72 69 74 65 73 0a 23  node.cr writes.#
0380: 20 46 6f 73 73 69 6c 20 72 75 6e 73 20 77 69 74   Fossil runs wit
0390: 68 20 48 4f 4d 45 3d 44 49 52 2f 68 6f 6d 65 2e  h HOME=DIR/home.
03a0: 20 6f 63 78 32 20 74 61 6b 65 73 20 69 74 73 20   ocx2 takes its 
03b0: 68 6f 6d 65 20 66 72 6f 6d 20 74 68 65 20 61 63  home from the ac
03c0: 63 6f 75 6e 74 0a 23 20 64 61 74 61 62 61 73 65  count.# database
03d0: 20 69 6e 73 74 65 61 64 20 28 74 6f 6f 6c 73 2f   instead (tools/
03e0: 6f 63 78 32 2e 63 72 3a 20 22 46 6f 73 73 69 6c  ocx2.cr: "Fossil
03f0: 20 6b 65 65 70 73 20 69 74 73 20 73 65 74 74 69   keeps its setti
0400: 6e 67 73 20 69 6e 20 74 68 65 20 68 6f 6d 65 20  ngs in the home 
0410: 74 68 65 0a 23 20 61 63 63 6f 75 6e 74 20 64 61  the.# account da
0420: 74 61 62 61 73 65 20 6e 61 6d 65 73 22 29 2c 20  tabase names"), 
0430: 73 6f 20 74 68 65 20 73 65 72 76 65 72 20 61 6e  so the server an
0440: 64 20 44 49 52 2f 62 69 6e 2f 6f 63 78 32 20 72  d DIR/bin/ocx2 r
0450: 75 6e 20 69 6e 20 62 77 72 61 70 20 77 69 74 68  un in bwrap with
0460: 0a 23 20 44 49 52 2f 61 63 63 74 20 62 6f 75 6e  .# DIR/acct boun
0470: 64 20 6f 76 65 72 20 74 68 61 74 20 68 6f 6d 65  d over that home
0480: 3a 20 6e 6f 20 7e 2f 2e 66 6f 73 73 69 6c 20 6f  : no ~/.fossil o
0490: 75 74 73 69 64 65 20 44 49 52 20 69 73 20 74 6f  utside DIR is to
04a0: 75 63 68 65 64 2e 0a 23 20 4f 43 58 32 3d 50 41  uched..# OCX2=PA
04b0: 54 48 20 74 65 73 74 73 20 61 6e 6f 74 68 65 72  TH tests another
04c0: 20 62 75 69 6c 64 20 74 68 61 6e 20 74 68 69 73   build than this
04d0: 20 68 6f 73 74 27 73 20 73 74 61 67 65 64 20 6f   host's staged o
04e0: 6e 65 2e 0a 23 0a 23 20 57 68 61 74 20 69 74 20  ne..#.# What it 
04f0: 6c 65 61 76 65 73 3a 0a 23 20 20 20 44 49 52 2f  leaves:.#   DIR/
0500: 73 65 72 76 65 72 2f 72 65 70 6f 2e 66 6f 73 73  server/repo.foss
0510: 69 6c 20 20 20 74 68 65 20 73 65 72 76 65 64 20  il   the served 
0520: 72 65 70 6f 73 69 74 6f 72 79 20 28 22 66 6f 73  repository ("fos
0530: 73 69 6c 20 6e 65 77 20 2d 41 20 6f 77 6e 65 72  sil new -A owner
0540: 22 29 0a 23 20 20 20 44 49 52 2f 73 65 72 76 65  ").#   DIR/serve
0550: 72 2f 63 68 65 63 6b 6f 75 74 20 20 20 20 20 20  r/checkout      
0560: 61 20 63 68 65 63 6b 6f 75 74 20 6f 66 20 69 74  a checkout of it
0570: 2c 20 74 68 65 20 73 65 72 76 65 72 2d 73 69 64  , the server-sid
0580: 65 20 6f 6e 65 0a 23 20 20 20 44 49 52 2f 63 6c  e one.#   DIR/cl
0590: 6f 6e 65 73 2f 69 76 79 2f 63 6c 6f 6e 65 2e 66  ones/ivy/clone.f
05a0: 6f 73 73 69 6c 2c 20 44 49 52 2f 63 6c 6f 6e 65  ossil, DIR/clone
05b0: 73 2f 69 76 79 2f 74 72 65 65 0a 23 20 20 20 20  s/ivy/tree.#    
05c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
05d0: 20 20 20 20 20 20 20 20 61 20 63 6c 6f 6e 65 20          a clone 
05e0: 6d 61 64 65 20 6f 76 65 72 20 48 54 54 50 20 61  made over HTTP a
05f0: 73 20 69 76 79 20 28 69 2c 6f 29 2c 20 69 74 73  s ivy (i,o), its
0600: 20 70 61 73 73 77 6f 72 64 0a 23 20 20 20 20 20   password.#     
0610: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0620: 20 20 20 20 20 20 20 73 61 76 65 64 2c 20 61 75         saved, au
0630: 74 6f 73 79 6e 63 20 6f 66 66 2c 20 61 6e 64 20  tosync off, and 
0640: 69 74 73 20 63 68 65 63 6b 6f 75 74 0a 23 20 20  its checkout.#  
0650: 20 44 49 52 2f 70 61 73 73 77 6f 72 64 73 2e 74   DIR/passwords.t
0660: 78 74 20 20 20 20 20 20 20 20 22 75 73 65 72 20  xt        "user 
0670: 70 61 73 73 77 6f 72 64 20 63 61 70 61 62 69 6c  password capabil
0680: 69 74 69 65 73 22 20 70 65 72 20 6c 69 6e 65 20  ities" per line 
0690: 28 73 63 72 61 74 63 68 29 0a 23 20 20 20 44 49  (scratch).#   DI
06a0: 52 2f 66 61 63 74 73 2e 74 78 74 20 20 20 20 20  R/facts.txt     
06b0: 20 20 20 20 20 20 20 68 61 73 68 65 73 20 6d 61         hashes ma
06c0: 64 65 20 68 65 72 65 20 28 63 68 65 63 6b 2d 69  de here (check-i
06d0: 6e 73 2c 20 70 6f 73 74 73 2c 20 74 69 63 6b 65  ns, posts, ticke
06e0: 74 2c 20 77 69 6b 69 29 0a 23 20 20 20 44 49 52  t, wiki).#   DIR
06f0: 2f 65 6e 76 2e 73 68 20 20 20 20 20 20 20 20 20  /env.sh         
0700: 20 20 20 20 20 20 22 2e 20 44 49 52 2f 65 6e 76        ". DIR/env
0710: 2e 73 68 22 20 73 65 74 73 20 48 4f 4d 45 2c 20  .sh" sets HOME, 
0720: 50 41 54 48 20 28 6f 63 78 32 20 66 69 72 73 74  PATH (ocx2 first
0730: 29 2c 20 55 52 4c 0a 23 20 20 20 44 49 52 2f 62  ), URL.#   DIR/b
0740: 69 6e 2f 6f 63 78 32 20 20 20 20 20 20 20 20 20  in/ocx2         
0750: 20 20 20 20 74 68 65 20 43 4c 49 2c 20 63 6f 6e      the CLI, con
0760: 66 69 6e 65 64 20 61 73 20 61 62 6f 76 65 0a 23  fined as above.#
0770: 20 20 20 44 49 52 2f 61 63 63 74 20 20 20 20 20     DIR/acct     
0780: 20 20 20 20 20 20 20 20 20 20 20 20 77 68 61 74              what
0790: 20 6f 63 78 32 20 73 65 65 73 20 61 73 20 74 68   ocx2 sees as th
07a0: 65 20 61 63 63 6f 75 6e 74 27 73 20 68 6f 6d 65  e account's home
07b0: 0a 23 20 20 20 44 49 52 2f 73 74 61 72 74 2e 73  .#   DIR/start.s
07c0: 68 2c 20 44 49 52 2f 73 74 6f 70 2e 73 68 2c 20  h, DIR/stop.sh, 
07d0: 44 49 52 2f 73 65 72 76 65 72 2e 70 69 64 2c 20  DIR/server.pid, 
07e0: 44 49 52 2f 73 65 72 76 65 72 2e 6c 6f 67 2c 20  DIR/server.log, 
07f0: 44 49 52 2f 73 65 72 76 65 72 2e 65 72 72 2e 6c  DIR/server.err.l
0800: 6f 67 0a 23 20 54 68 65 20 73 65 72 76 65 72 20  og.# The server 
0810: 6b 65 65 70 73 20 72 75 6e 6e 69 6e 67 20 77 68  keeps running wh
0820: 65 6e 20 74 68 69 73 20 73 63 72 69 70 74 20 65  en this script e
0830: 78 69 74 73 3b 20 73 74 6f 70 20 69 74 20 77 69  xits; stop it wi
0840: 74 68 20 44 49 52 2f 73 74 6f 70 2e 73 68 2c 0a  th DIR/stop.sh,.
0850: 23 20 73 74 61 72 74 20 69 74 20 61 67 61 69 6e  # start it again
0860: 20 6f 6e 20 74 68 65 20 73 61 6d 65 20 70 6f 72   on the same por
0870: 74 20 77 69 74 68 20 44 49 52 2f 73 74 61 72 74  t with DIR/start
0880: 2e 73 68 2e 20 2f 65 78 74 2f 77 68 6f 20 61 6e  .sh. /ext/who an
0890: 73 77 65 72 73 0a 23 20 22 76 69 65 77 65 72 3d  swers.# "viewer=
08a0: 55 53 45 52 20 63 61 70 61 62 69 6c 69 74 69 65  USER capabilitie
08b0: 73 3d 43 41 50 53 22 20 28 69 6e 73 69 64 65 20  s=CAPS" (inside 
08c0: 46 6f 73 73 69 6c 27 73 20 73 6b 69 6e 29 20 66  Fossil's skin) f
08d0: 6f 72 20 77 68 6f 65 76 65 72 20 74 68 65 0a 23  or whoever the.#
08e0: 20 72 65 71 75 65 73 74 27 73 20 63 6f 6f 6b 69   request's cooki
08f0: 65 20 73 69 67 6e 73 20 69 6e 3b 20 6e 6f 62 6f  e signs in; nobo
0900: 64 79 20 73 68 6f 77 73 20 61 73 20 61 6e 20 65  dy shows as an e
0910: 6d 70 74 79 20 76 69 65 77 65 72 2e 0a 73 65 74  mpty viewer..set
0920: 20 2d 65 75 0a 0a 5b 20 24 23 20 2d 65 71 20 32   -eu..[ $# -eq 2
0930: 20 5d 20 7c 7c 20 7b 20 65 63 68 6f 20 22 75 73   ] || { echo "us
0940: 61 67 65 3a 20 24 30 20 44 49 52 20 50 4f 52 54  age: $0 DIR PORT
0950: 22 20 3e 26 32 3b 20 65 78 69 74 20 32 3b 20 7d  " >&2; exit 2; }
0960: 0a 44 49 52 3d 24 31 0a 50 4f 52 54 3d 24 32 0a  .DIR=$1.PORT=$2.
0970: 53 54 41 47 45 44 3d 24 7b 4f 43 58 32 3a 2d 2f  STAGED=${OCX2:-/
0980: 76 61 72 2f 6c 69 62 2f 6f 63 78 2f 61 67 65 6e  var/lib/ocx/agen
0990: 74 73 2f 6f 70 75 73 2d 6f 63 78 32 2f 70 72 6f  ts/opus-ocx2/pro
09a0: 6a 65 63 74 73 2f 6f 6c 6c 61 6d 61 2f 62 32 64  jects/ollama/b2d
09b0: 65 38 62 30 63 32 63 36 37 30 30 65 62 35 63 36  e8b0c2c6700eb5c6
09c0: 38 36 62 31 37 34 37 62 35 61 61 61 31 65 32 64  86b1747b5aaa1e2d
09d0: 32 64 30 31 33 37 30 61 63 35 35 66 32 65 35 61  2d01370ac55f2e5a
09e0: 31 35 31 61 36 37 65 30 33 62 34 38 61 2f 73 74  151a67e03b48a/st
09f0: 61 67 65 64 2f 6e 65 78 74 2f 6f 63 78 32 7d 0a  aged/next/ocx2}.
0a00: 23 20 74 68 65 20 68 6f 6d 65 20 74 68 65 20 61  # the home the a
0a10: 63 63 6f 75 6e 74 20 64 61 74 61 62 61 73 65 20  ccount database 
0a20: 6e 61 6d 65 73 2c 20 77 68 69 63 68 20 6f 63 78  names, which ocx
0a30: 32 20 72 65 61 64 73 20 61 6e 64 20 62 77 72 61  2 reads and bwra
0a40: 70 20 63 6f 76 65 72 73 0a 41 43 43 54 5f 48 4f  p covers.ACCT_HO
0a50: 4d 45 3d 24 28 67 65 74 65 6e 74 20 70 61 73 73  ME=$(getent pass
0a60: 77 64 20 22 24 28 69 64 20 2d 75 29 22 20 7c 20  wd "$(id -u)" | 
0a70: 63 75 74 20 2d 64 3a 20 2d 66 36 29 0a 4e 49 43  cut -d: -f6).NIC
0a80: 45 3d 22 6e 69 63 65 20 2d 6e 20 31 30 22 0a 46  E="nice -n 10".F
0a90: 4f 53 53 49 4c 3d 24 28 63 6f 6d 6d 61 6e 64 20  OSSIL=$(command 
0aa0: 2d 76 20 66 6f 73 73 69 6c 29 20 7c 7c 20 7b 20  -v fossil) || { 
0ab0: 65 63 68 6f 20 22 66 6f 73 73 69 6c 20 69 73 20  echo "fossil is 
0ac0: 6e 6f 74 20 6f 6e 20 50 41 54 48 22 20 3e 26 32  not on PATH" >&2
0ad0: 3b 20 65 78 69 74 20 32 3b 20 7d 0a 0a 5b 20 2d  ; exit 2; }..[ -
0ae0: 78 20 22 24 53 54 41 47 45 44 22 20 5d 20 7c 7c  x "$STAGED" ] ||
0af0: 20 7b 20 65 63 68 6f 20 22 6e 6f 20 70 72 6f 67   { echo "no prog
0b00: 72 61 6d 20 61 74 20 24 53 54 41 47 45 44 3b 20  ram at $STAGED; 
0b10: 67 69 76 65 20 6f 6e 65 20 77 69 74 68 20 4f 43  give one with OC
0b20: 58 32 3d 50 41 54 48 22 20 3e 26 32 3b 20 65 78  X2=PATH" >&2; ex
0b30: 69 74 20 32 3b 20 7d 0a 63 6f 6d 6d 61 6e 64 20  it 2; }.command 
0b40: 2d 76 20 62 77 72 61 70 20 3e 2f 64 65 76 2f 6e  -v bwrap >/dev/n
0b50: 75 6c 6c 20 7c 7c 20 7b 20 65 63 68 6f 20 22 62  ull || { echo "b
0b60: 77 72 61 70 20 69 73 20 6e 65 65 64 65 64 2c 20  wrap is needed, 
0b70: 74 6f 20 6b 65 65 70 20 6f 63 78 32 20 6f 66 66  to keep ocx2 off
0b80: 20 24 41 43 43 54 5f 48 4f 4d 45 22 20 3e 26 32   $ACCT_HOME" >&2
0b90: 3b 20 65 78 69 74 20 32 3b 20 7d 0a 5b 20 2d 64  ; exit 2; }.[ -d
0ba0: 20 22 24 41 43 43 54 5f 48 4f 4d 45 22 20 5d 20   "$ACCT_HOME" ] 
0bb0: 7c 7c 20 7b 20 65 63 68 6f 20 22 74 68 65 20 61  || { echo "the a
0bc0: 63 63 6f 75 6e 74 27 73 20 68 6f 6d 65 20 24 41  ccount's home $A
0bd0: 43 43 54 5f 48 4f 4d 45 20 69 73 20 6e 6f 74 20  CCT_HOME is not 
0be0: 61 20 64 69 72 65 63 74 6f 72 79 22 20 3e 26 32  a directory" >&2
0bf0: 3b 20 65 78 69 74 20 32 3b 20 7d 0a 63 61 73 65  ; exit 2; }.case
0c00: 20 24 50 4f 52 54 20 69 6e 20 27 27 7c 2a 5b 21   $PORT in ''|*[!
0c10: 30 2d 39 5d 2a 29 20 65 63 68 6f 20 22 50 4f 52  0-9]*) echo "POR
0c20: 54 20 6d 75 73 74 20 62 65 20 61 20 6e 75 6d 62  T must be a numb
0c30: 65 72 22 20 3e 26 32 3b 20 65 78 69 74 20 32 3b  er" >&2; exit 2;
0c40: 3b 20 65 73 61 63 0a 69 66 20 5b 20 2d 65 20 22  ; esac.if [ -e "
0c50: 24 44 49 52 22 20 5d 20 26 26 20 5b 20 2d 6e 20  $DIR" ] && [ -n 
0c60: 22 24 28 6c 73 20 2d 41 20 22 24 44 49 52 22 20  "$(ls -A "$DIR" 
0c70: 32 3e 2f 64 65 76 2f 6e 75 6c 6c 29 22 20 5d 3b  2>/dev/null)" ];
0c80: 20 74 68 65 6e 0a 20 20 65 63 68 6f 20 22 24 44   then.  echo "$D
0c90: 49 52 20 65 78 69 73 74 73 20 61 6e 64 20 69 73  IR exists and is
0ca0: 20 6e 6f 74 20 65 6d 70 74 79 3b 20 67 69 76 65   not empty; give
0cb0: 20 61 20 66 72 65 73 68 20 64 69 72 65 63 74 6f   a fresh directo
0cc0: 72 79 22 20 3e 26 32 3b 20 65 78 69 74 20 32 0a  ry" >&2; exit 2.
0cd0: 66 69 0a 69 66 20 63 75 72 6c 20 2d 73 20 2d 6f  fi.if curl -s -o
0ce0: 20 2f 64 65 76 2f 6e 75 6c 6c 20 2d 2d 6d 61 78   /dev/null --max
0cf0: 2d 74 69 6d 65 20 32 20 22 68 74 74 70 3a 2f 2f  -time 2 "http://
0d00: 31 32 37 2e 30 2e 30 2e 31 3a 24 50 4f 52 54 2f  127.0.0.1:$PORT/
0d10: 22 3b 20 74 68 65 6e 0a 20 20 65 63 68 6f 20 22  "; then.  echo "
0d20: 73 6f 6d 65 74 68 69 6e 67 20 61 6c 72 65 61 64  something alread
0d30: 79 20 61 6e 73 77 65 72 73 20 6f 6e 20 31 32 37  y answers on 127
0d40: 2e 30 2e 30 2e 31 3a 24 50 4f 52 54 22 20 3e 26  .0.0.1:$PORT" >&
0d50: 32 3b 20 65 78 69 74 20 32 0a 66 69 0a 0a 6d 6b  2; exit 2.fi..mk
0d60: 64 69 72 20 2d 70 20 22 24 44 49 52 22 0a 44 49  dir -p "$DIR".DI
0d70: 52 3d 24 28 63 64 20 22 24 44 49 52 22 20 26 26  R=$(cd "$DIR" &&
0d80: 20 70 77 64 29 0a 55 52 4c 3d 22 68 74 74 70 3a   pwd).URL="http:
0d90: 2f 2f 31 32 37 2e 30 2e 30 2e 31 3a 24 50 4f 52  //127.0.0.1:$POR
0da0: 54 22 0a 65 78 70 6f 72 74 20 48 4f 4d 45 3d 22  T".export HOME="
0db0: 24 44 49 52 2f 68 6f 6d 65 22 0a 6d 6b 64 69 72  $DIR/home".mkdir
0dc0: 20 2d 70 20 22 24 48 4f 4d 45 22 20 22 24 44 49   -p "$HOME" "$DI
0dd0: 52 2f 61 63 63 74 22 20 22 24 44 49 52 2f 73 65  R/acct" "$DIR/se
0de0: 72 76 65 72 2f 63 68 65 63 6b 6f 75 74 22 20 22  rver/checkout" "
0df0: 24 44 49 52 2f 63 6c 6f 6e 65 73 22 20 22 24 44  $DIR/clones" "$D
0e00: 49 52 2f 65 78 74 22 20 5c 0a 20 20 22 24 44 49  IR/ext" \.  "$DI
0e10: 52 2f 72 6f 6f 74 2f 63 75 72 72 65 6e 74 22 20  R/root/current" 
0e20: 22 24 44 49 52 2f 72 6f 6f 74 2f 73 74 61 67 65  "$DIR/root/stage
0e30: 64 2f 6e 65 78 74 22 20 22 24 44 49 52 2f 62 69  d/next" "$DIR/bi
0e40: 6e 22 0a 0a 66 6f 73 73 69 6c 28 29 20 7b 20 24  n"..fossil() { $
0e50: 4e 49 43 45 20 22 24 46 4f 53 53 49 4c 22 20 22  NICE "$FOSSIL" "
0e60: 24 40 22 3b 20 7d 0a 70 77 28 29 20 7b 20 6f 64  $@"; }.pw() { od
0e70: 20 2d 41 6e 20 2d 74 78 31 20 2d 4e 39 20 2f 64   -An -tx1 -N9 /d
0e80: 65 76 2f 75 72 61 6e 64 6f 6d 20 7c 20 74 72 20  ev/urandom | tr 
0e90: 2d 64 20 27 20 5c 6e 27 3b 20 7d 0a 0a 23 20 2d  -d ' \n'; }..# -
0ea0: 2d 2d 20 74 68 65 20 70 72 6f 67 72 61 6d 3a 20  -- the program: 
0eb0: 63 6f 70 69 65 73 20 6f 66 20 74 68 65 20 73 74  copies of the st
0ec0: 61 67 65 64 20 72 65 6c 65 61 73 65 2c 20 69 6e  aged release, in
0ed0: 20 61 20 73 63 72 61 74 63 68 20 72 65 6c 65 61   a scratch relea
0ee0: 73 65 20 72 6f 6f 74 0a 63 70 20 22 24 53 54 41  se root.cp "$STA
0ef0: 47 45 44 22 20 22 24 44 49 52 2f 72 6f 6f 74 2f  GED" "$DIR/root/
0f00: 63 75 72 72 65 6e 74 2f 6f 63 78 32 22 0a 63 70  current/ocx2".cp
0f10: 20 22 24 53 54 41 47 45 44 22 20 22 24 44 49 52   "$STAGED" "$DIR
0f20: 2f 72 6f 6f 74 2f 73 74 61 67 65 64 2f 6e 65 78  /root/staged/nex
0f30: 74 2f 6f 63 78 32 22 0a 63 68 6d 6f 64 20 37 35  t/ocx2".chmod 75
0f40: 35 20 22 24 44 49 52 2f 72 6f 6f 74 2f 63 75 72  5 "$DIR/root/cur
0f50: 72 65 6e 74 2f 6f 63 78 32 22 20 22 24 44 49 52  rent/ocx2" "$DIR
0f60: 2f 72 6f 6f 74 2f 73 74 61 67 65 64 2f 6e 65 78  /root/staged/nex
0f70: 74 2f 6f 63 78 32 22 0a 6c 6e 20 2d 73 20 22 24  t/ocx2".ln -s "$
0f80: 44 49 52 2f 72 6f 6f 74 2f 63 75 72 72 65 6e 74  DIR/root/current
0f90: 2f 6f 63 78 32 22 20 22 24 44 49 52 2f 65 78 74  /ocx2" "$DIR/ext
0fa0: 2f 6f 63 78 32 2d 63 67 69 22 0a 6c 6e 20 2d 73  /ocx2-cgi".ln -s
0fb0: 20 22 24 44 49 52 2f 72 6f 6f 74 2f 73 74 61 67   "$DIR/root/stag
0fc0: 65 64 2f 6e 65 78 74 2f 6f 63 78 32 22 20 22 24  ed/next/ocx2" "$
0fd0: 44 49 52 2f 65 78 74 2f 6f 63 78 32 2d 63 67 69  DIR/ext/ocx2-cgi
0fe0: 2d 6e 65 78 74 22 0a 23 20 74 68 65 20 43 4c 49  -next".# the CLI
0ff0: 2c 20 62 79 20 69 74 73 20 6f 77 6e 20 6e 61 6d  , by its own nam
1000: 65 2c 20 63 6f 6e 66 69 6e 65 64 20 73 6f 20 69  e, confined so i
1010: 74 20 73 65 65 73 20 44 49 52 2f 61 63 63 74 20  t sees DIR/acct 
1020: 61 73 20 74 68 65 20 61 63 63 6f 75 6e 74 27 73  as the account's
1030: 20 68 6f 6d 65 0a 70 72 69 6e 74 66 20 27 23 21   home.printf '#!
1040: 2f 62 69 6e 2f 73 68 5c 6e 65 78 65 63 20 62 77  /bin/sh\nexec bw
1050: 72 61 70 20 2d 2d 64 65 76 2d 62 69 6e 64 20 2f  rap --dev-bind /
1060: 20 2f 20 2d 2d 62 69 6e 64 20 22 25 73 22 20 22   / --bind "%s" "
1070: 25 73 22 20 2d 2d 20 22 25 73 22 20 22 24 40 22  %s" -- "%s" "$@"
1080: 5c 6e 27 20 22 24 44 49 52 2f 61 63 63 74 22 20  \n' "$DIR/acct" 
1090: 22 24 41 43 43 54 5f 48 4f 4d 45 22 20 22 24 44  "$ACCT_HOME" "$D
10a0: 49 52 2f 72 6f 6f 74 2f 63 75 72 72 65 6e 74 2f  IR/root/current/
10b0: 6f 63 78 32 22 20 3e 20 22 24 44 49 52 2f 62 69  ocx2" > "$DIR/bi
10c0: 6e 2f 6f 63 78 32 22 0a 63 68 6d 6f 64 20 37 35  n/ocx2".chmod 75
10d0: 35 20 22 24 44 49 52 2f 62 69 6e 2f 6f 63 78 32  5 "$DIR/bin/ocx2
10e0: 22 0a 23 20 73 65 72 76 65 64 5f 6e 6f 64 65 2e  ".# served_node.
10f0: 63 72 27 73 20 76 69 65 77 65 72 2d 6e 61 6d 69  cr's viewer-nami
1100: 6e 67 20 73 63 72 69 70 74 2c 20 73 6f 20 61 20  ng script, so a 
1110: 74 65 73 74 65 72 20 63 61 6e 20 61 73 6b 20 46  tester can ask F
1120: 6f 73 73 69 6c 20 77 68 6f 20 69 74 20 73 69 67  ossil who it sig
1130: 6e 65 64 20 69 6e 0a 70 72 69 6e 74 66 20 27 23  ned in.printf '#
1140: 21 2f 62 69 6e 2f 73 68 5c 6e 70 72 69 6e 74 66  !/bin/sh\nprintf
1150: 20 27 22 27 22 27 43 6f 6e 74 65 6e 74 2d 54 79   '"'"'Content-Ty
1160: 70 65 3a 20 74 65 78 74 2f 70 6c 61 69 6e 5c 5c  pe: text/plain\\
1170: 72 5c 5c 6e 5c 5c 72 5c 5c 6e 76 69 65 77 65 72  r\\n\\r\\nviewer
1180: 3d 25 25 73 20 63 61 70 61 62 69 6c 69 74 69 65  =%%s capabilitie
1190: 73 3d 25 25 73 5c 5c 6e 27 22 27 22 27 20 22 24  s=%%s\\n'"'"' "$
11a0: 46 4f 53 53 49 4c 5f 55 53 45 52 22 20 22 24 46  FOSSIL_USER" "$F
11b0: 4f 53 53 49 4c 5f 43 41 50 41 42 49 4c 49 54 49  OSSIL_CAPABILITI
11c0: 45 53 22 5c 6e 27 20 3e 20 22 24 44 49 52 2f 65  ES"\n' > "$DIR/e
11d0: 78 74 2f 77 68 6f 22 0a 63 68 6d 6f 64 20 37 35  xt/who".chmod 75
11e0: 35 20 22 24 44 49 52 2f 65 78 74 2f 77 68 6f 22  5 "$DIR/ext/who"
11f0: 0a 0a 23 20 2d 2d 2d 20 74 68 65 20 72 65 70 6f  ..# --- the repo
1200: 73 69 74 6f 72 79 2c 20 69 74 73 20 61 64 6d 69  sitory, its admi
1210: 6e 2c 20 61 6e 64 20 69 74 73 20 75 73 65 72 73  n, and its users
1220: 0a 52 45 50 4f 3d 22 24 44 49 52 2f 73 65 72 76  .REPO="$DIR/serv
1230: 65 72 2f 72 65 70 6f 2e 66 6f 73 73 69 6c 22 0a  er/repo.fossil".
1240: 43 4f 3d 22 24 44 49 52 2f 73 65 72 76 65 72 2f  CO="$DIR/server/
1250: 63 68 65 63 6b 6f 75 74 22 0a 63 72 65 61 74 65  checkout".create
1260: 64 3d 24 28 63 64 20 22 24 44 49 52 2f 73 65 72  d=$(cd "$DIR/ser
1270: 76 65 72 22 20 26 26 20 66 6f 73 73 69 6c 20 6e  ver" && fossil n
1280: 65 77 20 2d 41 20 6f 77 6e 65 72 20 22 24 52 45  ew -A owner "$RE
1290: 50 4f 22 29 0a 4f 57 4e 45 52 5f 50 57 3d 24 28  PO").OWNER_PW=$(
12a0: 70 72 69 6e 74 66 20 27 25 73 5c 6e 27 20 22 24  printf '%s\n' "$
12b0: 63 72 65 61 74 65 64 22 20 7c 20 73 65 64 20 2d  created" | sed -
12c0: 6e 20 27 73 2f 2e 2a 70 61 73 73 77 6f 72 64 20  n 's/.*password 
12d0: 69 73 20 22 5c 28 5b 5e 22 5d 2a 5c 29 22 2e 2a  is "\([^"]*\)".*
12e0: 2f 5c 31 2f 70 27 29 0a 5b 20 2d 6e 20 22 24 4f  /\1/p').[ -n "$O
12f0: 57 4e 45 52 5f 50 57 22 20 5d 20 7c 7c 20 7b 20  WNER_PW" ] || { 
1300: 65 63 68 6f 20 22 66 6f 73 73 69 6c 20 6e 65 77  echo "fossil new
1310: 20 70 72 69 6e 74 65 64 20 6e 6f 20 70 61 73 73   printed no pass
1320: 77 6f 72 64 3a 20 24 63 72 65 61 74 65 64 22 20  word: $created" 
1330: 3e 26 32 3b 20 65 78 69 74 20 31 3b 20 7d 0a 28  >&2; exit 1; }.(
1340: 63 64 20 22 24 43 4f 22 20 26 26 20 66 6f 73 73  cd "$CO" && foss
1350: 69 6c 20 6f 70 65 6e 20 22 24 52 45 50 4f 22 20  il open "$REPO" 
1360: 3e 2f 64 65 76 2f 6e 75 6c 6c 20 26 26 20 66 6f  >/dev/null && fo
1370: 73 73 69 6c 20 75 73 65 72 20 64 65 66 61 75 6c  ssil user defaul
1380: 74 20 6f 77 6e 65 72 20 26 26 20 66 6f 73 73 69  t owner && fossi
1390: 6c 20 73 65 74 74 69 6e 67 73 20 61 75 74 6f 73  l settings autos
13a0: 79 6e 63 20 6f 66 66 29 0a 0a 3a 20 3e 20 22 24  ync off)..: > "$
13b0: 44 49 52 2f 70 61 73 73 77 6f 72 64 73 2e 74 78  DIR/passwords.tx
13c0: 74 22 0a 63 68 6d 6f 64 20 36 30 30 20 22 24 44  t".chmod 600 "$D
13d0: 49 52 2f 70 61 73 73 77 6f 72 64 73 2e 74 78 74  IR/passwords.txt
13e0: 22 0a 65 63 68 6f 20 22 23 20 75 73 65 72 20 70  ".echo "# user p
13f0: 61 73 73 77 6f 72 64 20 63 61 70 61 62 69 6c 69  assword capabili
1400: 74 69 65 73 20 20 20 28 73 63 72 61 74 63 68 20  ties   (scratch 
1410: 70 61 73 73 77 6f 72 64 73 20 66 6f 72 20 24 55  passwords for $U
1420: 52 4c 29 22 20 3e 3e 20 22 24 44 49 52 2f 70 61  RL)" >> "$DIR/pa
1430: 73 73 77 6f 72 64 73 2e 74 78 74 22 0a 65 63 68  sswords.txt".ech
1440: 6f 20 22 6f 77 6e 65 72 20 24 4f 57 4e 45 52 5f  o "owner $OWNER_
1450: 50 57 20 73 20 20 20 28 66 6f 73 73 69 6c 20 6e  PW s   (fossil n
1460: 65 77 20 2d 41 29 22 20 3e 3e 20 22 24 44 49 52  ew -A)" >> "$DIR
1470: 2f 70 61 73 73 77 6f 72 64 73 2e 74 78 74 22 0a  /passwords.txt".
1480: 61 64 64 5f 75 73 65 72 28 29 20 7b 20 23 20 6c  add_user() { # l
1490: 6f 67 69 6e 20 63 61 70 73 0a 20 20 70 3d 24 28  ogin caps.  p=$(
14a0: 70 77 29 0a 20 20 28 63 64 20 22 24 43 4f 22 20  pw).  (cd "$CO" 
14b0: 26 26 20 66 6f 73 73 69 6c 20 75 73 65 72 20 6e  && fossil user n
14c0: 65 77 20 22 24 31 22 20 22 24 31 40 73 63 72 61  ew "$1" "$1@scra
14d0: 74 63 68 2e 69 6e 76 61 6c 69 64 22 20 22 24 70  tch.invalid" "$p
14e0: 22 20 3e 2f 64 65 76 2f 6e 75 6c 6c 20 26 26 20  " >/dev/null && 
14f0: 66 6f 73 73 69 6c 20 75 73 65 72 20 63 61 70 61  fossil user capa
1500: 62 69 6c 69 74 69 65 73 20 22 24 31 22 20 22 24  bilities "$1" "$
1510: 32 22 20 3e 2f 64 65 76 2f 6e 75 6c 6c 29 0a 20  2" >/dev/null). 
1520: 20 65 63 68 6f 20 22 24 31 20 24 70 20 24 32 22   echo "$1 $p $2"
1530: 20 3e 3e 20 22 24 44 49 52 2f 70 61 73 73 77 6f   >> "$DIR/passwo
1540: 72 64 73 2e 74 78 74 22 0a 7d 0a 61 64 64 5f 75  rds.txt".}.add_u
1550: 73 65 72 20 73 61 6c 6c 79 20 73 20 20 20 20 20  ser sally s     
1560: 23 20 73 65 74 75 70 0a 61 64 64 5f 75 73 65 72  # setup.add_user
1570: 20 61 64 61 6d 20 61 20 20 20 20 20 20 23 20 61   adam a      # a
1580: 64 6d 69 6e 0a 61 64 64 5f 75 73 65 72 20 69 76  dmin.add_user iv
1590: 79 20 69 6f 20 20 20 20 20 20 23 20 63 68 65 63  y io      # chec
15a0: 6b 2d 69 6e 20 61 6e 64 20 72 65 61 64 0a 61 64  k-in and read.ad
15b0: 64 5f 75 73 65 72 20 6f 74 74 6f 20 6f 20 20 20  d_user otto o   
15c0: 20 20 20 23 20 72 65 61 64 20 6f 6e 6c 79 0a 61     # read only.a
15d0: 64 64 5f 75 73 65 72 20 72 69 74 61 20 52 69 20  dd_user rita Ri 
15e0: 20 20 20 20 23 20 4f 43 58 27 73 20 72 75 6e 20      # OCX's run 
15f0: 73 65 6e 64 65 72 20 28 52 29 20 77 69 74 68 20  sender (R) with 
1600: 63 68 65 63 6b 2d 69 6e 0a 23 20 6e 6f 62 6f 64  check-in.# nobod
1610: 79 20 61 6e 64 20 61 6e 6f 6e 79 6d 6f 75 73 20  y and anonymous 
1620: 6b 65 65 70 20 77 68 61 74 20 22 66 6f 73 73 69  keep what "fossi
1630: 6c 20 6e 65 77 22 20 67 69 76 65 73 20 74 68 65  l new" gives the
1640: 6d 0a 70 61 73 73 77 6f 72 64 5f 6f 66 28 29 20  m.password_of() 
1650: 7b 20 61 77 6b 20 2d 76 20 75 3d 22 24 31 22 20  { awk -v u="$1" 
1660: 27 24 31 3d 3d 75 20 7b 70 72 69 6e 74 20 24 32  '$1==u {print $2
1670: 7d 27 20 22 24 44 49 52 2f 70 61 73 73 77 6f 72  }' "$DIR/passwor
1680: 64 73 2e 74 78 74 22 3b 20 7d 0a 0a 23 20 2d 2d  ds.txt"; }..# --
1690: 2d 20 63 68 65 63 6b 2d 69 6e 73 20 62 79 20 64  - check-ins by d
16a0: 69 66 66 65 72 65 6e 74 20 75 73 65 72 73 0a 63  ifferent users.c
16b0: 6f 6d 6d 69 74 28 29 20 7b 20 23 20 75 73 65 72  ommit() { # user
16c0: 20 66 69 6c 65 20 63 6f 6e 74 65 6e 74 20 63 6f   file content co
16d0: 6d 6d 65 6e 74 0a 20 20 28 63 64 20 22 24 43 4f  mment.  (cd "$CO
16e0: 22 20 26 26 20 70 72 69 6e 74 66 20 27 25 73 5c  " && printf '%s\
16f0: 6e 27 20 22 24 33 22 20 3e 20 22 24 32 22 20 26  n' "$3" > "$2" &
1700: 26 20 66 6f 73 73 69 6c 20 61 64 64 20 22 24 32  & fossil add "$2
1710: 22 20 3e 2f 64 65 76 2f 6e 75 6c 6c 20 26 26 20  " >/dev/null && 
1720: 5c 0a 20 20 20 66 6f 73 73 69 6c 20 63 6f 6d 6d  \.   fossil comm
1730: 69 74 20 2d 2d 6e 6f 2d 77 61 72 6e 69 6e 67 73  it --no-warnings
1740: 20 2d 2d 75 73 65 72 20 22 24 31 22 20 2d 6d 20   --user "$1" -m 
1750: 22 24 34 22 20 3e 2f 64 65 76 2f 6e 75 6c 6c 29  "$4" >/dev/null)
1760: 0a 7d 0a 63 6f 6d 6d 69 74 20 6f 77 6e 65 72 20  .}.commit owner 
1770: 52 45 41 44 4d 45 2e 6d 64 20 22 23 20 73 63 72  README.md "# scr
1780: 61 74 63 68 20 70 72 6f 6a 65 63 74 22 20 22 53  atch project" "S
1790: 74 61 72 74 20 74 68 65 20 73 63 72 61 74 63 68  tart the scratch
17a0: 20 70 72 6f 6a 65 63 74 2e 22 0a 63 6f 6d 6d 69   project.".commi
17b0: 74 20 69 76 79 20 68 65 6c 6c 6f 2e 74 78 74 20  t ivy hello.txt 
17c0: 22 68 65 6c 6c 6f 22 20 22 41 64 64 20 68 65 6c  "hello" "Add hel
17d0: 6c 6f 2e 22 0a 63 6f 6d 6d 69 74 20 73 61 6c 6c  lo.".commit sall
17e0: 79 20 50 4c 41 4e 2e 6d 64 20 22 50 6c 61 6e 3a  y PLAN.md "Plan:
17f0: 20 6e 6f 74 68 69 6e 67 20 79 65 74 2e 22 20 22   nothing yet." "
1800: 41 64 64 20 61 20 70 6c 61 6e 2e 22 0a 63 6f 6d  Add a plan.".com
1810: 6d 69 74 20 69 76 79 20 68 65 6c 6c 6f 2e 74 78  mit ivy hello.tx
1820: 74 20 22 68 65 6c 6c 6f 2c 20 77 6f 72 6c 64 22  t "hello, world"
1830: 20 22 53 61 79 20 6d 6f 72 65 20 69 6e 20 68 65   "Say more in he
1840: 6c 6c 6f 2e 22 0a 63 68 65 63 6b 69 6e 73 3d 24  llo.".checkins=$
1850: 28 66 6f 73 73 69 6c 20 73 71 6c 20 2d 52 20 22  (fossil sql -R "
1860: 24 52 45 50 4f 22 20 22 53 45 4c 45 43 54 20 62  $REPO" "SELECT b
1870: 2e 75 75 69 64 7c 7c 27 20 27 7c 7c 65 2e 75 73  .uuid||' '||e.us
1880: 65 72 20 46 52 4f 4d 20 65 76 65 6e 74 20 65 20  er FROM event e 
1890: 4a 4f 49 4e 20 62 6c 6f 62 20 62 20 4f 4e 20 62  JOIN blob b ON b
18a0: 2e 72 69 64 3d 65 2e 6f 62 6a 69 64 20 57 48 45  .rid=e.objid WHE
18b0: 52 45 20 65 2e 74 79 70 65 3d 27 63 69 27 20 4f  RE e.type='ci' O
18c0: 52 44 45 52 20 42 59 20 65 2e 6d 74 69 6d 65 22  RDER BY e.mtime"
18d0: 29 0a 0a 23 20 2d 2d 2d 20 61 20 77 69 6b 69 20  )..# --- a wiki 
18e0: 70 61 67 65 2c 20 62 79 20 61 64 61 6d 0a 28 63  page, by adam.(c
18f0: 64 20 22 24 43 4f 22 20 26 26 20 66 6f 73 73 69  d "$CO" && fossi
1900: 6c 20 75 73 65 72 20 64 65 66 61 75 6c 74 20 61  l user default a
1910: 64 61 6d 20 26 26 20 70 72 69 6e 74 66 20 27 23  dam && printf '#
1920: 20 4e 6f 74 65 73 5c 6e 5c 6e 53 63 72 61 74 63   Notes\n\nScratc
1930: 68 20 6e 6f 74 65 73 20 66 6f 72 20 74 65 73 74  h notes for test
1940: 65 72 73 2e 5c 6e 27 20 3e 20 22 24 44 49 52 2f  ers.\n' > "$DIR/
1950: 73 65 72 76 65 72 2f 6e 6f 74 65 73 2e 6d 64 22  server/notes.md"
1960: 20 26 26 20 5c 0a 20 66 6f 73 73 69 6c 20 77 69   && \. fossil wi
1970: 6b 69 20 63 72 65 61 74 65 20 4e 6f 74 65 73 20  ki create Notes 
1980: 22 24 44 49 52 2f 73 65 72 76 65 72 2f 6e 6f 74  "$DIR/server/not
1990: 65 73 2e 6d 64 22 20 2d 2d 6d 69 6d 65 74 79 70  es.md" --mimetyp
19a0: 65 20 74 65 78 74 2f 78 2d 6d 61 72 6b 64 6f 77  e text/x-markdow
19b0: 6e 20 3e 2f 64 65 76 2f 6e 75 6c 6c 29 0a 0a 23  n >/dev/null)..#
19c0: 20 2d 2d 2d 20 61 20 74 69 63 6b 65 74 20 61 6e   --- a ticket an
19d0: 64 20 69 74 73 20 63 68 61 6e 67 65 73 2c 20 62  d its changes, b
19e0: 79 20 64 69 66 66 65 72 65 6e 74 20 75 73 65 72  y different user
19f0: 73 0a 28 63 64 20 22 24 43 4f 22 20 26 26 20 66  s.(cd "$CO" && f
1a00: 6f 73 73 69 6c 20 75 73 65 72 20 64 65 66 61 75  ossil user defau
1a10: 6c 74 20 6f 77 6e 65 72 29 0a 74 6b 74 5f 6f 75  lt owner).tkt_ou
1a20: 74 3d 24 28 63 64 20 22 24 43 4f 22 20 26 26 20  t=$(cd "$CO" && 
1a30: 66 6f 73 73 69 6c 20 74 69 63 6b 65 74 20 61 64  fossil ticket ad
1a40: 64 20 74 69 74 6c 65 20 22 53 63 72 61 74 63 68  d title "Scratch
1a50: 20 74 69 63 6b 65 74 22 20 73 74 61 74 75 73 20   ticket" status 
1a60: 4f 70 65 6e 20 74 79 70 65 20 43 6f 64 65 5f 44  Open type Code_D
1a70: 65 66 65 63 74 20 63 6f 6d 6d 65 6e 74 20 22 46  efect comment "F
1a80: 69 72 73 74 20 72 65 70 6f 72 74 2e 22 29 0a 54  irst report.").T
1a90: 49 43 4b 45 54 3d 24 28 70 72 69 6e 74 66 20 27  ICKET=$(printf '
1aa0: 25 73 5c 6e 27 20 22 24 74 6b 74 5f 6f 75 74 22  %s\n' "$tkt_out"
1ab0: 20 7c 20 73 65 64 20 2d 6e 20 27 73 2f 2e 2a 66   | sed -n 's/.*f
1ac0: 6f 72 20 5c 28 5b 30 2d 39 61 2d 66 5d 5c 7b 34  or \([0-9a-f]\{4
1ad0: 30 2c 36 34 5c 7d 5c 29 2e 2a 2f 5c 31 2f 70 27  0,64\}\).*/\1/p'
1ae0: 29 0a 5b 20 2d 6e 20 22 24 54 49 43 4b 45 54 22  ).[ -n "$TICKET"
1af0: 20 5d 20 7c 7c 20 7b 20 65 63 68 6f 20 22 74 69   ] || { echo "ti
1b00: 63 6b 65 74 20 61 64 64 20 70 72 69 6e 74 65 64  cket add printed
1b10: 20 6e 6f 20 68 61 73 68 3a 20 24 74 6b 74 5f 6f   no hash: $tkt_o
1b20: 75 74 22 20 3e 26 32 3b 20 65 78 69 74 20 31 3b  ut" >&2; exit 1;
1b30: 20 7d 0a 28 63 64 20 22 24 43 4f 22 20 26 26 20   }.(cd "$CO" && 
1b40: 66 6f 73 73 69 6c 20 75 73 65 72 20 64 65 66 61  fossil user defa
1b50: 75 6c 74 20 69 76 79 20 26 26 20 66 6f 73 73 69  ult ivy && fossi
1b60: 6c 20 74 69 63 6b 65 74 20 63 68 61 6e 67 65 20  l ticket change 
1b70: 22 24 54 49 43 4b 45 54 22 20 69 63 6f 6d 6d 65  "$TICKET" icomme
1b80: 6e 74 20 22 53 65 65 6e 20 69 74 20 74 6f 6f 2c  nt "Seen it too,
1b90: 20 62 79 20 69 76 79 2e 22 20 3e 2f 64 65 76 2f   by ivy." >/dev/
1ba0: 6e 75 6c 6c 29 0a 28 63 64 20 22 24 43 4f 22 20  null).(cd "$CO" 
1bb0: 26 26 20 66 6f 73 73 69 6c 20 75 73 65 72 20 64  && fossil user d
1bc0: 65 66 61 75 6c 74 20 73 61 6c 6c 79 20 26 26 20  efault sally && 
1bd0: 66 6f 73 73 69 6c 20 74 69 63 6b 65 74 20 63 68  fossil ticket ch
1be0: 61 6e 67 65 20 22 24 54 49 43 4b 45 54 22 20 73  ange "$TICKET" s
1bf0: 74 61 74 75 73 20 46 69 78 65 64 20 69 63 6f 6d  tatus Fixed icom
1c00: 6d 65 6e 74 20 22 46 69 78 65 64 2c 20 62 79 20  ment "Fixed, by 
1c10: 73 61 6c 6c 79 2e 22 20 3e 2f 64 65 76 2f 6e 75  sally." >/dev/nu
1c20: 6c 6c 29 0a 28 63 64 20 22 24 43 4f 22 20 26 26  ll).(cd "$CO" &&
1c30: 20 66 6f 73 73 69 6c 20 75 73 65 72 20 64 65 66   fossil user def
1c40: 61 75 6c 74 20 6f 77 6e 65 72 29 0a 0a 23 20 2d  ault owner)..# -
1c50: 2d 2d 20 74 68 65 20 73 65 72 76 65 72 0a 65 63  -- the server.ec
1c60: 68 6f 20 22 24 50 4f 52 54 22 20 3e 20 22 24 44  ho "$PORT" > "$D
1c70: 49 52 2f 73 65 72 76 65 72 2e 70 6f 72 74 22 0a  IR/server.port".
1c80: 63 64 20 22 24 44 49 52 22 0a 63 61 74 20 3e 20  cd "$DIR".cat > 
1c90: 22 24 44 49 52 2f 73 74 61 72 74 2e 73 68 22 20  "$DIR/start.sh" 
1ca0: 3c 3c 45 4f 46 0a 23 21 2f 62 69 6e 2f 73 68 0a  <<EOF.#!/bin/sh.
1cb0: 23 20 53 74 61 72 74 73 20 28 61 67 61 69 6e 29  # Starts (again)
1cc0: 20 74 68 65 20 73 63 72 61 74 63 68 20 73 65 72   the scratch ser
1cd0: 76 65 72 20 66 6f 72 20 24 44 49 52 20 6f 6e 20  ver for $DIR on 
1ce0: 31 32 37 2e 30 2e 30 2e 31 3a 24 50 4f 52 54 2c  127.0.0.1:$PORT,
1cf0: 20 6e 69 63 65 64 2c 20 69 6e 0a 23 20 69 74 73   niced, in.# its
1d00: 20 6f 77 6e 20 73 65 73 73 69 6f 6e 3b 20 44 49   own session; DI
1d10: 52 2f 73 74 6f 70 2e 73 68 20 73 74 6f 70 73 20  R/stop.sh stops 
1d20: 69 74 2e 0a 5b 20 2d 66 20 22 24 44 49 52 2f 73  it..[ -f "$DIR/s
1d30: 65 72 76 65 72 2e 70 69 64 22 20 5d 20 26 26 20  erver.pid" ] && 
1d40: 6b 69 6c 6c 20 2d 30 20 22 5c 24 28 63 61 74 20  kill -0 "\$(cat 
1d50: 22 24 44 49 52 2f 73 65 72 76 65 72 2e 70 69 64  "$DIR/server.pid
1d60: 22 29 22 20 32 3e 2f 64 65 76 2f 6e 75 6c 6c 20  ")" 2>/dev/null 
1d70: 26 26 20 7b 20 65 63 68 6f 20 22 61 6c 72 65 61  && { echo "alrea
1d80: 64 79 20 72 75 6e 6e 69 6e 67 22 20 3e 26 32 3b  dy running" >&2;
1d90: 20 65 78 69 74 20 31 3b 20 7d 0a 63 64 20 22 24   exit 1; }.cd "$
1da0: 44 49 52 22 0a 48 4f 4d 45 3d 22 24 44 49 52 2f  DIR".HOME="$DIR/
1db0: 68 6f 6d 65 22 20 73 65 74 73 69 64 20 6e 69 63  home" setsid nic
1dc0: 65 20 2d 6e 20 31 30 20 62 77 72 61 70 20 2d 2d  e -n 10 bwrap --
1dd0: 64 65 76 2d 62 69 6e 64 20 2f 20 2f 20 2d 2d 62  dev-bind / / --b
1de0: 69 6e 64 20 22 24 44 49 52 2f 61 63 63 74 22 20  ind "$DIR/acct" 
1df0: 22 24 41 43 43 54 5f 48 4f 4d 45 22 20 2d 2d 20  "$ACCT_HOME" -- 
1e00: 22 24 46 4f 53 53 49 4c 22 20 73 65 72 76 65 72  "$FOSSIL" server
1e10: 20 2d 2d 6c 6f 63 61 6c 68 6f 73 74 20 2d 2d 70   --localhost --p
1e20: 6f 72 74 20 22 24 50 4f 52 54 22 20 2d 2d 6e 6f  ort "$PORT" --no
1e30: 6a 61 69 6c 20 5c 5c 0a 20 20 2d 2d 65 78 74 72  jail \\.  --extr
1e40: 6f 6f 74 20 22 24 44 49 52 2f 65 78 74 22 20 2d  oot "$DIR/ext" -
1e50: 2d 65 72 72 6f 72 6c 6f 67 20 22 24 44 49 52 2f  -errorlog "$DIR/
1e60: 73 65 72 76 65 72 2e 65 72 72 2e 6c 6f 67 22 20  server.err.log" 
1e70: 22 24 52 45 50 4f 22 20 3e 3e 20 22 24 44 49 52  "$REPO" >> "$DIR
1e80: 2f 73 65 72 76 65 72 2e 6c 6f 67 22 20 32 3e 26  /server.log" 2>&
1e90: 31 20 3c 20 2f 64 65 76 2f 6e 75 6c 6c 20 26 0a  1 < /dev/null &.
1ea0: 65 63 68 6f 20 5c 24 21 20 3e 20 22 24 44 49 52  echo \$! > "$DIR
1eb0: 2f 73 65 72 76 65 72 2e 70 69 64 22 0a 69 3d 30  /server.pid".i=0
1ec0: 0a 75 6e 74 69 6c 20 63 75 72 6c 20 2d 73 20 2d  .until curl -s -
1ed0: 6f 20 2f 64 65 76 2f 6e 75 6c 6c 20 2d 2d 6d 61  o /dev/null --ma
1ee0: 78 2d 74 69 6d 65 20 31 20 22 24 55 52 4c 2f 22  x-time 1 "$URL/"
1ef0: 3b 20 64 6f 0a 20 20 69 3d 5c 24 28 28 69 2b 31  ; do.  i=\$((i+1
1f00: 29 29 3b 20 5b 20 5c 24 69 20 2d 6c 74 20 35 30  )); [ \$i -lt 50
1f10: 20 5d 20 7c 7c 20 7b 20 65 63 68 6f 20 22 66 6f   ] || { echo "fo
1f20: 73 73 69 6c 20 73 65 72 76 65 72 20 64 69 64 20  ssil server did 
1f30: 6e 6f 74 20 61 6e 73 77 65 72 20 6f 6e 20 24 55  not answer on $U
1f40: 52 4c 22 20 3e 26 32 3b 20 22 24 44 49 52 2f 73  RL" >&2; "$DIR/s
1f50: 74 6f 70 2e 73 68 22 3b 20 65 78 69 74 20 31 3b  top.sh"; exit 1;
1f60: 20 7d 0a 20 20 73 6c 65 65 70 20 30 2e 31 0a 64   }.  sleep 0.1.d
1f70: 6f 6e 65 0a 65 63 68 6f 20 22 73 65 72 76 69 6e  one.echo "servin
1f80: 67 20 24 55 52 4c 20 28 70 69 64 20 5c 24 28 63  g $URL (pid \$(c
1f90: 61 74 20 22 24 44 49 52 2f 73 65 72 76 65 72 2e  at "$DIR/server.
1fa0: 70 69 64 22 29 29 22 0a 45 4f 46 0a 63 68 6d 6f  pid"))".EOF.chmo
1fb0: 64 20 37 35 35 20 22 24 44 49 52 2f 73 74 61 72  d 755 "$DIR/star
1fc0: 74 2e 73 68 22 0a 63 61 74 20 3e 20 22 24 44 49  t.sh".cat > "$DI
1fd0: 52 2f 73 74 6f 70 2e 73 68 22 20 3c 3c 45 4f 46  R/stop.sh" <<EOF
1fe0: 0a 23 21 2f 62 69 6e 2f 73 68 0a 23 20 53 74 6f  .#!/bin/sh.# Sto
1ff0: 70 73 20 74 68 65 20 73 63 72 61 74 63 68 20 73  ps the scratch s
2000: 65 72 76 65 72 20 73 65 74 75 70 2e 73 68 20 73  erver setup.sh s
2010: 74 61 72 74 65 64 20 66 6f 72 20 24 44 49 52 3a  tarted for $DIR:
2020: 20 69 74 73 20 70 72 6f 63 65 73 73 20 67 72 6f   its process gro
2030: 75 70 2c 0a 23 20 61 6e 64 20 61 6e 79 20 70 72  up,.# and any pr
2040: 6f 63 65 73 73 20 73 74 69 6c 6c 20 73 65 72 76  ocess still serv
2050: 69 6e 67 20 74 68 69 73 20 72 65 70 6f 73 69 74  ing this reposit
2060: 6f 72 79 2c 20 73 75 63 68 20 61 73 20 46 6f 73  ory, such as Fos
2070: 73 69 6c 27 73 0a 23 20 62 61 63 6b 6f 66 66 69  sil's.# backoffi
2080: 63 65 2c 20 77 68 69 63 68 20 6c 65 61 76 65 73  ce, which leaves
2090: 20 69 74 73 20 73 65 72 76 65 72 27 73 20 70 72   its server's pr
20a0: 6f 63 65 73 73 20 67 72 6f 75 70 20 61 6e 64 20  ocess group and 
20b0: 6d 61 79 20 6c 69 6e 67 65 72 2e 0a 70 69 64 3d  may linger..pid=
20c0: 5c 24 28 63 61 74 20 22 24 44 49 52 2f 73 65 72  \$(cat "$DIR/ser
20d0: 76 65 72 2e 70 69 64 22 20 32 3e 2f 64 65 76 2f  ver.pid" 2>/dev/
20e0: 6e 75 6c 6c 29 0a 5b 20 2d 6e 20 22 5c 24 70 69  null).[ -n "\$pi
20f0: 64 22 20 5d 20 26 26 20 7b 20 6b 69 6c 6c 20 2d  d" ] && { kill -
2100: 54 45 52 4d 20 2d 2d 20 2d 5c 24 70 69 64 20 32  TERM -- -\$pid 2
2110: 3e 2f 64 65 76 2f 6e 75 6c 6c 20 7c 7c 20 6b 69  >/dev/null || ki
2120: 6c 6c 20 2d 54 45 52 4d 20 5c 24 70 69 64 20 32  ll -TERM \$pid 2
2130: 3e 2f 64 65 76 2f 6e 75 6c 6c 3b 20 7d 0a 73 65  >/dev/null; }.se
2140: 72 76 69 6e 67 28 29 20 7b 0a 20 20 66 6f 72 20  rving() {.  for 
2150: 70 20 69 6e 20 2f 70 72 6f 63 2f 5b 30 2d 39 5d  p in /proc/[0-9]
2160: 2a 3b 20 64 6f 0a 20 20 20 20 63 3d 5c 24 28 74  *; do.    c=\$(t
2170: 72 20 27 5c 5c 30 27 20 27 20 27 20 32 3e 2f 64  r '\\0' ' ' 2>/d
2180: 65 76 2f 6e 75 6c 6c 20 3c 20 5c 24 70 2f 63 6d  ev/null < \$p/cm
2190: 64 6c 69 6e 65 29 20 7c 7c 20 63 6f 6e 74 69 6e  dline) || contin
21a0: 75 65 0a 20 20 20 20 63 61 73 65 20 22 5c 24 63  ue.    case "\$c
21b0: 22 20 69 6e 20 2a 22 66 6f 73 73 69 6c 20 73 65  " in *"fossil se
21c0: 72 76 65 72 20 22 2a 22 24 52 45 50 4f 22 2a 29  rver "*"$REPO"*)
21d0: 20 65 63 68 6f 20 5c 24 7b 70 23 2f 70 72 6f 63   echo \${p#/proc
21e0: 2f 7d 3b 3b 20 65 73 61 63 0a 20 20 64 6f 6e 65  /};; esac.  done
21f0: 0a 7d 0a 66 6f 72 20 69 20 69 6e 20 31 20 32 20  .}.for i in 1 2 
2200: 33 20 34 20 35 20 36 20 37 20 38 20 39 20 31 30  3 4 5 6 7 8 9 10
2210: 3b 20 64 6f 0a 20 20 6c 65 66 74 3d 5c 24 28 73  ; do.  left=\$(s
2220: 65 72 76 69 6e 67 29 3b 20 5b 20 2d 7a 20 22 5c  erving); [ -z "\
2230: 24 6c 65 66 74 22 20 5d 20 26 26 20 62 72 65 61  $left" ] && brea
2240: 6b 0a 20 20 6b 69 6c 6c 20 2d 54 45 52 4d 20 5c  k.  kill -TERM \
2250: 24 6c 65 66 74 20 32 3e 2f 64 65 76 2f 6e 75 6c  $left 2>/dev/nul
2260: 6c 3b 20 73 6c 65 65 70 20 30 2e 32 0a 64 6f 6e  l; sleep 0.2.don
2270: 65 0a 6c 65 66 74 3d 5c 24 28 73 65 72 76 69 6e  e.left=\$(servin
2280: 67 29 3b 20 5b 20 2d 6e 20 22 5c 24 6c 65 66 74  g); [ -n "\$left
2290: 22 20 5d 20 26 26 20 6b 69 6c 6c 20 2d 4b 49 4c  " ] && kill -KIL
22a0: 4c 20 5c 24 6c 65 66 74 20 32 3e 2f 64 65 76 2f  L \$left 2>/dev/
22b0: 6e 75 6c 6c 0a 72 6d 20 2d 66 20 22 24 44 49 52  null.rm -f "$DIR
22c0: 2f 73 65 72 76 65 72 2e 70 69 64 22 0a 5b 20 2d  /server.pid".[ -
22d0: 7a 20 22 5c 24 28 73 65 72 76 69 6e 67 29 22 20  z "\$(serving)" 
22e0: 5d 20 26 26 20 65 63 68 6f 20 22 73 74 6f 70 70  ] && echo "stopp
22f0: 65 64 3a 20 6e 6f 74 68 69 6e 67 20 73 65 72 76  ed: nothing serv
2300: 65 73 20 24 52 45 50 4f 22 20 7c 7c 20 7b 20 65  es $REPO" || { e
2310: 63 68 6f 20 22 73 74 69 6c 6c 20 73 65 72 76 69  cho "still servi
2320: 6e 67 3a 20 5c 24 28 73 65 72 76 69 6e 67 29 22  ng: \$(serving)"
2330: 20 3e 26 32 3b 20 65 78 69 74 20 31 3b 20 7d 0a   >&2; exit 1; }.
2340: 45 4f 46 0a 63 68 6d 6f 64 20 37 35 35 20 22 24  EOF.chmod 755 "$
2350: 44 49 52 2f 73 74 6f 70 2e 73 68 22 0a 23 20 61  DIR/stop.sh".# a
2360: 20 66 61 69 6c 75 72 65 20 66 72 6f 6d 20 68 65   failure from he
2370: 72 65 20 6f 6e 20 6c 65 61 76 65 73 20 6e 6f 20  re on leaves no 
2380: 73 65 72 76 65 72 20 72 75 6e 6e 69 6e 67 0a 74  server running.t
2390: 72 61 70 20 27 73 74 3d 24 3f 3b 20 5b 20 24 73  rap 'st=$?; [ $s
23a0: 74 20 2d 65 71 20 30 20 5d 20 7c 7c 20 7b 20 65  t -eq 0 ] || { e
23b0: 63 68 6f 20 22 73 65 74 75 70 20 66 61 69 6c 65  cho "setup faile
23c0: 64 20 28 24 73 74 29 3b 20 73 74 6f 70 70 69 6e  d ($st); stoppin
23d0: 67 20 74 68 65 20 73 65 72 76 65 72 22 20 3e 26  g the server" >&
23e0: 32 3b 20 22 24 44 49 52 2f 73 74 6f 70 2e 73 68  2; "$DIR/stop.sh
23f0: 22 20 3e 26 32 3b 20 7d 27 20 45 58 49 54 0a 22  " >&2; }' EXIT."
2400: 24 44 49 52 2f 73 74 61 72 74 2e 73 68 22 20 3e  $DIR/start.sh" >
2410: 2f 64 65 76 2f 6e 75 6c 6c 0a 0a 23 20 2d 2d 2d  /dev/null..# ---
2420: 20 61 20 66 6f 72 75 6d 20 74 68 72 65 61 64 20   a forum thread 
2430: 74 68 72 6f 75 67 68 20 46 6f 73 73 69 6c 27 73  through Fossil's
2440: 20 6f 77 6e 20 66 6f 72 6d 2c 20 72 65 70 6c 69   own form, repli
2450: 65 73 20 62 79 20 64 69 66 66 65 72 65 6e 74 20  es by different 
2460: 75 73 65 72 73 0a 4a 41 52 53 3d 22 24 44 49 52  users.JARS="$DIR
2470: 2f 68 6f 6d 65 2f 6a 61 72 73 22 3b 20 6d 6b 64  /home/jars"; mkd
2480: 69 72 20 2d 70 20 22 24 4a 41 52 53 22 0a 6c 6f  ir -p "$JARS".lo
2490: 67 69 6e 28 29 20 7b 20 23 20 75 73 65 72 20 2d  gin() { # user -
24a0: 3e 20 63 6f 6f 6b 69 65 20 6a 61 72 20 70 61 74  > cookie jar pat
24b0: 68 0a 20 20 63 75 72 6c 20 2d 73 20 2d 6f 20 2f  h.  curl -s -o /
24c0: 64 65 76 2f 6e 75 6c 6c 20 2d 63 20 22 24 4a 41  dev/null -c "$JA
24d0: 52 53 2f 24 31 22 20 2d 2d 64 61 74 61 2d 75 72  RS/$1" --data-ur
24e0: 6c 65 6e 63 6f 64 65 20 22 75 3d 24 31 22 20 2d  lencode "u=$1" -
24f0: 2d 64 61 74 61 2d 75 72 6c 65 6e 63 6f 64 65 20  -data-urlencode 
2500: 22 70 3d 24 28 70 61 73 73 77 6f 72 64 5f 6f 66  "p=$(password_of
2510: 20 22 24 31 22 29 22 20 2d 64 20 69 6e 3d 31 20   "$1")" -d in=1 
2520: 22 24 55 52 4c 2f 6c 6f 67 69 6e 22 0a 20 20 67  "$URL/login".  g
2530: 72 65 70 20 2d 71 20 66 6f 73 73 69 6c 2d 20 22  rep -q fossil- "
2540: 24 4a 41 52 53 2f 24 31 22 20 7c 7c 20 7b 20 65  $JARS/$1" || { e
2550: 63 68 6f 20 22 6c 6f 67 69 6e 20 61 73 20 24 31  cho "login as $1
2560: 20 73 65 74 20 6e 6f 20 63 6f 6f 6b 69 65 22 20   set no cookie" 
2570: 3e 26 32 3b 20 65 78 69 74 20 31 3b 20 7d 0a 7d  >&2; exit 1; }.}
2580: 0a 63 73 72 66 28 29 20 7b 20 73 65 64 20 2d 6e  .csrf() { sed -n
2590: 20 27 73 2f 2e 2a 6e 61 6d 65 3d 22 63 73 72 66   's/.*name="csrf
25a0: 22 20 76 61 6c 75 65 3d 22 5c 28 5b 5e 22 5d 2a  " value="\([^"]*
25b0: 5c 29 22 2e 2a 2f 5c 31 2f 70 27 20 7c 20 68 65  \)".*/\1/p' | he
25c0: 61 64 20 2d 6e 20 31 3b 20 7d 0a 6c 61 74 65 73  ad -n 1; }.lates
25d0: 74 5f 70 6f 73 74 28 29 20 7b 20 66 6f 73 73 69  t_post() { fossi
25e0: 6c 20 73 71 6c 20 2d 52 20 22 24 52 45 50 4f 22  l sql -R "$REPO"
25f0: 20 22 53 45 4c 45 43 54 20 62 2e 75 75 69 64 20   "SELECT b.uuid 
2600: 46 52 4f 4d 20 62 6c 6f 62 20 62 20 4a 4f 49 4e  FROM blob b JOIN
2610: 20 66 6f 72 75 6d 70 6f 73 74 20 66 20 4f 4e 20   forumpost f ON 
2620: 62 2e 72 69 64 3d 66 2e 66 70 69 64 20 4f 52 44  b.rid=f.fpid ORD
2630: 45 52 20 42 59 20 66 2e 66 6d 74 69 6d 65 20 44  ER BY f.fmtime D
2640: 45 53 43 2c 20 66 2e 66 70 69 64 20 44 45 53 43  ESC, f.fpid DESC
2650: 20 4c 49 4d 49 54 20 31 22 20 7c 20 74 72 20 2d   LIMIT 1" | tr -
2660: 64 20 22 27 22 3b 20 7d 0a 6e 65 77 5f 74 68 72  d "'"; }.new_thr
2670: 65 61 64 28 29 20 7b 20 23 20 75 73 65 72 20 74  ead() { # user t
2680: 69 74 6c 65 20 63 6f 6e 74 65 6e 74 0a 20 20 6c  itle content.  l
2690: 6f 67 69 6e 20 22 24 31 22 0a 20 20 74 3d 24 28  ogin "$1".  t=$(
26a0: 63 75 72 6c 20 2d 73 20 2d 62 20 22 24 4a 41 52  curl -s -b "$JAR
26b0: 53 2f 24 31 22 20 22 24 55 52 4c 2f 66 6f 72 75  S/$1" "$URL/foru
26c0: 6d 6e 65 77 22 20 7c 20 63 73 72 66 29 0a 20 20  mnew" | csrf).  
26d0: 63 75 72 6c 20 2d 73 20 2d 6f 20 2f 64 65 76 2f  curl -s -o /dev/
26e0: 6e 75 6c 6c 20 2d 62 20 22 24 4a 41 52 53 2f 24  null -b "$JARS/$
26f0: 31 22 20 2d 65 20 22 24 55 52 4c 2f 66 6f 72 75  1" -e "$URL/foru
2700: 6d 6e 65 77 22 20 2d 2d 64 61 74 61 2d 75 72 6c  mnew" --data-url
2710: 65 6e 63 6f 64 65 20 22 63 73 72 66 3d 24 74 22  encode "csrf=$t"
2720: 20 2d 2d 64 61 74 61 2d 75 72 6c 65 6e 63 6f 64   --data-urlencod
2730: 65 20 22 74 69 74 6c 65 3d 24 32 22 20 5c 0a 20  e "title=$2" \. 
2740: 20 20 20 2d 64 20 6d 69 6d 65 74 79 70 65 3d 74     -d mimetype=t
2750: 65 78 74 2f 78 2d 6d 61 72 6b 64 6f 77 6e 20 2d  ext/x-markdown -
2760: 2d 64 61 74 61 2d 75 72 6c 65 6e 63 6f 64 65 20  -data-urlencode 
2770: 22 63 6f 6e 74 65 6e 74 3d 24 33 22 20 2d 64 20  "content=$3" -d 
2780: 73 75 62 6d 69 74 3d 53 75 62 6d 69 74 20 22 24  submit=Submit "$
2790: 55 52 4c 2f 66 6f 72 75 6d 65 31 22 0a 20 20 6c  URL/forume1".  l
27a0: 61 74 65 73 74 5f 70 6f 73 74 0a 7d 0a 72 65 70  atest_post.}.rep
27b0: 6c 79 28 29 20 7b 20 23 20 75 73 65 72 20 74 6f  ly() { # user to
27c0: 20 63 6f 6e 74 65 6e 74 0a 20 20 6c 6f 67 69 6e   content.  login
27d0: 20 22 24 31 22 0a 20 20 74 3d 24 28 63 75 72 6c   "$1".  t=$(curl
27e0: 20 2d 73 20 2d 62 20 22 24 4a 41 52 53 2f 24 31   -s -b "$JARS/$1
27f0: 22 20 22 24 55 52 4c 2f 66 6f 72 75 6d 70 6f 73  " "$URL/forumpos
2800: 74 2f 24 32 22 20 7c 20 63 73 72 66 29 0a 20 20  t/$2" | csrf).  
2810: 63 75 72 6c 20 2d 73 20 2d 6f 20 2f 64 65 76 2f  curl -s -o /dev/
2820: 6e 75 6c 6c 20 2d 62 20 22 24 4a 41 52 53 2f 24  null -b "$JARS/$
2830: 31 22 20 2d 65 20 22 24 55 52 4c 2f 66 6f 72 75  1" -e "$URL/foru
2840: 6d 65 32 22 20 2d 2d 64 61 74 61 2d 75 72 6c 65  me2" --data-urle
2850: 6e 63 6f 64 65 20 22 63 73 72 66 3d 24 74 22 20  ncode "csrf=$t" 
2860: 2d 64 20 22 66 70 69 64 3d 24 32 22 20 2d 64 20  -d "fpid=$2" -d 
2870: 72 65 70 6c 79 3d 31 20 5c 0a 20 20 20 20 2d 64  reply=1 \.    -d
2880: 20 6d 69 6d 65 74 79 70 65 3d 74 65 78 74 2f 78   mimetype=text/x
2890: 2d 6d 61 72 6b 64 6f 77 6e 20 2d 2d 64 61 74 61  -markdown --data
28a0: 2d 75 72 6c 65 6e 63 6f 64 65 20 22 63 6f 6e 74  -urlencode "cont
28b0: 65 6e 74 3d 24 33 22 20 2d 64 20 73 75 62 6d 69  ent=$3" -d submi
28c0: 74 3d 53 75 62 6d 69 74 20 22 24 55 52 4c 2f 66  t=Submit "$URL/f
28d0: 6f 72 75 6d 65 32 22 0a 20 20 6c 61 74 65 73 74  orume2".  latest
28e0: 5f 70 6f 73 74 0a 7d 0a 54 48 52 45 41 44 3d 24  _post.}.THREAD=$
28f0: 28 6e 65 77 5f 74 68 72 65 61 64 20 6f 77 6e 65  (new_thread owne
2900: 72 20 22 53 63 72 61 74 63 68 20 74 68 72 65 61  r "Scratch threa
2910: 64 22 20 22 54 68 65 20 66 69 72 73 74 20 70 6f  d" "The first po
2920: 73 74 2c 20 62 79 20 6f 77 6e 65 72 2e 22 29 0a  st, by owner.").
2930: 52 31 3d 24 28 72 65 70 6c 79 20 61 64 61 6d 20  R1=$(reply adam 
2940: 22 24 54 48 52 45 41 44 22 20 22 41 20 72 65 70  "$THREAD" "A rep
2950: 6c 79 2c 20 62 79 20 61 64 61 6d 2e 22 29 0a 52  ly, by adam.").R
2960: 32 3d 24 28 72 65 70 6c 79 20 73 61 6c 6c 79 20  2=$(reply sally 
2970: 22 24 52 31 22 20 22 41 20 72 65 70 6c 79 20 74  "$R1" "A reply t
2980: 6f 20 61 64 61 6d 2c 20 62 79 20 73 61 6c 6c 79  o adam, by sally
2990: 2e 22 29 0a 52 33 3d 24 28 72 65 70 6c 79 20 6f  .").R3=$(reply o
29a0: 77 6e 65 72 20 22 24 54 48 52 45 41 44 22 20 22  wner "$THREAD" "
29b0: 41 20 73 65 63 6f 6e 64 20 72 65 70 6c 79 20 74  A second reply t
29c0: 6f 20 74 68 65 20 66 69 72 73 74 20 70 6f 73 74  o the first post
29d0: 2c 20 62 79 20 6f 77 6e 65 72 2e 22 29 0a 70 6f  , by owner.").po
29e0: 73 74 73 3d 24 28 66 6f 73 73 69 6c 20 73 71 6c  sts=$(fossil sql
29f0: 20 2d 52 20 22 24 52 45 50 4f 22 20 22 53 45 4c   -R "$REPO" "SEL
2a00: 45 43 54 20 62 2e 75 75 69 64 7c 7c 27 20 27 7c  ECT b.uuid||' '|
2a10: 7c 65 2e 75 73 65 72 20 46 52 4f 4d 20 66 6f 72  |e.user FROM for
2a20: 75 6d 70 6f 73 74 20 66 20 4a 4f 49 4e 20 62 6c  umpost f JOIN bl
2a30: 6f 62 20 62 20 4f 4e 20 62 2e 72 69 64 3d 66 2e  ob b ON b.rid=f.
2a40: 66 70 69 64 20 4a 4f 49 4e 20 65 76 65 6e 74 20  fpid JOIN event 
2a50: 65 20 4f 4e 20 65 2e 6f 62 6a 69 64 3d 66 2e 66  e ON e.objid=f.f
2a60: 70 69 64 20 4f 52 44 45 52 20 42 59 20 66 2e 66  pid ORDER BY f.f
2a70: 6d 74 69 6d 65 22 29 0a 5b 20 22 24 28 70 72 69  mtime").[ "$(pri
2a80: 6e 74 66 20 27 25 73 5c 6e 27 20 22 24 70 6f 73  ntf '%s\n' "$pos
2a90: 74 73 22 20 7c 20 77 63 20 2d 6c 29 22 20 2d 65  ts" | wc -l)" -e
2aa0: 71 20 34 20 5d 20 7c 7c 20 7b 20 65 63 68 6f 20  q 4 ] || { echo 
2ab0: 22 65 78 70 65 63 74 65 64 20 34 20 70 6f 73 74  "expected 4 post
2ac0: 73 2c 20 68 61 76 65 3a 20 24 70 6f 73 74 73 22  s, have: $posts"
2ad0: 20 3e 26 32 3b 20 22 24 44 49 52 2f 73 74 6f 70   >&2; "$DIR/stop
2ae0: 2e 73 68 22 3b 20 65 78 69 74 20 31 3b 20 7d 0a  .sh"; exit 1; }.
2af0: 0a 23 20 2d 2d 2d 20 61 20 63 6c 6f 6e 65 20 6f  .# --- a clone o
2b00: 76 65 72 20 48 54 54 50 20 61 73 20 69 76 79 2c  ver HTTP as ivy,
2b10: 20 77 69 74 68 20 61 20 63 68 65 63 6b 6f 75 74   with a checkout
2b20: 0a 49 56 59 3d 22 24 44 49 52 2f 63 6c 6f 6e 65  .IVY="$DIR/clone
2b30: 73 2f 69 76 79 22 0a 6d 6b 64 69 72 20 2d 70 20  s/ivy".mkdir -p 
2b40: 22 24 49 56 59 2f 74 72 65 65 22 0a 28 63 64 20  "$IVY/tree".(cd 
2b50: 22 24 49 56 59 22 20 26 26 20 66 6f 73 73 69 6c  "$IVY" && fossil
2b60: 20 63 6c 6f 6e 65 20 2d 41 20 69 76 79 20 2d 2d   clone -A ivy --
2b70: 73 61 76 65 2d 68 74 74 70 2d 70 61 73 73 77 6f  save-http-passwo
2b80: 72 64 20 22 68 74 74 70 3a 2f 2f 69 76 79 3a 24  rd "http://ivy:$
2b90: 28 70 61 73 73 77 6f 72 64 5f 6f 66 20 69 76 79  (password_of ivy
2ba0: 29 40 31 32 37 2e 30 2e 30 2e 31 3a 24 50 4f 52  )@127.0.0.1:$POR
2bb0: 54 2f 22 20 22 24 49 56 59 2f 63 6c 6f 6e 65 2e  T/" "$IVY/clone.
2bc0: 66 6f 73 73 69 6c 22 20 3e 2f 64 65 76 2f 6e 75  fossil" >/dev/nu
2bd0: 6c 6c 29 0a 28 63 64 20 22 24 49 56 59 2f 74 72  ll).(cd "$IVY/tr
2be0: 65 65 22 20 26 26 20 66 6f 73 73 69 6c 20 6f 70  ee" && fossil op
2bf0: 65 6e 20 22 24 49 56 59 2f 63 6c 6f 6e 65 2e 66  en "$IVY/clone.f
2c00: 6f 73 73 69 6c 22 20 3e 2f 64 65 76 2f 6e 75 6c  ossil" >/dev/nul
2c10: 6c 20 26 26 20 66 6f 73 73 69 6c 20 75 73 65 72  l && fossil user
2c20: 20 64 65 66 61 75 6c 74 20 69 76 79 20 26 26 20   default ivy && 
2c30: 66 6f 73 73 69 6c 20 73 65 74 74 69 6e 67 73 20  fossil settings 
2c40: 61 75 74 6f 73 79 6e 63 20 6f 66 66 29 0a 0a 63  autosync off)..c
2c50: 61 74 20 3e 20 22 24 44 49 52 2f 65 6e 76 2e 73  at > "$DIR/env.s
2c60: 68 22 20 3c 3c 45 4f 46 0a 23 20 2e 20 24 44 49  h" <<EOF.# . $DI
2c70: 52 2f 65 6e 76 2e 73 68 20 20 20 2d 2d 20 66 6f  R/env.sh   -- fo
2c80: 72 20 74 65 73 74 65 72 73 3a 20 74 68 65 20 73  r testers: the s
2c90: 63 72 61 74 63 68 20 48 4f 4d 45 2c 20 6f 63 78  cratch HOME, ocx
2ca0: 32 20 6f 6e 20 50 41 54 48 2c 20 74 68 65 20 73  2 on PATH, the s
2cb0: 65 72 76 65 72 27 73 20 55 52 4c 0a 65 78 70 6f  erver's URL.expo
2cc0: 72 74 20 48 4f 4d 45 3d 22 24 44 49 52 2f 68 6f  rt HOME="$DIR/ho
2cd0: 6d 65 22 0a 65 78 70 6f 72 74 20 50 41 54 48 3d  me".export PATH=
2ce0: 22 24 44 49 52 2f 62 69 6e 3a 5c 24 50 41 54 48  "$DIR/bin:\$PATH
2cf0: 22 0a 65 78 70 6f 72 74 20 55 52 4c 3d 22 24 55  ".export URL="$U
2d00: 52 4c 22 0a 65 78 70 6f 72 74 20 52 45 50 4f 3d  RL".export REPO=
2d10: 22 24 52 45 50 4f 22 0a 45 4f 46 0a 0a 7b 0a 20  "$REPO".EOF..{. 
2d20: 20 65 63 68 6f 20 22 75 72 6c 20 24 55 52 4c 22   echo "url $URL"
2d30: 0a 20 20 65 63 68 6f 20 22 6f 63 78 5f 70 61 67  .  echo "ocx_pag
2d40: 65 20 24 55 52 4c 2f 65 78 74 2f 6f 63 78 32 2d  e $URL/ext/ocx2-
2d50: 63 67 69 22 0a 20 20 65 63 68 6f 20 22 72 65 70  cgi".  echo "rep
2d60: 6f 73 69 74 6f 72 79 20 24 52 45 50 4f 22 0a 20  ository $REPO". 
2d70: 20 65 63 68 6f 20 22 73 65 72 76 65 72 5f 63 68   echo "server_ch
2d80: 65 63 6b 6f 75 74 20 24 43 4f 22 0a 20 20 65 63  eckout $CO".  ec
2d90: 68 6f 20 22 63 6c 6f 6e 65 5f 69 76 79 20 24 49  ho "clone_ivy $I
2da0: 56 59 2f 63 6c 6f 6e 65 2e 66 6f 73 73 69 6c 22  VY/clone.fossil"
2db0: 0a 20 20 65 63 68 6f 20 22 63 68 65 63 6b 6f 75  .  echo "checkou
2dc0: 74 5f 69 76 79 20 24 49 56 59 2f 74 72 65 65 22  t_ivy $IVY/tree"
2dd0: 0a 20 20 65 63 68 6f 20 22 70 72 6f 67 72 61 6d  .  echo "program
2de0: 20 24 44 49 52 2f 72 6f 6f 74 2f 63 75 72 72 65   $DIR/root/curre
2df0: 6e 74 2f 6f 63 78 32 20 28 63 6f 70 79 20 6f 66  nt/ocx2 (copy of
2e00: 20 24 53 54 41 47 45 44 2c 20 73 68 61 32 35 36   $STAGED, sha256
2e10: 20 24 28 73 68 61 32 35 36 73 75 6d 20 22 24 53   $(sha256sum "$S
2e20: 54 41 47 45 44 22 20 7c 20 63 75 74 20 2d 64 27  TAGED" | cut -d'
2e30: 20 27 20 2d 66 31 29 29 22 0a 20 20 65 63 68 6f   ' -f1))".  echo
2e40: 20 22 74 69 63 6b 65 74 20 24 54 49 43 4b 45 54   "ticket $TICKET
2e50: 22 0a 20 20 65 63 68 6f 20 22 74 68 72 65 61 64  ".  echo "thread
2e60: 20 24 54 48 52 45 41 44 22 0a 20 20 65 63 68 6f   $THREAD".  echo
2e70: 20 22 72 65 70 6c 79 5f 61 64 61 6d 20 24 52 31   "reply_adam $R1
2e80: 22 0a 20 20 65 63 68 6f 20 22 72 65 70 6c 79 5f  ".  echo "reply_
2e90: 73 61 6c 6c 79 5f 74 6f 5f 61 64 61 6d 20 24 52  sally_to_adam $R
2ea0: 32 22 0a 20 20 65 63 68 6f 20 22 72 65 70 6c 79  2".  echo "reply
2eb0: 5f 6f 77 6e 65 72 20 24 52 33 22 0a 20 20 65 63  _owner $R3".  ec
2ec0: 68 6f 20 22 77 69 6b 69 20 4e 6f 74 65 73 22 0a  ho "wiki Notes".
2ed0: 20 20 70 72 69 6e 74 66 20 27 25 73 5c 6e 27 20    printf '%s\n' 
2ee0: 22 24 63 68 65 63 6b 69 6e 73 22 20 7c 20 74 72  "$checkins" | tr
2ef0: 20 2d 64 20 22 27 22 20 7c 20 73 65 64 20 27 73   -d "'" | sed 's
2f00: 2f 5e 2f 63 68 65 63 6b 69 6e 20 2f 27 0a 20 20  /^/checkin /'.  
2f10: 65 63 68 6f 20 22 6e 6f 62 6f 64 79 5f 63 61 70  echo "nobody_cap
2f20: 73 20 24 28 66 6f 73 73 69 6c 20 73 71 6c 20 2d  s $(fossil sql -
2f30: 52 20 22 24 52 45 50 4f 22 20 22 53 45 4c 45 43  R "$REPO" "SELEC
2f40: 54 20 63 61 70 20 46 52 4f 4d 20 75 73 65 72 20  T cap FROM user 
2f50: 57 48 45 52 45 20 6c 6f 67 69 6e 3d 27 6e 6f 62  WHERE login='nob
2f60: 6f 64 79 27 22 29 22 0a 20 20 65 63 68 6f 20 22  ody'")".  echo "
2f70: 61 6e 6f 6e 79 6d 6f 75 73 5f 63 61 70 73 20 24  anonymous_caps $
2f80: 28 66 6f 73 73 69 6c 20 73 71 6c 20 2d 52 20 22  (fossil sql -R "
2f90: 24 52 45 50 4f 22 20 22 53 45 4c 45 43 54 20 63  $REPO" "SELECT c
2fa0: 61 70 20 46 52 4f 4d 20 75 73 65 72 20 57 48 45  ap FROM user WHE
2fb0: 52 45 20 6c 6f 67 69 6e 3d 27 61 6e 6f 6e 79 6d  RE login='anonym
2fc0: 6f 75 73 27 22 29 22 0a 7d 20 3e 20 22 24 44 49  ous'")".} > "$DI
2fd0: 52 2f 66 61 63 74 73 2e 74 78 74 22 0a 0a 65 63  R/facts.txt"..ec
2fe0: 68 6f 20 22 72 65 61 64 79 3a 20 24 55 52 4c 20  ho "ready: $URL 
2ff0: 28 70 69 64 20 24 28 63 61 74 20 22 24 44 49 52  (pid $(cat "$DIR
3000: 2f 73 65 72 76 65 72 2e 70 69 64 22 29 29 3b 20  /server.pid")); 
3010: 70 61 73 73 77 6f 72 64 73 20 69 6e 20 24 44 49  passwords in $DI
3020: 52 2f 70 61 73 73 77 6f 72 64 73 2e 74 78 74 3b  R/passwords.txt;
3030: 20 66 61 63 74 73 20 69 6e 20 24 44 49 52 2f 66   facts in $DIR/f
3040: 61 63 74 73 2e 74 78 74 3b 20 73 74 6f 70 20 77  acts.txt; stop w
3050: 69 74 68 20 24 44 49 52 2f 73 74 6f 70 2e 73 68  ith $DIR/stop.sh
3060: 22 0a                                            ".