Help us shape the future of Go! Take the 2026 Go Developer Survey

selfupdate

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package selfupdate implements the sync82 self-update command: checking GitHub Releases for a newer version, verifying its checksum, and replacing the currently installed binary in place.

Index

Constants

View Source
const DefaultAPIURL = "https://api.github.com/repos/" + Repo + "/releases/latest"

DefaultAPIURL is the GitHub Releases endpoint that returns the latest release of Repo. It is the default value for Deps.APIURL.

View Source
const ExitUpdateAvailable = 10

ExitUpdateAvailable is the exit code of "self-update --check" when a newer release exists.

View Source
const Repo = "oito2/mcp-sync82"

Repo is the GitHub repository self-update fetches releases from.

Variables

This section is empty.

Functions

func AssetName

func AssetName(goos, goarch string) string

AssetName returns the release asset name of the sync82 binary for goos/goarch: sync82_<goos>_<goarch>, with an ".exe" suffix on Windows. The name carries no version, so the newest release is always reachable at the same releases/latest/download URL.

func ReleasePlatforms added in v1.2.0

func ReleasePlatforms() [][2]string

ReleasePlatforms returns the GOOS/GOARCH pairs every release is built for, each published as the asset AssetName names. Each call returns a new slice.

func RunSelfUpdate

func RunSelfUpdate(ctx context.Context, args []string, deps Deps, stdin io.Reader, stdout, stderr io.Writer) int

RunSelfUpdate implements "sync82 self-update [--check] [--yes|-y]" and "sync82 self-update --rollback". "--require-signature" is also accepted with an update. args are the options after the subcommand name; deps supplies the environment; stdin is read for the confirmation answer; progress goes to stdout and errors to stderr.

It returns the process exit code: 0 = up to date / aborted / updated / rolled back, ExitUpdateAvailable = update available with --check, 1 = error (development build, closed stdin at the confirmation prompt, failed check, download, verification or replacement, or no usable cosign with --require-signature), 2 = usage error (unknown option or combination).

An update downloads the new binary into a temporary directory next to the running one, verifies the Sigstore signature of the release's checksums.txt with cosign v3 or later when one is found (see verifySignature), checks the binary against checksums.txt, runs it with --version and requires the release tag back, then swaps it in, keeping the replaced binary as "<binary>.bak" — restored automatically if the swap fails, and by hand with --rollback.

Types

type Deps

type Deps struct {
	// Version is the currently running binary's version; GOOS and GOARCH
	// select the release asset to download.
	Version string
	GOOS    string
	GOARCH  string

	// APIURL is the releases endpoint queried for the latest release, and
	// HTTPClient performs every HTTP request.
	APIURL     string
	HTTPClient *http.Client

	// ExecutablePath resolves the path of the currently running binary.
	ExecutablePath func() (string, error)

	// TempDir is the directory the update is staged in. Defaults to the
	// running binary's own directory, so the final rename never crosses
	// filesystems.
	TempDir string

	// ValidateURL checks a download URL, and every redirect target, before
	// it is fetched. Defaults to validateAssetURL (HTTPS from github.com or
	// GitHub's release asset hosts only).
	ValidateURL func(rawURL string) error

	// ValidateAsset checks the download URL of a release asset against the
	// release's tag before it is fetched. Defaults to validateReleaseAsset
	// (the repository's own release of that tag only).
	ValidateAsset func(rawURL, tag string) error

	// RunVersion runs a binary with --version and returns its trimmed
	// output. Defaults to runVersion.
	RunVersion func(ctx context.Context, path string) (string, error)

	// LookCosign returns the path of the cosign binary used to verify the
	// release signature, or an error when there is none. Defaults to
	// exec.LookPath("cosign").
	LookCosign func() (string, error)

	// RunCosign runs the cosign binary at path with args and returns its
	// combined output. Defaults to runCosign.
	RunCosign func(ctx context.Context, path string, args ...string) ([]byte, error)

	// Rename moves a file, for the swap of the binary and its backup.
	// Defaults to fsutil.Rename.
	Rename func(oldpath, newpath string) error
}

Deps bundles everything RunSelfUpdate needs from its environment, so each piece can be replaced to avoid real network access, the real executable path and writes outside a chosen directory.

Jump to

Keyboard shortcuts

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