selfupdate

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package selfupdate resolves and downloads akari client releases from GitHub so the client can update itself in place.

It is the Go counterpart of the install scripts in scripts/: it resolves the latest published release, downloads the archive that matches a target OS and architecture, verifies it against the release SHA256SUMS, and extracts the binary. The client uses it for a fully native update with no shell or curl.

Index

Constants

View Source
const DefaultRepo = "jssblck/akari"

DefaultRepo is the GitHub owner/repo releases are pulled from. AKARI_REPO overrides it, matching the install scripts.

Variables

This section is empty.

Functions

func AssetName

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

AssetName is the release archive filename for a binary and target, matching the names the release workflow produces: the version without a leading v, a .zip for Windows, and a .tar.gz everywhere else.

func CleanupOld

func CleanupOld(target string)

CleanupOld is a no-op on Unix; only the Windows path leaves a stale file behind after an update.

func Replace

func Replace(target, newPath string) error

Replace installs newPath at target, replacing the running binary.

On Unix a running executable's file can be replaced while it runs: the kernel keeps the old inode mapped for the live process, and the rename atomically swaps the directory entry so the next launch picks up the new binary. newPath must be on the same filesystem as target (the caller extracts it into target's directory) so the rename does not fail with a cross-device error.

func UpToDate

func UpToDate(current, latest string) (upToDate, comparable bool)

UpToDate compares the running version against the latest release tag.

upToDate is true when current is the same as, or newer than, latest (so a build running a prerelease ahead of the latest stable is not told to downgrade). comparable is false when current is not a valid semver tag (a development build stamped with a commit SHA or "dev"), in which case upToDate is meaningless and callers should treat the build as updatable.

Types

type Client

type Client struct {
	// Repo is the GitHub owner/repo to download from.
	Repo string
	// APIBaseURL is the base for the GitHub API. Overridable for testing.
	APIBaseURL string
	// DownloadBaseURL, when non-empty, is the base URL holding the archive and
	// SHA256SUMS, overriding the per-tag GitHub release URL. It mirrors the
	// AKARI_BASE_URL the install scripts honor, and lets tests point at a local
	// server.
	DownloadBaseURL string
	// contains filtered or unexported fields
}

Client resolves and downloads release assets. The zero value is not usable; construct one with New.

func New

func New() *Client

New builds a Client with the default GitHub endpoints, honoring the AKARI_REPO and AKARI_BASE_URL environment overrides the install scripts also respect.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, binName, tag, goos, goarch, dest string) error

Fetch downloads the release archive for binName at tag for the given target, verifies it against the release SHA256SUMS, and extracts the binary to dest (created with mode 0755). It does not touch the running binary; the caller installs the result with Replace.

func (*Client) LatestTag

func (c *Client) LatestTag(ctx context.Context) (string, error)

LatestTag returns the tag of the latest published release (the same release the install scripts resolve through the GitHub API).

Jump to

Keyboard shortcuts

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