installsh

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package installsh generates a consumer repo's root install.sh from one canonical template.

Shell cannot be imported, so the honest form of "shared" is generated-and-verified. The template lives here; each consumer repo holds a small spec file and a generated install.sh at its root (it must be at the root for `curl …/main/install.sh | sh` to resolve), plus a drift check that fails when the checked-in copy no longer matches what the template would produce.

The template is the union of the six hand-written scripts it replaces — curl-or-wget, uname mapping including the three 32-bit ARM spellings, GitHub API version resolution with optional token, sha256 verification against checksums.txt, optional tarball unpacking, BIN_DIR with the legacy PREFIX alias, sudo escalation, PATH warning, runtime-dependency warnings and post-install hints — with every point of divergence turned into a Spec field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDrift

func CheckDrift(path string, spec Spec) error

CheckDrift reports whether the file at path is byte-identical to what Render(spec) produces. This is the dev-only guard that keeps six copies of a script from diverging again: run it from a Make target or a test.

func Render

func Render(spec Spec) ([]byte, error)

Render produces the install.sh contents for spec.

func Write

func Write(path string, spec Spec) error

Write renders spec and writes it to path with mode 0755 — install.sh is executable in every repo that has one.

The chmod is not redundant: os.WriteFile applies its mode only when it CREATES the file, so regenerating over an existing non-executable copy would otherwise leave a `./install.sh` that cannot be run.

Types

type Dep

type Dep struct {
	// Name is the command looked for on PATH, e.g. "tmux".
	Name string `json:"name"`
	// Message is the warning shown when it is absent.
	Message string `json:"message"`
}

Dep is a runtime dependency the installed binary needs but this script will not install: the package name differs per distro, and silently pulling in a terminal multiplexer (acp-tmux's case) is not an installer's business. The script warns instead.

type Spec

type Spec struct {
	// Repo is the GitHub "owner/name", e.g. "kfet/harb".
	Repo string `json:"repo"`
	// Binary is the installed file name.
	Binary string `json:"binary"`
	// AssetStem defaults to Binary. See distkit.Config.AssetStem.
	AssetStem string `json:"asset_stem,omitempty"`
	// AssetTemplate defaults to distkit.DefaultAssetTemplate and uses the
	// same placeholders, so a consumer's Go config and its install.sh
	// cannot drift apart on asset naming.
	AssetTemplate string `json:"asset_template,omitempty"`
	// ArmSuffix is the asset-name token for 32-bit ARM; defaults to
	// "armv6".
	ArmSuffix string `json:"arm_suffix,omitempty"`
	// NoChecksums disables sha256 verification. Two of the six originals
	// shipped without it; that was a bug, not a variation, so it must be
	// asked for explicitly.
	NoChecksums bool `json:"no_checksums,omitempty"`
	// ChecksumsAsset defaults to distkit.DefaultChecksums.
	ChecksumsAsset string `json:"checksums_asset,omitempty"`
	// Darwin includes macOS in the supported-OS list. Default true.
	// Pointer so the JSON zero value can still mean "yes".
	Darwin *bool `json:"darwin,omitempty"`
	// FreeBSD includes FreeBSD (airan and mintick published for it).
	FreeBSD bool `json:"freebsd,omitempty"`
	// Arch386 includes 32-bit x86.
	Arch386 bool `json:"arch_386,omitempty"`
	// BrewFormula, when set (e.g. "kfet/tap/harb"), adds the macOS
	// "prefer brew" note to the header.
	BrewFormula string `json:"brew_formula,omitempty"`
	// RuntimeDeps are warned about when missing from PATH.
	RuntimeDeps []Dep `json:"runtime_deps,omitempty"`
	// VersionFlag is run against the freshly installed binary as a smoke
	// test, e.g. "-version". Empty skips it.
	VersionFlag string `json:"version_flag,omitempty"`
	// NextSteps are printed at the end, one per line, e.g.
	// "harb init    # bootstrap config".
	NextSteps []string `json:"next_steps,omitempty"`
	// ExampleTag appears in the usage header, e.g. "v0.1.0".
	ExampleTag string `json:"example_tag,omitempty"`
}

Spec is everything a consumer repo's install.sh varies by. The zero value is not usable: Repo and Binary are required.

func FromConfig

func FromConfig(cfg distkit.Config) Spec

FromConfig derives the install.sh spec from the same Config the binary self-updates with, so asset naming has exactly one definition per project.

func LoadSpec

func LoadSpec(path string) (Spec, error)

LoadSpec reads a spec from a JSON file, the form a consumer repo checks in next to its install.sh.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL