selfupdate

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package selfupdate replaces the running llmconfig binary with a newer release pulled from GitHub. The package is intentionally narrow: fetch release metadata, pick the right asset for the current OS/arch, verify SHA256 against the published checksums.txt, and atomically swap the binary on disk.

The atomic-swap pattern works on both Unix (where you can overwrite running binaries) and Windows (where you can't, but you *can* rename a running executable out of the way before placing the new one).

Index

Constants

View Source
const Repo = "kiliczsh/llmconfig"

Repo is the GitHub repository slug llmconfig publishes releases from. The selfupdater refuses to download from any other host, so changing this is the single point of trust.

Variables

View Source
var ErrNoChecksum = errors.New("selfupdate: no checksum entry for asset")

FetchChecksum returns the published SHA256 for an asset, downloaded from the release's checksums.txt. Returns ErrNoChecksum if the file or entry isn't present — callers can decide whether to fail or proceed.

Functions

func DownloadAsset

func DownloadAsset(asset *Asset, dest string, expectedSHA256 string, onProgress func(downloaded, total int64)) error

DownloadAsset streams the asset to dest, verifying SHA256 if expected is non-empty. onProgress receives (downloaded, total) byte counts as the stream advances. Refuses to download from anywhere outside the release URL prefix, even if Asset.DownloadURL was tampered with after PickAsset validated it (belt and braces).

func FetchChecksum

func FetchChecksum(rel *Release, assetName string) (string, error)

func Swap

func Swap(targetPath, newPath string) error

Swap replaces targetPath with newPath atomically. On Windows the running binary cannot be overwritten, but it can be renamed out of the way; we always rename current → "<target>.old" before installing the new one. If the second rename fails, the original is restored.

Both paths must live on the same filesystem — selfupdate places the staging file in the same directory as the target to satisfy this.

Types

type Asset

type Asset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
	Size        int64  `json:"size"`
}

Asset is one downloadable file attached to a release.

func PickAsset

func PickAsset(rel *Release) (*Asset, error)

PickAsset returns the release archive for the current OS/arch. The naming convention matches install.sh/install.ps1: llmconfig-<version>-<os>-<arch>.<ext> (.zip on Windows, .tar.gz elsewhere).

type ExtractedBinaries

type ExtractedBinaries struct {
	Llmconfig string
	Llmc      string // empty when the archive doesn't include the alias
	StageDir  string // caller is responsible for cleanup
}

ExtractedBinaries holds the on-disk paths to the llmconfig and (optional) llmc binaries inside a downloaded release archive's staging directory.

func ExtractRelease

func ExtractRelease(archivePath string) (*ExtractedBinaries, error)

ExtractRelease unpacks the downloaded archive into a fresh staging directory next to it and returns the absolute paths of the binaries found. Cleanup of StageDir is the caller's responsibility — typically after a successful Apply().

type Release

type Release struct {
	TagName string  `json:"tag_name"`
	Name    string  `json:"name"`
	Assets  []Asset `json:"assets"`
}

Release mirrors the subset of GitHub's release JSON that we use.

func LatestRelease

func LatestRelease() (*Release, error)

LatestRelease fetches the most recent release tagged on the repo.

func ReleaseByTag

func ReleaseByTag(tag string) (*Release, error)

ReleaseByTag fetches a specific tagged release. Use it for --version pinning.

Jump to

Keyboard shortcuts

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