%%%
A bootstrap solution for fnest (as platform-independent as possible)
The idea is to either download or detect an installed Tcl interpreter, and then run a Tcl install script for fnest.
Using a minimal Tcl interpreter such as jimsh avoids external dependencies.
The chicken-and-egg problem
It would be easy to run a Tcl install script if a Tcl interpreter is always guaranteed
to be present on the local host, but this is not always the case.
So the first problem to be solved is: How to detect the presence of a Tcl interpreter?
Obviously, Tcl can not be used for this task.
The first problem to be solved : Which scripting language/shell command should be used to detect a Tcl interpreter?
Unfortunately, there is no platform-independent solution.
Anyhow, the shell to use could be reduced to:
- Any platform except MS Windows:
sh(Bourne shell, or derivates) - MS Windows:
PowerShell
This means that two different install script are required:
fnest.sh: For any platform except MS Windowsfnest.ps: MS Windows
To run a remote shell script, the shell command is combined with a "download tool".
This "download tool" is also platform-dependent, but may be reduced to:
wget: Installed by default on most Linux distributions.fetch: Installed by default on BSD platforms.curl: Installed by default on MacOSX.irm/iex: The equivalent commands used on MS Windows.
irmis short forInvoke-RestMethod. It will download a script from that website.iexis short forInvoke-Expression. It will run the script.
The browser as a "OS detection helper"
Modern browsers can detect the local OS, so a web page could show a dynamic content depending on the local OS:
- Depending on if the detected OS is MS Windows or not, show one "direct download link".
If the user chooses this option, the script should be downloaded and run "manually" from a shell terminal.https://kuu.se/fossil/fnest.sh
orhttps://kuu.se/fossil/fnest.ps
- An install command, including the "download tool":
- Linux:
sh <(wget -q https://kuu.se/fossil/fnest.sh -O -) - BSD:
sh <(fetch -q https://kuu.se/fossil/fnest.sh) - MacOSX:
sh <(curl -s https://kuu.se/fossil/fnest.sh) - MS Windows:
irm https://kuu.se/fossil/fnest.ps | iex
- Linux:
If the local OS cannot be detected, the most logical option is to show the Linux alternative by default.
Example web page
%%%
Modern browsers can detect the local OS, so a web page could show different install commands depending on the local OS.
Linux (wget)

Image 1: Install using Bash + wget
BSD (fetch)

Image 2: Install using Bash + fetch
MacOSX (curl)

Ms Windows (wget)

irm is short for Invoke-RestMethod . It will download a script from that website.
iex is short for Invoke-Expression . It will run the script.
Linux / Mac / BSD / etc (sh):

Image 1: Browser page for installation using Bash
MS Windows (PowerShell):

Image 2: Browser page for installation using PowerShell
As there only two combinations of the "system download command" and the "system script language", only two download commands and two download are required.
See below for details for each download command.
The preferred way: Use the jimsh0.c source code
As jimsh is tiny (single C-code file, source code: ~614 kB, executable: ~341 kB), it is well suited for bootstrapping over the Net.
If a C compiler is available on the local system, jimsh0.c may be downloaded and compiled.
This is the preferred way to install jimsh0, as no OS detection is required.
Second choice: Use a precompiled jimsh0 executable
If no compiler is available on the local system, the jimsh0 (or jimsh0.exe) executable must be downloaded.
In this case, the OS must be detected first, to download a compatible executable for the local system.
This means that the download server must offer several different jimsh0 binaries, one for each supported OS/platform.
For a generic installation of any software, this may imply a myriad of jimsh0 versions for different platforms, somewhat inconvenient to maintain.
Anyway, in the specific case of fnest, fossil is one dependency, so the list of supported platforms may be the same
as the list of platforms on the Fossil download page.
Some assumptions may also be done to further reduce the list of different precompiled jimsh0 executables:
- BSD systems: A compiler is (almost) always present, so there is no need to precompile
jimshfor Free|Open|NetBSD. - Linux systems: Easy to compile and upload to the server, where it also can be tested.
- MS Windows systems: Assume that a compiler is not available, so always offer a precompiled version. (Using MSYS2, this is an easy task.)
- MacOSX, Raspberry Pi: Suggestion: Use a Linux host/VM, and setup a
clangcross-compiler environment MacOSX and Raspberry.
Scripting language for the first stage: sh or PowerShell
This is why the very first stage must be written in some "system script language", which is known to always be available on the local system.
As in many other situations, MS Windows is the exception here, so the "system script language" may be resumed to the following:
- Any platform except MS Windows:
sh(Bourne shell, or derivates) - MS Windows:
PowerShell
Download command for the first stage: wget, fetch, curl or Invoke-RestMethod/Invoke-Expression
wget: Installed by default on most Linux distributions.fetch: Installed by default on BSD platforms.curl: Installed by default on MacOSX.Invoke-RestMethod/Invoke-Expression: The equivalent commands used on MS Windows.
Installation details
Download-and-install step (ideas from the
ghcupinstaller) and from Tauri:Linux/Unix/MacOSX/MSYS2/Cygwin/WSL2: Run in a terminal (as a non-root user):
curl --proto '=https' --tlsv1.2 -sSf https://kuu.se/your-installer.sh | shMS Windows: Run in a PowerShell session (as a non-admin user):
Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { & ([ScriptBlock]::Create((Invoke-WebRequest https://kuu.se/your-installer.ps1 -UseBasicParsing))) -Interactive -DisableCurl } catch { Write-Error $_ }
Install details:
- Linux/Unix/MacOSX/MSYS2/Cygwin/WSL2:
- Download and run
your-installer.sh(done by the command above).
Theyour-installer.shscript should:- Automatically download
bootstrap.tcl. - Try to find
tclshorjimsh0inPATH. - If found, run
tclsh bootstrap.tcl. - If not found, try to find
ccinPATH. - If a compiler is present found, automatically download and compile
jimsh0.c. - If no compiler is present, detect OS, and download a precompiled
jimsh0interpreter for the current OS. - There is no precompiled
jimsh0for MacOSX, so in such a case, an error message should be shown with something like "Install Xcode". - Run
./jimsh0 bootstrap.tclto start the installation.
- Automatically download
- Download and run
- MS Windows (PowerShell):
- Download and run
your-installer.ps1(done by the command above).
Theyour-installer.ps1script should:- Automatically download
bootstrap.tcl. - Try to find
tclshorjimsh0inPATH. - If no Tcl interpreter was found, automatically download a precompiled
jimsh0interpreter for MS Windows. - Run
jimsh0 bootstrap.tclto start the installation.
- Automatically download
- Download and run
- Linux/Unix/MacOSX/MSYS2/Cygwin/WSL2:
The bootstrap.tcl script
The bootstrap.tcl script should setup the environment as described in the fnest README.
Related (bootstrap script) - DOSH
More bootstrap script examples
- myscript.cmd from https://nastytester.com/posts/script-that-works-in-windows-and-linux.html
- myscriptwithargs.cmd from https://superuser.com/questions/188143/how-to-detect-windows-os-in-shell-script