Tcl

TCL - bootstrapping
Login

home

%%%

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:

This means that two different install script are required:

  1. fnest.sh : For any platform except MS Windows
  2. fnest.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:

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:

  1. 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
      or
    • https://kuu.se/fossil/fnest.ps
  2. 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

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:

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:

Download command for the first stage: wget, fetch, curl or Invoke-RestMethod/Invoke-Expression

Installation details

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

See also