Back to concept
Lesson 10c86e7Managed Toolchain4/10

Separate tool facts from install mechanics

Start the managed toolchain with ShellCheck: tool-specific facts stay in one script, while reusable install mechanics live in a shared helper.

01

Keep the tool definition data-oriented

The toolchain starts with one pinned tool. ShellCheck's script owns the release version, host asset name, checksum, upstream URL, and path of the executable inside the archive.

The script still runs installation phases, so it is executable rather than purely declarative. Its tool-specific surface is nevertheless data-oriented: reusable download, verification, extraction, and placement mechanics stay in the sourced helper.

toolchain/tools/install-shellcheck.sh:9-28

14 focused lines

Loading source...

Install the pinned ShellCheck build

Run the installer with an explicit prefix, then inspect the installed version. The replay omits curl's progress meter.

step 1/2
interactive replay

Select the terminal to begin, or choose Auto-fill.

02

Reject an unspecified destination

The shared helper enables fail-fast shell behavior and requires TOOLCHAIN_INSTALL_PREFIX as it is sourced. The ${NAME:?message} expansion stops before any directory is created when the caller has not selected a destination.

Making the boundary explicit lets Make provide the repository-local prefix later, while tests and direct runs can safely choose a temporary tree.

toolchain/tools/lib/install.sh:27-41

12 focused lines

Loading source...

Fail before choosing a destination

Run the tool script without an install prefix. Dash reports both the calling script and the sourced line where expansion stops.

step 1/1
interactive replay

Select the terminal to begin, or choose Auto-fill.

03

Download and verify in a staging area

The first fetch creates a temporary directory inside the install prefix and registers cleanup traps. The stable bin directory is not the download destination.

After curl succeeds, the helper computes the staged file's SHA-256 value with sha256sum -c. A mismatch aborts before extraction or publication can trust the bytes.

toolchain/tools/lib/install.sh:110-163

18 focused lines

Loading source...
04

Publish the complete executable last

Only after fetch, verification, and extraction does install_bin validate the staged executable and create the destination directory.

The staging directory lives on the same filesystem as bin, so the final mv can publish the completed executable by rename instead of writing the stable path incrementally.

toolchain/tools/lib/install.sh:181-203

16 focused lines

Loading source...

Finished this lesson?

Completion is saved on this device and used to resume the course.