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 ¶
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.
const Repo = "oito2/mcp-sync82"
Repo is the GitHub repository self-update fetches releases from.
Variables ¶
This section is empty.
Functions ¶
func AssetName ¶
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 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". 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 / update available with --check / aborted / updated / rolled back, 1 = error (development build, closed stdin at the confirmation prompt, failed check, download, verification or replacement), 2 = usage error (unknown option).
An update downloads the new binary into a temporary directory next to the running one, checks it against the release's 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 before it is fetched. Defaults to
// validateAssetURL (HTTPS from GitHub only).
ValidateURL func(rawURL 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)
}
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.