update

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package update implements what `lazyshell update` needs: find the latest GitHub release, download the archive built for this OS/arch, check it against the release's checksums.txt, and swap the running binary for the one inside.

It is the in-binary equivalent of scripts/install.sh, and deliberately does the same three things in the same order — download, verify, replace. The checksum step is not optional: this code writes an executable that will be run as the user, so a truncated or tampered download must fail loudly rather than land on disk.

Nothing here knows about the CLI: pkg/app owns the messages, the flags and the "am I newer" decision. This package only knows how to fetch and install.

Index

Constants

View Source
const (
	// Repo is where releases come from, in "owner/name" form. Same repository
	// scripts/install.sh downloads from.
	Repo = "thomas-gleizes/lazyshell"
)

Variables

This section is empty.

Functions

func Compare

func Compare(a, b string) (int, bool)

Compare orders two release versions: -1 if a < b, 0 if equal, 1 if a > b. It reports false when either side is not a plain vX.Y.Z — the caller decides what to do about a version it cannot place, and guessing would be the one wrong answer (a build called "dev" is not "older than everything").

func IsRelease

func IsRelease(v string) bool

IsRelease reports whether v looks like a version this package can compare — i.e. a real release, not the "dev" of a `go build` without ldflags nor the `git describe` string a local `make build` produces.

Types

type Updater

type Updater struct {
	// Repo is the "owner/name" repository, defaulting to Repo.
	Repo string
	// APIBase is the GitHub API root, defaulting to https://api.github.com.
	APIBase string
	// DownloadBase is the release-download root, defaulting to
	// https://github.com.
	DownloadBase string
	// GOOS and GOARCH select the archive, defaulting to the running binary's.
	GOOS, GOARCH string
	// Client is the HTTP client, defaulting to http.DefaultClient.
	Client *http.Client
	// Target is the file to replace, defaulting to the running executable
	// (symlinks resolved).
	Target string
}

Updater is a configured "where do I get releases from". The zero value works and targets the real GitHub repository for the running OS/arch — every field exists so the tests can point the whole thing at an httptest server and a temporary directory.

func (Updater) ArchiveName

func (u Updater) ArchiveName() (string, error)

ArchiveName is the release asset for this platform, per .goreleaser.yml's name_template.

func (Updater) Download

func (u Updater) Download(ctx context.Context, tag string) ([]byte, error)

Download fetches the archive for the given tag, checks it against the release's checksums.txt and returns the verified binary's bytes. Nothing touches the filesystem here: an installation that fails halfway must not be able to leave a partial binary behind.

func (Updater) Install

func (u Updater) Install(bin []byte) (string, error)

Install replaces the target with bin and returns the path it wrote to.

The write is a temporary file in the target's own directory followed by a rename, which is what makes it atomic: an interrupted update leaves either the old binary or the new one, never half of either. Renaming over a running executable is fine on Unix — the running process keeps the inode it started with — which is why `lazyshell update` can be run from inside lazyshell.

func (Updater) Latest

func (u Updater) Latest(ctx context.Context) (string, error)

Latest returns the tag of the latest published release, e.g. "v1.2.0".

Jump to

Keyboard shortcuts

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