# -*- mode: org; fill-column: 100; -*-
# vim: set ai tw=100 
#+TITLE: fossil scripts
#+SUBTITLE: for source code maintenance and forum viewing on localhost
#+AUTHOR: brickviking
#+DATE: <2024-09-17 Tue 23:48>
#+TAGS: fossil libfossil fnc fsl fuel pikchr sqlite sqlitecloud forum bash tcl tk althttpd pikmojicon wapp
#+REVISION: 2.35
#+OPTIONS: _:nil
#+OPTIONS: toc:2
#+OPTIONS: num:nil
#+OPTIONS: ^:{}
#+STARTUP: showeverything
#+auto_tangle: t


* Introduction

This is a set of homebaked scripts to fetch fossil-related source code such as the fossil program or
sqlite3 database. It's currently implemented as bash code, with no real intention to rework it to
anything else. Hey, if it works, ... right?

#+BEGIN_EXPORT latex
\newpage
#+END_EXPORT

#+TOC: headlines 2

#+BEGIN_EXPORT latex
\newpage
#+END_EXPORT


:CONTENTS:

:END:
* Notes
:PROPERTIES:
:TOC:      :include all :depth 2
:END:

We should probably make sure the fossil directory and the sqlite directories exist before we try to
tangle code into them. Extracting source from here is as easy as `C-c C-v t`.

I have also added org-auto-tangle, so rendering this on platforms without that may cause one or two
issues.

Creating a pdf from this document is as easy as—in emacs, anyhow—`C-c C-e l l`, which will export
your file to a .tex file, then you can run pdflatex on this file to produce a pdf. It's not very
good looking at the moment.

* Licence

At the moment, this project falls under the MIT licence, as it's the most permissive of the 
available licences I wish to support.

#+BEGIN_SRC text -i :tangle LICENCE
MIT Licence

Copyright (c) 2024 Brickviking

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicence, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#+END_SRC

Hopefully this should sort things out. I'll change this over to SRC once I grab the first commit
from the new github project.

* TODO-things

** Relevancy of certain packages (a.k.a. how often are they updated)

Decide whether to keep fsl and fuel in, as they haven't been updated in quite some time (2018 for 
fuel, 2019 for fsl). The same holds for the flint project, which hasn't seen code updates since
2012 aside from the licencing rebind in 2013.

The libfossil-forum repo has had its contents merged with the parent repo, and now lives with the
libfossil repository instead of being called out separately (a la sqlite/fossil).

** Update fossilsource to do initial fetching

That's rather going to depend upon what use people have for the respective code. If you don't need
it for study/learning/testing, generally you won't have bothered with fossil anyhow. But if you
happen to be interested in the state of play for the sqlite3 project, then this is how you'd do
it. So…

*** Do we add a clone flag to fossilsource?

