selfupdate

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 29 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package selfupdate finds the desktop app's newest release, verifies it with the release's Sigstore signature, and installs it over the running app when enbu manages the installation itself.

Index

Constants

View Source
const Repository = "enbu-net/enbu"

Repository is where the desktop app is released.

Variables

View Source
var ErrDownload = errors.New("download failed")

ErrDownload marks a failure to reach GitHub or to download a release file; trying again later may work.

View Source
var ErrNotSelfManaged = errors.New("this installation is not updated by the app")

ErrNotSelfManaged means the installation is updated some other way.

View Source
var ErrUnverified = errors.New("update failed verification")

ErrUnverified marks an update whose signature or checksum did not match; nothing of it is installed.

Functions

func AssetName

func AssetName(version, goos, goarch string) (string, bool)

AssetName is the desktop archive a release builds for one platform; the names come from .github/workflows/release-build.yaml.

func ChecksumFor

func ChecksumFor(checksums []byte, name string) ([]byte, error)

ChecksumFor finds a file's SHA-256 in a sha256sum listing.

func CleanUp

func CleanUp(target string)

CleanUp removes what an earlier update left beside target: the old Windows binary, which could not be deleted while it ran, and a new copy an interrupted update did not rename into place.

func Install

func Install(ctx context.Context, goos string, archive *os.File, target string) error

Install replaces target (see Target) with the app in a verified release archive. It reads the archive through the handle that was verified, not by its name, so the file cannot be swapped in between (the disk image, which hdiutil opens by name, lives in the user's private cache directory). The new copy is written beside target first and then renamed into place, so a failure leaves the running app as it was.

func IsRelease

func IsRelease(version string) bool

IsRelease reports whether version names a release (vMAJOR.MINOR.PATCH, without a prerelease or build suffix such as -dirty).

func Newer

func Newer(current, latest string) bool

Newer reports whether latest is a newer release than current.

func Relaunch

func Relaunch(executable string) error

Relaunch starts executable again, telling it to wait until this process has exited. The caller quits right after.

func Target

func Target(goos, executable string) (string, bool)

Target is what an update replaces: the .app bundle on macOS, the binary elsewhere. ok is false for a macOS binary outside an app bundle.

func VerifyChecksums

func VerifyChecksums(trusted root.TrustedMaterial, checksums, bundleJSON []byte) error

VerifyChecksums checks the Sigstore bundle of checksums.txt against the trusted root: a Fulcio certificate for the release workflow, an SCT, and an entry in the Rekor transparency log.

func VerifyFile

func VerifyFile(r io.Reader, want []byte) error

VerifyFile checks that r hashes to want.

func WaitForPrevious

func WaitForPrevious(c clock.Clock, timeout time.Duration)

WaitForPrevious blocks, for at most timeout, until the app that relaunched this one has exited, and clears the variable so children do not inherit it.

Types

type Installation

type Installation struct {
	GOOS       string
	Version    string
	Executable string // the running binary, symlinks resolved
	// Writable reports whether this user may create and rename files in dir.
	Writable func(dir string) bool
	// Exists reports whether a path exists.
	Exists func(path string) bool
}

Installation is what Detect looks at; the fields are inputs so that tests can describe any machine.

func Here

func Here(goos, version string) Installation

Here describes the running installation.

type Method

type Method string

Method says who updates an installation, and so what the app may offer.

const (
	// MethodSelf: unpacked from a release archive into a place this user may
	// write; the app replaces itself.
	MethodSelf Method = "self"
	// MethodHomebrew: installed with Homebrew; `brew upgrade` updates it.
	MethodHomebrew Method = "homebrew"
	// MethodSystemPackage: installed from the .deb or .rpm; the system's
	// package manager updates it.
	MethodSystemPackage Method = "system_package"
	// MethodEditor: the enbu binary inside an editor extension (VS Code),
	// which the editor's extension updates replace.
	MethodEditor Method = "editor"
	// MethodDevelopment: a build without a release version.
	MethodDevelopment Method = "development"
	// MethodManual: a release build in a place this user may not write;
	// the person downloads the release.
	MethodManual Method = "manual"
)

func Detect

func Detect(in Installation) Method

Detect decides who updates the installation. The checks go from the most specific to the most general: a build without a release version never updates, a package manager's files belong to it, and only then may the app replace itself where it can write.

func (Method) Looks

func (m Method) Looks() bool

Looks reports whether a method looks for releases at all: editor extensions are updated by the editor, and development builds have no release to compare with.

type Release

type Release struct {
	Version string
	URL     string            // the release page
	Assets  map[string]string // file name -> download URL
}

Release is a published release and the files the updater needs from it.

func Latest

func Latest(ctx context.Context, client *http.Client) (Release, error)

Latest asks GitHub for the newest release. It needs no sign-in: the repository is public, and the signature, not GitHub, is what the updater trusts.

type Status

type Status struct {
	Method  Method `json:"method"`
	Current string `json:"current"`
	// Latest is empty when the method does not look for releases
	// (development builds and editor extensions).
	Latest string `json:"latest,omitempty"`
	// Available is true when Latest is newer than Current.
	Available bool   `json:"available"`
	URL       string `json:"url,omitempty"`
}

Status is what a check found.

type Updater

type Updater struct {
	Client  *http.Client
	Method  Method
	Version string
	GOOS    string
	GOARCH  string
	// Target is what Install replaces (see Target).
	Target string
	// CacheDir keeps the Sigstore trusted root and the downloads.
	CacheDir string
	// TrustedRoot returns the Sigstore trusted root; nil fetches it over
	// TUF (the root of trust embedded in sigstore-go), cached in CacheDir.
	TrustedRoot func(ctx context.Context) (root.TrustedMaterial, error)
	// Clock bounds the release lookup; nil uses the real clock.
	Clock clock.Clock
	// contains filtered or unexported fields
}

Updater checks for and installs releases of one installation.

func (*Updater) Check

func (u *Updater) Check(ctx context.Context) (Status, error)

Check compares the installation with the newest release.

func (*Updater) Update

func (u *Updater) Update(ctx context.Context) (Status, error)

Update installs the newest release when it is newer: it downloads checksums.txt and its Sigstore bundle, verifies them, downloads this platform's archive, checks it against checksums.txt and only then replaces the app. It returns the status after the update.

Jump to

Keyboard shortcuts

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