We either add one or we don't. If I do, then I have to make sure it's reasonably rock-solid. If I
don't add it, then you fetch them like normal (i.e. `fossil clone https://blahdeblah.kom
yourfossilname.fossil`), and make sure that fossilsource can update them later. At the moment the
concept of where I have the fossils is most definitely baked in, and this would need to change in
any event. That'll be a point for "Future Directions" too.

If we elect to fetch initial fossils, we run into the problem of having to *have* fossil so we can
clone all the remaining fossils that I have direct access to. That we have to leave up to the user
of this script, or indeed this repository. Thankfully it's easy to grab a copy, as they have it up
for grabs at =http://fossil-scm/fossil/uv/download/html=.

*** Do we then create a set of directories where each of the major categories are stored?

This partially depends upon if you cluster your fossils together, rather than giving each fossil its
own unique place to live separate from any of the other fossils. People have often created one place
to put all their fossils, or at most two and then used `fossil all ....` where you put in your
command, oblivious to where they may be stored. In the end, if the fossil has ended up in the
`${HOME}/.fossil` file (a list of repositories and their correlating checkouts) fossil will find it
just fine if you're just updating. I don't know if that also works for starting up a ui or server on
a particular fossil that doesn't live in the directory you're in at the moment. That might be
something I have to SIAS.

Another option is simply to ask the user where they wish to put that respective fossil. It's up to
them whether they collect all fossils into one place, or cluster them like I've done. This is more
likely to need at least some clue of what to do. This isn't exactly git or svn, after all.

**** List of possible variations

1) One single place, somewhere in ${HOME}.
  +  This would possibly be one of ~/fossils, ~/Repositories, ~/Documents/fossils or some variation
    on that. You can create a checkout anywhere on the filesystem, and just point it at the original
    fossil back home in fossils/, things will "just work™".
2) Scattergun approach, or a few categories (my personal current choice).
  +  I've subdivided ~/src/c/ into fossil-scm, sqlite, libfossil, tcl and tk. Some of the fossils
live in each of those subdirectories, for example, fossil-scm holds anything related to fossil
itself (fossil-code, fossil-forums, fossil book, etc),
 sqlite holds stuff relating to sqlite but not fossil or tcl/tk, libfossil holds its own
related fossils (libfossil and fsl/fnc), and of course tcl and tk have their own
individual subdirectories. It's the least organised and most baked-in approach for the moment.
3) Everything has its own directory, separate from anything else, i.e.:
  +  ${HOME}/src/fossil-scm/fossil.fossil,
  +  ${HOME}/src/fossil-book/fossil-book.fossil,
  +  ${HOME}/src/cvstrac/cvstrac.fossil and so on.
3a) or you could use the developer as a pathname component:
  + ${HOME}/src/drh/fossil-scm/fossil.fossil
  + ...

**** Quick note to self - can fossil open be used with a remote url?

Yes. Quoting from docs (fossil help open),
#+BEGIN_QUOTE
Usage: fossil open REPOSITORY ?VERSION? ?OPTIONS?

Open a new connection to the repository name REPOSITORY. ...
... snip ...
REPOSITORY can be the filename for a repository that already exists on the
local machine or it can be a URI for a remote repository.
#+END_QUOTE

This implies that we don't even have to store the fossils locally, also rendering the fossilsource
script entirely moot. Well. That's going back to the days of SVN and CVS, where we called home to a
central repository to sync data. Not that fossil _has_ to be configured that way, but it certainly
can be used that way. There's less local serverstate then, but does mean any changes you make are
to the canonical sites themselves, as opposed to a local copy that you have almost complete control
over.

Further testing indicates that running fossil open in this way actually runs a clone operation
first, leaving a fossil.fossil in the directory you chose when you ran fossil open. Hm. Maybe the
script isn't so superfluous after all. Huh.

** Update fossilsource to possibly update the checkouts too
This might require a little more futzing with fossil to dig out a unique checkout directory. 
 I could readily use =-s= as a param. It'd look a bit like the following excerpt:

#+BEGIN_EXAMPLE bash -i
bash$ fossilsource -s fossil  # This should update the checked-out fossil source tree
#+END_EXAMPLE

In the event where there is more than one checkout on a fossil repository, then perhaps the user
should be asked which checkout they want to update.

That could well look like this:
#+BEGIN_EXAMPLE bash -i
bash$ fossilsource -s fossil  # This should update the checked-out fossil source tree
Warning: fossil has multiple checkouts. Please select which checkout you
wish to update, or 0 to cancel the update:
0) cancel update
1) /home/user/src/c/fossil-scm/fossil
2) /opt/sourcecode/fossil-scm/ancient-fossil
#+END_EXAMPLE

The other problem where the user doesn't have a checkout will have to be addressed separately.
At the moment, I'd have to punt to the user, saying "There is no active checkout, cancelling update."
* REAMDE
  :PROPERTIES:
  :header-args: org :tangle README.org
  :TOC:      :include all :depth 3
  :END:

This is the initial cut at this file, which should parse perfectly well on Github, although it
might not be very well rendered by the fossil binary itself, as fossil doesn't care what an org
file is.

It's likely to see a lot of changes, as I refine things said in here.

#+BEGIN_SRC org -i
,* Introduction

This is a very simple wrapper script to update already-downloaded fossil files. Changes can be
made to the variables inside the script, which will help drive how fossil will update your
existing stored fossil files.

Fossil, at least the SCM program, is a way to store versions of files in a single place along
with relevant documentation, issue reporting, and even online chat, provided by one binary and 
one storage file (in a modified sqlite3 format) per project.

,* Variables and requirements

First off, you'll need to install the fossil binary. This is available at
=https://fossil-scm.org//home/uv/download.html=, grab whatever works best for you.
The next thing is a small or maybe large stash of fossils you wish to update on at least a
semi-regular basis. I've chosen fairly simple places where you can store these, but though these 
are my preferences, nothing's stopping you from changing the script to tell it where to find
your own fossil files so it can keep them up to date.

,* Very short list of Frequently Asked Questions

,** Why?

Why not? Often if you have fossil files you want to keep up to date, you'll be running fossil pull 
or some variant of that. This script attempts to update any existing fossils you've told it 
about and somewhat streamline the process. Simply issuing a command like 

,#+BEGIN_QUOTE
fossilsource sqlite
,#+END_QUOTE

will update the fossils for sqlite itself, the sqlite forums, and other projects fairly closely
related to sqlite itself.

,** What do you cover?

I cover updating fossil files once they've been fetched and installed onto your own machine.
This is as simple as choosing a place to put your several fossil files.

,** What don't you cover?

I don't cover initial fetching of the fossils; that's best done by yourself once you've chosen 
what subset of the existing fossilized programs you want to keep up to date. However, this is a
fairly complete list of the publically-available sources stored in fossil format that I know about.

I also don't cover keeping source up to date once you have run `fossil open ...`, again, that's
up to you. I don't educate you how to use fossil, that's already been addressed by the fossil-scm
website; that has some excellent documentation on the subject of keeping stuff up to date.

,** What will you add?

Given the last point, I /may/ add initial cloning of the fossils at some stage in the future once
I have answered several questions to my satisfaction; this includes things like where best to
store them (a personal decision in most cases), what to download, and when to keep them up to date.

,** When will <fill-in-blank-here> be updated?

That's up to the project maintainer. Some projects haven't been updated since 2009, some
are in nearly hourly flux. It's very dependent upon how often stuff changes in the source code
and how often the developers want to push out changes. I do have the `rarely` and `veryrarely`
categories for this reason; the stuff covered in `rarely` updates on perhaps a monthly basis
every three months, the stuff in `veryrarely` doesn't even change that often; some projects
are finished and won't see any further development. Some projects might have even moved on to
other homes without leaving a notice on the website.

,** What are the -forum fossils I see mentioned here such as sqlite-forum, fossil-forum?

Forums have discussions about the related source code (whether sqlite, fossil or other).
Some of these are split off from the main project and stored into their own fossil. If you want
to report a problem at the project's forums, it's best to go to the parent forum instead of trying
to reply at the downloaded forum fossils. These fossils are merely a way to get the discussions
locally so you can read them on your local machine without taking up extra bandwidth until you
actually need to report a problem or make other comments.

,** What if I don't want all the fossils, but just some of them?

You can edit what fossils you want to keep updated by looking at the respective -all functions,
for example sqlite-all (or simply sqlite) covers all the sqlite-related fossils (assuming you have
them), the tcl category includes tcl, tk, and tips as well as the wapp project. If you want to trim
back the number of projects in each of these categories (perhaps to leave out the -forum fossils
or the less-updated fossils) then feel free to edit the file.

These projects should all be capable of being individually updated in the same manner as you now
do with fossil, but if you have tailored this script to your needs, you will no longer need to
`cd place; fossil pull` or `fossil pull <project-name>` to see changes, especially if you have
more than one or two fossil projects you like to keep up to date with.

,** How do I tailor this script to my needs, considering you'll be making changes too?

You open it up in an editor, and you compare it with the changes that I've made, like any
responsible developer will do for themselves.

,** What's this fossil.org document I see?

It's the source file for all the other relevant bash scripts I have here, such as the fossilsource
program itself, and fossilserve. The rest (the *.sh files) serve as examples of how I used to do
things before I dramatically simplified them into simply fossilserve. As well, I've included this
README so I only have one place to go to edit things. All of this is stored in org format, and is
best used with a recent-ish copy of Emacs from the past decade or so, although Emacsen as far back
as Emacs-23 will probably open it fine, given the right installation.
#+END_SRC

* Changelog

+ 1.0 Initial fossil.sh created, as version 0.0.1, pretty much just fetched fossil-scm source
      code.
  + 1.1 expanded to fossilsource.sh, includes forums, added fossil book a while later.
  + 1.2 included fossilweb.sh, initially starts up servers to access fossil source and forums.
  + 1.3-1.4 changes.
  + 1.5 added sqlite source code fetching and forums to fossilsource.sh.
  + 1.6 added sqlite web server to fossilweb.sh.
  +  1.7 split off sqliteweb stuff into its own script (sqliteweb.sh).
  +  2.0 expanded fossilsource to create functions for fetching individual components.
  +  2.1 added docsrc (sqlite) to fossilsource.sh and sqliteweb.sh.
  +  2.2 added sqllogictests to fossilsource.sh and sqliteweb.sh.
  +  2.3 Initial cut of a fossil.org containing document, now that these scripts are getting big
    enough.
  +  2.4 Added org-auto-tangle, prodded help switch into fossilsource.sh and extra switches into
    tclweb.sh.
  +  2.5 Added libfossil.
  +  2.6 Corrected some mistakes.
  +  2.7 Added wasm to fossilsource, changed things around a wee bit.
  +  2.8 Also added althttpd to sqliteweb, tidied up case switch on $@.
  +  2.9 Added pikchr to fossilsource, putting it into rarely. Tweaked REVISION in header.
  +  2.10 Added fsl to fossilsource, made note of its "rarely" status in fossilsource.
     +  Also added fuel - Dead. Dodo. Won't compile here. Weirdly enough, I seem to have got it
        compiled at some stage, though I've no idea how.
  +  2.11 Tidying up fnc, moved fnc from rarely into libfossil section.
  +  2.12 Added a new function to cover cloudsqlite.
  +  2.13 Forgot to tack on some lines for fnc/fsl et al, mainly the ====done stuff.
  +  2.14 Added pikmojicon, rearranged locations as pikchr etc are libfossil, not fossil-scm.
  +  2.15 Preliminary stubs put in for fossilmake/fossildoc.
  +  2.16 Rearranged things a little, moved althttpd back from rarely.
  +  2.17 Added some stuff like fresh, fuel, inskinerator and flint.
  +  2.18 Expanded on Adding Clone Flag section and following section.
  +  2.19 Shifted help strings for althttpd and wasm back to sqlite/ and added wapp.
  +  2.20 Added wapp to rarely after cursory examination.
  +  2.21 Added REAMDE. Points if you know the reference.
  +  2.22 Added a LICENCE.
  +  2.23 Tweaked help, correcting the references to chisel.
  +  2.24 Silenced pushd/popd.
  +  2.25 Adding "common" to cover {fossil,sqlite}-{code,forum} and tcl/tk.
  +  2.26 Fixes to above for some mistakes with cd.
  +  2.27 Finally removed libfossil-forum, as forum has been merged into libfossil repo.
  +  2.28 Reworked hashbang for portability reasons. Added version and function.
  +  2.29 Shortened up the $0, making it into a var and shortening it.
  +  2.30 Reworked the help display, removed redundancies.
  +  2.31 Added a fossilcommit utility function.
  +  2.32 Added comment to fossilmake's installFossil about privileges.
  +  2.33 Added sync commandline param. Only works with fossils you can push to.
  +  2.34 Added fossilsource repo.
* Source files

These files are responsible for updating source fossil files, or starting up the internal content
web servers related to fossil, sqlite, tcl and tk and some other projects. The main ones you want to
look at are fossilsource and fossilserve, as the others are only there from earlier stages of the
project.

I've also added a utility fossilcommit function, as I (strangely enough) have repositories
under both git and fossil management. It makes for an interesting time when I'm running commits for
both, as I have to commit first (to git) then to fossil.

** fossils covered to date
At the moment, I have the following fossils installed in my system, with one or two of them being
pushed to git repositories in my gitea instance.
*** Fossil-scm and related
  +  fossil-scm, fossil-forum, fossil-book

** fossilsource
This fetches all the code that's currently supplied as .fossil files from sqlite.org, including the
sqlite-related files. Additionally, tcl and tk are available too. As of November 2022, that's the
following files stored in ${HOME}/src/c/fossil-scm:
 + fossil-scm source (fossil.fossil)
 + fossil-scm fossil (fossilforum.fossil)
 + fossil-scm book (fossil-book.fossil)

Sqlite files are stored in ${HOME}/src/c/sqlite/:
 + Sqlite source: (sqlite.fossil)
 + Sqlite forum: (sqliteforum.fossil)
 + Sqlite document collation source (docsrc.fossil)
 + The althttpd web server (althttpd)
 + Logic tests for sqlite (sqllogictest.fossil)
 + Wasm/JS documents (wasm.fossil)

Tcl and Tk files are stored in ${HOME}/src/c/tcl and tk respectively.

libfossil is in ${HOME}/src/c/libfossil, which contains the sourcecode and fnc fossils.  The code
is currently in the process of being converted to parse parameters. The forums for libfossil were
cut over at the end of June 2024, so people now go to the libfossil page to access the forums.

As of March 2023, several outlier projects were added, such as fsl, pikchr, cvstrac (direct fossil
predecessor), wapp and tips (tcl/tk project). I also added the fuel project, but it hasn't been
updated since 2018 and doesn't want to compile on my system, though I don't know why. It's dead, Jim.

EDIT: I got a copy to compile and run (it at least showed me a GUI), though I can't quite remember
how. As a result, I'll stick a stanza in for updating it from fossilsource.

In April 2023, fnc was added in, though it had been on my system a while. Poor thing.

February 2024 sees inskinerator added, there's been several other internal changes too.
March 2024 sees the flint project added (software behind the chisel hosting site).
July 2024 sees a REAMDE. Finally. It's about time. The reason is because if I host this on github,
then I'll need a file that renders in Github's website to introduce the fossilsource project.

Future plans: 
 + include a verbose switch.
 + add other switch processing.
 + (perhaps) add initial cloning.
 + expand to include git projects such as emacs and git itself. There's already a scmsource project
     for fetching source code for the other SCMs such as svn/hg.
 + add a new category "exceptionally rarely", for projects not updated in years (flint, fuel?). 
This is covered somewhat by the veryrarely category.

======== Beginning of fossilsource ========

#+ATTR_LATEX: :options frame=single,backgroundcolor=\color{lightgray}
#+BEGIN_SRC bash -i :tangle fossilsource :tangle-mode (identity #o755)
#!/usr/bin/env bash
# v0.1 iterate through my fossils.
# v0.2 Add in some git projects.
# v0.3 Added in some more sqlite-related items.
# v0.3a TODO: split this up like fossilweb.sh.
# v0.4 still working on new fossilstuff function - not live yet.
# v0.5 newfossilstuff got the axe. I've got to build a function to
#      cycle through $1.
# v0.6 I added tips to Tcl (Tcl Improvement Proposals).
# v0.6a Added extra line between downloads.
# v0.7 add libfossil, correct mistakes.
# v0.8 create a rarely section for docsrc, book and others.
# v0.9 Added sqlite-wasm to the rarely section, also added althttpd.
# v0.10 Moved sqlite-wasm back out of rarely, due to activity.
# v0.11 Added pikchr into rarely.
# v0.12 Adding params to fossil.
# v0.13 Changed out MYHOME and other vars to FOSHOME etc.
# v0.14 Added sqlite-cloudsqlite, tidied up help.
# v0.15 Put in fnc, should have been in there a while. Poor thing.
# v0.16 Added in pikmojicon, pretty rarely used.
# v0.17 Added in inskinerator, makes skins for fossil.
# v0.18 Made note about veryrarely (created for chisel project files and the like).
# v0.19 Shifted help strings for althttpd and wasm back to sqlite/ and added wapp to tcl.
# v0.20 Added wapp to rarely after cursory examination.
# v0.21 Added REAMDE, no changes to this source as a result.
# v0.22 Added LICENCE, no changes to this source as a result.
# v0.23 Tweaked help, correcting the references to chisel.
# v0.24 Silenced pushd/popd.
# v0.25 Adding "common" to cover {fossil,sqlite}-{code,forum} and tcl/tk.
# v0.26 Fixes to above for some mistakes with cd.
# v0.27 Finally removed libfossil-forum, as forum has been merged into libfossil repo.
# v0.28 Reworked hashbang for portability reasons. Added version and function.
# v0.29 Shortened up the $0, making it into a var and shortening it.
# v0.30 Reworked the help display, removed redundancies.
# v0.31 Added a fossilcommit utility function. (No functional changes to fossilsource)
# v0.32 Added sync command. Only works for fossils you can push to.
# v0.33 Added fossilsource repo.
# v0.34 Added jimtcl. This isn't always kept up to the same place as the git repo.
# v0.35 Added bash completion script. No functional change to fossilsource itself.
FOSVERSION=0.35

########
# Notes #
#########
# This really needs to be run from the source directory first.
# fossil has source code, forums, pikchr and a book.
# sqlite has source code, forums, docsrc, althttpd, wasm and a testing harness.
# tcl and tk each have source code, and tcl has proposals (tcl-tip).
# Cannot get TH3 source without a commercial licence, so can't run tests for docsrc.
# leave libfossil out of the main loop, but call them specifically, just like fossil-book, pikchr, sqlite-wasm and sqlite-testing.
FOSHOME="${HOME}/src/c/"

# Doesn't fit, but it's short.
ME="$(basename ${0})"
# Obligatory help function
function dohelp() { # needed renaming, as "help" already exists somewhere else
  echo "Welcome to the $ME help page for version ${FOSVERSION}."
  echo "${ME} {all}: fetches all fossil, all sqlite, all tcl except rarely/veryrarely."
  echo "   -h|help|--help: this help page."
  echo "   -v|version|--version: provides version of this program."
  echo "   common: fetches {fossil,sqlite}-{code,forum}, althttpd and tcl/tk."
  echo "It leaves out things in rarely/veryrarely,"
  echo "plus a few less-updated parts of sqlite/fossil-space"
  echo "### fossil stuff."
  echo "   fossil-[code|forum|book]: fetches named section."
  echo "   fossil: fetches code and forum."
  echo "### wanderinghorse stuff."
  echo "   libfossil{-all}: fetches libfossil (libfossil-code) and fnc."
  echo "   [fsl|fnc|pikchr|pikmojicon]: fetches fsl, pikchr, pikmojicon or fnc."
  echo "### sqlite stuff."
  echo "   sqlite: fetches sqlite fossils (code, forum, docsrc, wasm, althttpd)."
  echo "   sqlite-{code|forum|docsrc|tests|althttpd|wasm|cloud}, fetches:"
  echo "       sqlite code, forum, docsrc, wasm, althttpd or test scripts."
  echo "   althttpd: fetches althttpd code."
  echo "   docsrc: fetches sqlite-docsrc code."
  echo "   wasm: fetches wasm-related code."
  echo "### tcl/tk."
  echo "    tcl-code: fetches code."
  echo "    tcl-tip: fetches proposals."
  echo "    tk-code: fetches code."
  echo "### jimtcl."
  echo "    jimtcl: fetches jimtcl fossil. Not always up to date."
  echo "### tangentsoft projects."
  echo "    inskin: fetches inskinerator code."
  echo "    tangentsoft-fossil: fetches local fossil for tangentsoft."
  echo "### Flying-brick project."
  echo "    fossilsource: fetches this codebase for this script"
  echo "### chisel project."
  echo "    flint: fetches the flint code for chisel server."
  echo "=== Rarely-updated stuff."
  echo "    rarely: updates almost all the stuff not touched by [{fossil|sqlite|libfossil}-]all."
  echo "Currently, this includes the following fossil, lifossil and sqlite projects:"
  echo "      fossil-book, pikchr, pikmojicon, fsl, sqlite-tests, sqlite-cloud, and cwal."
  echo "Also includes tangentsoft's inskinerator and james' flint."
  echo "This list will need modifying on occasion."
  echo "=== Very rarely updated stuff (less than yearly)."
  echo "   veryrarely: includes the flint, fuel and fsl projects."
  echo "======= TODO."
  echo "   remove inskinerator from rarely if project updates regularly."
  echo "For more projects (that vary in update frequency), check the chisel"
  echo "hosting site at chiselapp.com."
# Need a section in here for pull
  exit 0
}

function doversion() {
  echo "$ME version: ${FOSVERSION}"
  # This should really check we even _have_ a fossil first.
  echo "fossil version: $(fossil version)"
  exit 0
}
##### fossil-scm and related stuff
function fossil-code() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} fossil.fossil
  echo "==== fossil-code...done ==="
}

function fossil-forum() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} fossilforum.fossil
  echo "==== fossil-forum...done ==="
}

# Rarely updated
function fossil-book() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} fossil-book.fossil
  echo "==== fossil-book...done ==="
}

function fossil-all() { # Excludes fossil-book and pikchr
  cd fossil-scm # Yes, the directory name has -scm appended
  t=fossil
  ${t}-code
  sleep 5
  ${t}-forum
  cd ..
}

###### wanderinghorse items
function libfossil-code() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} libfossil.fossil
  echo "==== libfossil...done ==="
}

# Commented out for now (removal soon), as forums have been merged to master
# https://fossil.wanderinghorse.net/r/libfossil/forumpost/c58421800f
# function libfossil-forum {
#  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} libfossil-forum.fossil
#  echo "==== libfossil-forum...done ==="
# }

# ncurses client for fossil
function fnc {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} fnc.fossil
  echo "==== fnc...done ==="
}

# Rarely updated
function pikchr() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} pikchr.fossil
  echo "==== pikchr...done ===="
}

# Rarely updated
function pikmojicon() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} pikmojicon.fossil
  echo "==== pikmojicon...done ===="
}

function libfossil-all {
  cd libfossil
  libfossil-code
#  libfossil-forum
  fnc
  cd -
}

# Scripting engine without a language. Not sure where to put this.
function cwal {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} cwal.fossil
  echo "==== cwal...done ==="
}

# cson - old, but seemingly still in use
function cson {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} cson.fossil
  echo "==== cson...done ==="
}

###### end of wanderinghorse stuff

#### Some non-fossil-project (but fossil-related) ####
# Shell-based front end to fossil, append to rarely. Hasn't been updated since 2019.
function fsl {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} fsl.fossil
  echo "==== fsl...done ==="
}

# This is spectacularly unlikely to update further, but is here for completeness' sake
function fuel {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} fossil-fuel.fossil
  echo "==== fuel...done ==="
}

function flint {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} flint.fossil
  echo "==== flint...done ==="
}

function fresh {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} Fresh.fossil
  echo "==== fresh...done ==="
}

function inskin { # Shortened from Inskinerator
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} inskinerator.fossil
  echo "==== Inskinerator...done ==="
}

function tangentsoft-fossil() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} tangentsoft.fossil
}

# And of course, my own pet project, fossilsource. Needs renaming so I don't
# trip over my own bash script.
function fossilsource-code() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} fossil-bvscripts.fossil
  echo "==== fossilsource...done ==="
}

##### sqlite-hosted or sqlite-related projects
function sqlite-code() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} sqlite.fossil
  echo "==== sqlite-code...done ==="
}

function sqlite-forum() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} sqliteforum.fossil
  echo "==== sqlite-forum...done ==="
}

function sqlite-wasm() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} wasm.fossil
  echo "==== sqlite-wasm...done ==="
}

function sqlite-docsrc() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} docsrc.fossil
  echo "==== sqlite-docsrc...done ==="
}

function sqlite-althttpd() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} althttpd.fossil
  echo "==== sqlite-althttpd...done ==="
}

### These fossils are rarely updated. ###
function sqlite-tests() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} sqllogictest.fossil
  echo "==== sqlite-tests...done ==="
}

function sqlite-cloud() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} cloudsqlite.fossil
  echo "==== sqlite-cloudsqlite...done ==="
}

# Does everything not in "rarely" section
function sqlite-all() {
  t="sqlite"
  cd ${t}
  ${t}-code
  sleep 5
  ${t}-forum
  sleep 5
  ${t}-docsrc
  sleep 5
  ${t}-wasm
  sleep 5
  ${t}-althttpd # shifted from rarely()
#  ${t}-tests # shifted to rarely()
#  ${t}-cloud # shifted to rarely()
  unset $t
  cd .. # gets us back to ${MYHOME}
}

# Updates tcl sourcecode
function tcl-code() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} tcl.fossil
  echo "==== tcl-code...done ==="
}

# Updates tcl TIP database
function tcl-tips() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} tips.fossil
  echo "==== tcl-tips...done ==="
}

function wapp() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} wapp.fossil
  echo "==== wapp...done ==="
}

# Updates tk sourcecode
function tk-code() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} tk.fossil
  echo "==== tk code...done ==="
}

# Updates both tcl and tk sources
function tcl-all() {
  cd tcl
  tcl-code
  sleep 5
  tcl-tips   # TCL Improvement Proposals, rarely updated
  sleep 5
  wapp
  sleep 5
  cd ../tk
  tk-code
  cd .. # gets us back to ${MYHOME}
}

# Updates jimtcl's fossil
function jimtcl() {
  fossil ${FOSCMD} ${FOSCMDPARAMS[*]} jimtcl.fossil
  echo "==== jimtcl code...done ==="
}

# these don't get updated very often, if at all
function rarely() {
# fossil stuff
  cd fossil-scm
  fossil-book
# sqlite stuff
  cd ../sqlite
  sqlite-tests
  sqlite-cloud
# wanderinghorse - a.k.a. libfossil
  cd ../libfossil
  cwal
  pikchr
  # fsl and pikmojicon moved to veryrarely
# other stuff
  cd ../Fresh
  fresh
  cd ..
# tangentsoft (not tangentsoft-fossil)
  cd ${HOME}/src/perl/hosts/tangentsoft
  inskin
  cd -  # should land me back in /h/v/src/c
}

function veryrarely() { # for stuff that hasn't updated in years
  cd fossil-scm
  fuel # really really rare chance to update
  cd -
  cd libfossil
  fsl
  pikmojicon
  cd -
  cd ${HOME}/src/php/hosts/james
  flint
  cd -
}

function tangentsoft-all() {
  # only one entry at the moment
  cd ${HOME}/src/perl/hosts/tangentsoft
  inskin
  cd - # should land me back in /h/v/src/c
  cd ${HOME}/src/c/hosts/tangentsoft/
  tangentsoft-fossil
  cd -
}

# Meant to be like all, but misses out sqlite docs, tips and other stuff
function common() {
  # First fossil
  fossil-all # this changes dir at end of fossil-all
  # then sqlite - can't use sqlite-all as it includes too much
  t="sqlite"
  cd ${t}
  ${t}-code
  sleep 5
  ${t}-forum
  sleep 5
  ${t}-althttpd
  sleep 5
  # now tcl/tk
  cd ../tcl
  tcl-code
  sleep 5
  cd ../tk
  tk-code
  cd .. # gets us back to ${MYHOME}
}

function all() { # These each have a cd in them
# Note: does not include fsl
  fossil-all # code, forum, not book
  sleep 5
  sqlite-all # code, forum, althttpd, not tests
  sleep 5
  tcl-all    # code (tcl/tk), TCL Improvement Proposals (tip)
  sleep 5
  # tangentsoft-all has two paths, so we're not using it here
  cd ${HOME}/src/c/hosts/tangentsoft/
  tangentsoft-fossil # doesn't include inskinerator (under rarely)
  cd -
  sleep 5
  libfossil-all # added this as it doesn't make much sense to leave it out
  }
# Takes path arg

pushd "${FOSHOME}" >/dev/null
# Let's add something to FOSCMD to make the operation specific
# the caseloop below processes in order. -u needs to be first if
# we want to sync unversioned artifacts
declare FOSCMDPARAMS
# Was here for getting everything and breadcrumbing where I was
# FOSCMDPARAMS=("-v" "--verily" "-R")
# Strip it back a bit, I think.
FOSCMDPARAMS=("-R")

FOSCMD="pull" # default value unless it gets changed by -u
if [ ${#*} -lt 1 ]; then # I want it all
  all # sleep is built in between stages
else #iterate, chuck it in if keyword isn't recognised.
  for t in ${*}; do
    case "${t}" in
    "-u"|"--unversioned")
      # sync can't push without user perms on remote, but can still pull unversioned artifacts
      FOSCMDPARAMS=("-u" "-v" "--verily" "-R")
      FOSCMD="sync"
#      dohelp
    ;;
    "-s"|"--sync")
    # Sync needs remote perms - only works for projects supporting it
      FOSCMD="sync"
    ;;
    "help"|"-h"|"--help")
      dohelp # exits
    ;;
    "-v"|"version"|"--version") doversion  # exits
    ;;
# Each one of these handles path changing for itself
    "rarely"|"veryrarely"|"all"|"common")
      "${t}"
    ;;
    "fossil"|"sqlite"|"tcl"|"libfossil")
      "${t}"-all
    ;;
# All fossil-related stuff
    "fossil-forum"|"fossil-code"|"fossil-book"|"fuel")
      cd fossil-scm
      "${t}" # calls the function directly. I'll have to see if this works.
      cd ..
    ;;
    "book")
      cd fossil-scm
      fossil-book
      cd -
    ;;

# Some non-fossil stuff (hosted in a fossil)
    "fresh"|"Fresh")
      cd Fresh
      fresh
      cd ..
    ;;
# the host software for chisel (very rarely updated)
    "flint")
      cd ${HOME}/src/php/hosts/james
      flint
      cd -
    ;;
# and tangentsoft
    "inskin"|"Inskin"|"inskinerator"|"Inskinerator")
      cd ${HOME}/src/perl/hosts/tangentsoft
      inskin
      cd -
    ;;
    "tangentsoft-fossil")
      cd ${HOME}/src/c/hosts/tangentsoft
      tangentsoft-fossil
      cd -
    ;;
    "tangentsoft-all") 
      cd ${HOME}/src/c/hosts/tangentsoft
      tangentsoft-fossil
      cd -
    ;;
# My own fossilsource - I'll use chiselapp
    "fossilsource")
      cd ${HOME}/src/bash
      fossilsource-code
    ;;
# All wanderinghorse stuff
    "libfossil-all")
      libfossil-all # should do libfossil-code and fnc but not libfossil-forum
    ;;
    "libfossil-code"|"cwal"|"cson"|"fsl"|"fnc"|"pikchr"|"pikmojicon")
      cd libfossil
      ${t} # Seems a bit redundant to make this a full function call
      cd ..
    ;;
# All sqlite-related stuff
    "sqlite-code"|"sqlite-forum"|"sqlite-docsrc"|"sqlite-tests"|"sqlite-althttpd"|"sqlite-wasm")
      cd sqlite
      "${t}"
      cd -
    ;;
    "docsrc") # this fills in the hole
      cd sqlite
      sqlite-"${t}"
      cd -
    ;;
    "althttpd"|"httpd") # whoops, is this duplicated with the above section?
      cd sqlite
      sqlite-althttpd
      cd ..
    ;;
    "docsrc")
      cd sqlite
      sqlite-docsrc
      cd ..
    ;;
    "wasm")
      cd sqlite
      sqlite-wasm
      cd ..
    ;;
    "cloud"|"cloudsqlite"|"sqlite-cloud")
      cd sqlite
      sqlite-cloud
      cd ..
    ;;
# All tcl/tk-related stuff
    "tcl"|"tcl-all")
      tcl-all
    ;;
    "tcl-code"|"tcl-tips"|"wapp")
      cd tcl
      "${t}"
      cd -
    ;;
    "tk")
      cd "${t}"
      "${t}"-code  # Only the code at the moment.
      cd -
    ;;
    "tk-code")
      cd tk; pwd
      "${t}"
      cd -
    ;;
    "jimtcl")
    cd ${HOME}/src/tcl/hosts/msteveb/
    "${t}"
    cd -
    ;;
    esac # end of case ${t}
  done
fi
popd >/dev/null


#+END_SRC

======== End of fossilsource ========

** Fossilsource bash-completion
This is the bash-complete script for the fossilsource command. Unfortunately it's got the same
name as its parent script, but I'm not entirely sure it needs to be.

======== Beginning of fossilsource ========
#+BEGIN_SRC bash -i :tangle fossilsource-bashcomplete :tangle-mode (identity #o755)
_fossilsource_module() {
    local cur prev OPTS

    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    OPTS="help
    -h
    --help
    -s
    --sync
    -u
    --unversioned
    all
    althttpd
    common
    cson
    cwal
    flint
    fnc
    fossil
    fossil-code
    fossil-forum
    fossil-book
    fossilsource
    fsl
    inskin
    libfossil
    libfossil-all
    libfossil-code
    libfossil-forum
    pikchr
    pikmojicon
    rarely
    sqlite
    sqlite-code
    sqlite-forum
    sqlite-docsrc
    sqlite-tests
    sqlite-althttpd
    sqlite-wasm
    sqlite-cloud
    tangentsoft-fossil
    tcl-code
    tcl-tip
    tk-code
    veryrarely
    wasm"
    COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
    return 0
}

complete -F _fossilsource_module fossilsource

#+END_SRC
======== End of fossilsource ========

** fossilserve

This effectively replaces the twelve ports taken up by the individual servers and replaces them with
a front listing, which is probably how the fossil creators intend it to be used. It also replaces
fossilweb.sh, sqliteweb.sh and tclweb.sh, but those are left in this file to show a road marker of
where I got to before creating the master fossil server. It's also a heck of a lot shorter than any
of the other individual shell scripts.

======== Beginning of fossilserve ========

#+BEGIN_SRC bash :tangle fossilserve :tangle-mode (identity #o755)
#!/bin/bash
# v0.1 Initial release
# we don't exactly need a home, just a straight up fossil invoke
# from the / we can invoke a server (in a new tab) for every fossil we have
#
# TODO: we don't test for already-running fossil. -test is now ancient.
# v0.2 Changed default home for tangled script

if [[ "$1" == "-test" ]]; then
  fossil-test server --port 8100 / &
else # either there's no $1 or $1 holds something that's not -test
  fossil server --port 8100 / &
fi
#+END_SRC

======== End of fossilserve ========

** fossilcommit
#+BEGIN_SRC bash -i :tangle fossilcommit :tangle-mode (identity #o755)
#!/usr/bin/env bash
#
# v0.1 Initial copy from .bash_history.
#
# Attempts to make a fossil commit with the last git message.
# I got sick of looking this up, so I turned it into its own command.
#
# This needs a .fslckout and a .git in the project's root dir to work properly.
# It also needs a checked-out git tree and fossil. This takes no args.
#
# Only bug so far is that it doesn't check that fossil's actually out of  sync.

fossil commit -m "$(git --no-pager log -n 1 | sed -e 's/^    //g' | tail -n +5)"

#+END_SRC
** fossilweb.sh

This has been replaced with a front end on 8100 that points to every fossil on my system.

This starts up the web servers related to fossil code, forums and the fossil book. It—along with
tcl-web/tkweb and sqliteweb—have all been condensed into one fossil-driven front end. The only real
liability is that I may or may not be able to run multiple tabs each with its own server. I'll have
to try that. fossil tends to spawn its subprocesses in a separate tab each time.

======== Beginning of fossilweb.sh (superceded) ========

#+BEGIN_SRC bash :tangle fossilweb.sh :tangle-mode (identity #o755)
#!/bin/bash
# v0.0.1 FossilWeb - brings up all fossil servers on 8100/8110/8120
# v0.1.0 Starts up what we choose
# v0.1.2 Removed book from "all" as this very rarely gets updated
# v0.1.3 TODO: Add code to check for already running servers, dump if so
# v0.1.4 Changed default home for tangled script

# TODO: we need to bring this back up to date. It's been a really long
#       time since July 2022
# Forget it, server mode works far better.
FOSSILHOME="${HOME}/src/c/fossil-scm"

# First the source code
code() {
  echo -ne "Starting fossil code server: "
  fossil server --port 8100 fossil.fossil &
}

# Now the forums
forum() {
  echo -ne "Starting fossil forum server: "
  fossil server --port 8110 fossilforum.fossil &
}

# and last, the book files. need ui for this
book() {
  echo -ne "Starting fossil book server: "
  fossil server --port 8120 fossil-book.fossil &
}

# Everything except book. Seems a bit redundant.
all() {
  code
  sleep 5
  forum
  sleep 5
  # book # doesn't really need this, so we'll call it specifically
}

# Better provide help, can't call it help because of the builtin
dohelp() {
  echo "$0: help screen. Starts fossil server from files on commandline"
  echo "$0 [all|code|forum|book] ..."
  exit 0
}

# Change to correct directory
pushd "${FOSSILHOME}"

if [ ${#*} -lt 1 ]; then # I want it all
  all # sleep is built in between stages
else #iterate, chuck it in if keyword isn't recognised.
  for t in ${*}; do
    case $t in "-h"|"--help") dohelp ;;
      "code") code ;;
      "forum") forum ;;
      "book") book ;;
      "all") all ;; # doesn't include book, call that separately
      *) dohelp ;; # This exits, no matter what the state of other ${*}
		esac
		sleep 5 # Allow each server to start up before anything else happens
	done
fi

# We all done sah.
popd

#+END_SRC

======== End of fossilweb.sh ========

** sqliteweb.sh

This has been replaced with a front end on 8100 that points to every fossil on my system.

This starts up the web servers related to sqlite code, forums, docsrc, wasm/js, System.Data.SQLite
project and testing code. As yet, sqlite.org have not released TH3 as free open source code, so I'm
unable to completely fulfil the "docsrc" requirements. TH3 is most definitely commercial, and
probably contributes to helping with their running costs, alongside the encryption and compression
source that they can supply.

======== Beginning of sqliteweb.sh (superceded) ========

#+BEGIN_SRC bash :tangle sqliteweb.sh :tangle-mode (identity #o755)
#!/bin/bash
# v0.0.1 FossilWeb - brings up all fossil servers on 8100/8110/8120.
# v0.0.2 Sqlite fossil servers adjusted to start on 8200/10/20/30.
# v0.1.0 Starts up what we choose.
# v0.1.2 Removed book from "all" as this very rarely gets updated.
# v0.1.3 TODO: Add code to check for already running servers, dump if so.
# v0.1.4 name change about three versions ago to suit sqlite instead of fossil.
# v0.1.5 Added, then removed TCL Improvement Proposals (TIP), shifted to tclweb.sh
# v0.1.6 Added wasm/js server. This should by rights not be in all,
#        but I'll leave it there for now, as there's recent traffic.
# v0.1.7 TODO: Added althttpd fossil and streamlined the case switch.
# v0.1.8 Changed default home for tangled script.
# v0.1.9 Added System.Data.SQLite project.

SQLITEHOME="${HOME}/src/c/sqlite"

# First the source code
code() {
  echo -ne "Starting SQlite3 code fossil server: "
  fossil server --port 8200 sqlite.fossil &
}

# Now the forums
forum() {
  echo -ne "Starting SQlite3 forum fossil server: "
  fossil server --port 8210 sqliteforum.fossil &
}

# and the doc source files
docsrc() {
  echo -ne "Starting SQlite3 docsrc fossil server: "
  fossil server --port 8220 docsrc.fossil &
}

# and the SQL Logic Tests
tests() {
  echo -ne "Starting SQlite3 test code fossil server: "
  fossil server --port 8230 sqllogictest.fossil &
}

wasm() {
  echo -ne "Starting SQlite3 wasm/JS fossil server: "
  fossil server --port 8240 wasm.fossil &
}

althttpd() {
  echo -ne "Starting SQlite3 althttpd.fossil server: "
  fossil server --port 8250 althttpd.fossil &
}

sds() {
  echo -ne "Starting SQLite System.Data.Sqlite server: "
  fossil server --port 8260 sds.fossil &
}

# Everything
all() {
  code
  sleep 5
  forum
  sleep 5
  docsrc
  sleep 5
  tests
  sleep 5
  wasm
  sleep 5
  althttpd
  sleep 5
  sds
  sleep 5
}

# Better provide help, can't call it help because of the builtin
dohelp() {
  echo "$0: help screen. Starts fossil server from files on commandline"
  echo "$0 [all|code|forum|docsrc|test|wasm|althttpd] ..."
  echo "all: launch everything below, spaced out by five seconds"
  echo "code: sqlite source code"
  echo "forum: sqlite forums - read-only"
  echo "docsrc: source for generating sqlite document tree"
  echo "tests: sql logic test harness"
  echo "wasm: sqlite3 wasm/js code reference"
  echo "althttpd: sqlite3 althttpd reference"
  echo "sds: System.Data.SQLite instance"
  exit 0
}

# Change to correct directory
pushd "${SQLITEHOME}"

if [ ${#*} -lt 1 ]; then # I want it all
  all # sleep is built in between stages
else #iterate, chuck it in if keyword isn't recognised.
  for t in ${*}; do
    case $t in "-h"|"--help") dohelp ;;
      "code"|"forum"|"docsrc"|"tests"|"wasm"|"althttpd"|"sds") "${t}" ;;
      "all") all ;; # Streamlined a bit
      *) dohelp ;; # This exits, no matter what the state of other ${*}
    esac
    sleep 5 # Allow each server to start up before anything else happens
  done
fi

# We all done sah.
popd

#+END_SRC

======== End of sqliteweb.sh ========

** tclweb.sh

And the third member of the group, runs servers for the tcl/tk source trees. This has been replaced
with a front end on port 8100 that points to every fossil on my system.

======== Beginning of tclweb.sh ========

#+BEGIN_SRC bash :tangle tclweb.sh :tangle-mode (identity #o755)
#!/bin/bash
# v0.0.1 FossilWeb - brings up all fossil servers on 8100/8110/8120
# v0.1.0 Starts up what we choose
# v0.1.2 Removed book from "all" as this very rarely gets updated
# v0.1.3 TODO: Add code to check for already running servers, dump if so
# v0.1.4 name change about three versions ago to suit tcl instead of fossil
# v0.1.5 made notes about starting on ports 8300/10/20
# v0.1.6 Changed default home for tangled script

TCLHOME="${HOME}/src/c/tcl"
TKHOME="${HOME}/src/c/tk"

# First the source code
tcl-code() {
  cd "${TCLHOME}"
  echo -ne "Starting Tcl fossil server: "
  fossil server --port 8300 tcl.fossil &
  cd -
}

tcl-tips() {
  cd "${TCLHOME}"
  echo -ne "Starting Tcl Improvement Proposals fossil server: "
  fossil server --port 8310 tips.fossil &
  cd -
}

tk-code() {
  cd "${TKHOME}"
  echo -ne "Starting Tk fossil server: "
  fossil server --port 8320 tk.fossil &
  cd -
}

# Everything
all() {
  tcl-code
  sleep 5
  tcl-tips
  sleep 5
  tk-code
  sleep 5
}

# Better provide help, can't call it help because of the builtin
dohelp() {
	echo "$0: help screen. Starts fossil server for Tcl code from files on commandline"
  echo "$0 [all|tcl-code|tcl-tip|tk-code]"
  echo "all: launch all servers, spaced out by five seconds"
  echo "tcl-code: tcl source code"
  echo "tcl-tips: Tcl Improvement Proposals"
  echo "tk-code: tk source code"
#	echo "forum: tcl forums - read-only"
#	echo "docsrc: source for generating tcl document tree"
#	echo "tests: sql logic test harness"
	exit 0
}

# Change to correct directory
pushd "${TCLHOME}"

if [ ${#*} -lt 1 ]; then # I want it all
	all # sleep is built in between stages
else #iterate, chuck it in if keyword isn't recognised.
  for t in ${*}; do
    case $t in "-h"|"--help") dohelp ;;
      "tcl-code"|"tcl") tcl-code ;;
      "tcl-tips"|"tips") tcl-tips ;;
      "tk-code"|"tk") tk-code ;;
      "all") all ;;
      "*") dohelp ;; # This exits, no matter what the state of other ${*}
    esac
    sleep 5 # Allow each server to start up before anything else happens
  done
fi

# We all done sah.
popd

#+END_SRC

======== End of tclweb.sh ========

** fossilgitcreate
This little scriptlet will hopefully duplicate a git repo, seeing as there isn't an obvious way
to run fossil git import yet, as it hasn't been fully developed.
*** Problems:
This doesn't deal at all with any branching. I don't yet know how to do that, but I've no doubt I can
probably coerce both git and fossil to do branch wrangling.
I could possibly write this easier in tcl if I knew how.
*** Source file
My concept is as follows:

+ Create a new fossil file in the directory we wish to import from. (This can and should be changed later)

======== Beginning of fossilgitcreate (doesn't do anything yet) ========

#+BEGIN_SRC bash :tangle fossilgitcreate :tangle-mode (identity #o644)
#!/bin/bash
# Creates new fossil from git tree. There'll be a corresponding one for fossilgitadd. Soon.
#
# v0.0.1 Initial cut at problem
# v0.0.2 Switch out baked-in value for a variable


# Let's get a repo going. Later we'll ask for the name of this repo ($1 etc)
REPONAME=chooseyournewreponame.fossil
REPO_PASSWORD=${REPO_PASSWORD:~whateveryoulike} # choose default password unless we pass it in via $1
fossil init ${REPONAME} --template ${HOME}/fossils/skeleton.fossil
# Add correct password to setup user, probably ${USER}. We should add a daily-use user later with caps of ay.
fossil user password ${USER} "whateveryoulike" -R ${REPONAME}
# Now we "open" a new dir. Gotta coerce fossil to open in a not-empty directory.
fossil open -R ${REPONAME} --force

# Now we stash the current state, we'll need to come back to here at the end.
git stash create "CurrentState"
#+END_SRC

======== End of fossilgitcreate ========

Further notes for extra lines in the script:
+ Add user if not set from template
+ Run git log, look for very first entry. check that out.
+ fossil add all the files that turn up, excluding the fossil file itself, the .git hierarchy and the .fslckout, obviously.
+ loop through all the other git leaves
  + adding them to fossil one by one
  + with the commit message duplicating the one held by git.
+ close out the fossil, as the last git commit should now be at HEAD

** fossilmake

This is a script that changes into the relevant directory and re-creates the compiled binary,
presumably after a fossil update operation to get things right. At least for the moment I can simply
hack-and-cut from fossilsource, as that has enough bits in it where it visits every relevant fossil
I have here. All I'd then have to do is to strip out those bits I don't need, either because they
don't update any more (cvstrac) or they don't have an executable as an output. Instead, they have a
document such as a pdf. I could still create these, but the impetus would then shift to a separate
fossildoc tool that collects relevant docs together under one script that runs much like fossilmake
does.

I'll make this executable now I have some code in here.

#+ATTR_LATEX: :options frame=single,backgroundcolor=\color{lightgray}
#+BEGIN_SRC bash :tangle fossilmake :tangle-mode (identity #o755)
#!/bin/bash
#
# v0.0.1 Absolute first cut at fossilmake
# v0.1 Working updater, creator and installer
# v0.1.1 Added comment to fossilmake's installFossil about privileges.
# A prototype maker of fossil projects

MYNAME=fossilmake

# Variables? What variables?
# My default is /home/viking/src/bash/fossil/fossilmake
FOSSILSRC="${FOSSILSRC:-${HOME}/src/c/fossil-scm/fossil/}"
FOSSILINSTALLHOME="/usr/local" # default unless changed

# Functions
function helpFossil() {
  cd "${FOSSILSRC}"
  echo "Welcome to fossilmake, a program to update, make and install fossil."
  echo "Usage: fossilmake {-h|--help|-d|--clean|-g|--get|-m|--make|-i|--install}"
  echo "  -h   shows this help message"
  echo "  -d   clean (not distclean) removes all compiled output"
  echo "  -D   distclean removes all compiled output and configure scripts"
  echo "  -g   fetches latest fossil source code"
  echo "  -m   makes fossil with already-configured tree"
  echo "  -i    installs fossil once you've made it. This may require privileges"
  cd -
}

# Merely cleans compiled output, not a full distclean
function cleanFossil() {
  cd "${FOSSILSRC}"
  make clean
  cd -
}

function distcleanFossil() {
  cd "${FOSSILSRC}"
  make distclean
  cd -
}

function getFossil() {
  cd "${FOSSILSRC}"
  make clean # We do this so we have a clean codebase
  # I make use of a previously-written script here.
  fossilsource fossil-code  # First fetch the fossil
  fossil up    # then update source from the fossil
  cd -
}

function makeFossil() {
  cd "${FOSSILSRC}"
  make -j4 prefix="${FOSSILINSTALLHOME}"
  cd -
}

function installFossil() {
  cd "${FOSSILSRC}"
  # Don't forget to kill all running fossil servers
  # Don't forget to run this with privileges if you install to a place you don't "own"
  make prefix="${FOSSILINSTALLHOME}" install
  # You may want to restart the fossil server after this
  cd -
}

# Main function

if [[ -z $1 ]]; then
  helpFossil
else
case "$1" in "-g"|"--get") getFossil # does "make clean" first for a clean codebase
    ;;
    "-d"|"--clean") cleanFossil
    ;;
    "-D"|"--distclean") distcleanFossil
    ;;
    "-m"|"--make") makeFossil
    ;;
    "-i"|"--install") installFossil
    ;;
    "-mi"|"--makeinstall") # kind of obvious
        makeFossil
        installFossil
    ;;
    "-h"|"--help") helpFossil # call this case out specifically
    ;;
    # Anything else gets the usage message
    "*") helpFossil
    ;;
esac
fi

#+END_SRC

** fossildoc

Preliminary stub to create the docs for each relevant project. At this stage, those are just the
doctree for fossil-book and sqlite-docs, with a suitable upload to my local fossil for the sqlite
docs. As for other docs, I'll have to trawl through the other projects to find them, if they're not
already wrapped up inside fossil wikis. If they're there, then do I bother to crowbar them out or leave
them in their original wrappers? Thinking about it for ten seconds leads me to the conclusion that
fossil wikis are generally best if anything is embedded in the text such as TH1 or pikchr.

Again, I'll make this non-executable for the moment until I have some code in here.

#+ATTR_LATEX: :options frame=single,backgroundcolor=\color{lightgray}
#+BEGIN_SRC bash :tangle fossildoc :tangle-mode (identity #o644)
#!/bin/bash
#
# v0.0.1 Absolute first cut at fossildoc
# A prototype maker of docs for fossil projects

MYNAME=fossildoc


#+END_SRC

* Further directions

( or, future thoughts )

These scripts are mostly finished with, and the conversion of fossilsource to parsing parameters is
now done. Most of the hard work was already done in the sqliteweb.sh and fossilweb.sh scripts, so
the improvements from those scripts have made their way back to fossilsource.

fossilweb.sh, sqliteweb.sh, and tclweb.sh have all been pretty much superseded by fossilserve, as it
just shows a directory of all my fossils and lets me choose, instead of running up an individual
server on a separate port for the thing I want. As this may not be what you want, I provide the
other scripts here as a model on which to create your own. I haven't quite kept these up to date the
same way as fossilserve. It's something I should get to, in case you do acually want to just run one
or two of the fossils on their own ports.

There's also enough other fossils on my system that aren't covered by either of these XyZserve.sh 
scripts, and that doesn't bother me. Everything's covered by the fossilserve instead.

One other thing to seriously consider is initial cloning of the fossils that aren't already on my
system. I've got a small list of them here, but there are literally thousands up on chiselapp in
various stages of "We're done" to "We just copied at x point and didn't do anything else".

Thinking on something Stephan said in one of his forum posts on the many forums he's a part of, got
me thinking about a simple script to handle making some of the extracted code bases I do have here.
Simple stuff like pikchr and the like is pretty much wander in, make and copy to destination. With
the slightly more complex cases, I'd want to perhaps provide some localised default values for
compiling them instead of the OOTB values.

I could jokingly call it fossilmake.

* Postscript and credits

I'd love to thank the guys that created the sqlite project and all the other satellite projects that
go along for the ride, the most well known being the fossil SCM, upon which development is
based. You set up a fossil, put files into it, and they're then backed by a sqlite3 database inside
the fossil, complete with all the other advantages that an all-in-one solution provides.

