update

package
v0.0.20 Latest Latest
Warning

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

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

Documentation

Overview

Package update implements self-update: it compares the running version against GitHub releases and downloads, checksum-verifies, and installs a newer binary, skipping Homebrew and go-install builds.

Index

Constants

View Source
const (
	// GitHubOwner is the GitHub owner for amux.
	GitHubOwner = "andyrewlee"
	// GitHubRepo is the GitHub repo for amux.
	GitHubRepo = "amux"
	// GitHubAPIBase is the base URL for GitHub API.
	GitHubAPIBase = "https://api.github.com"
)

Variables

This section is empty.

Functions

func CanWrite

func CanWrite(path string) bool

CanWrite checks if we have write permission to the binary path.

func ExtractBinary

func ExtractBinary(archivePath, destDir string) (string, error)

ExtractBinary extracts the amux binary from a tar.gz archive. Returns the path to the extracted binary.

func GetCurrentBinaryPath

func GetCurrentBinaryPath() (string, error)

GetCurrentBinaryPath returns the path to the currently running binary.

func GetPlatformAssetName

func GetPlatformAssetName(version string) string

GetPlatformAssetName returns the expected asset name for the current platform.

func InstallBinary

func InstallBinary(newBinaryPath, currentBinaryPath string) error

InstallBinary performs an atomic replacement of the current binary. It stages the new binary in the same directory as the target to avoid cross-filesystem rename issues, then uses rename to atomically swap.

func IsDevBuild

func IsDevBuild(version string) bool

IsDevBuild returns true if this is a development build.

func IsGoInstall

func IsGoInstall() bool

IsGoInstall returns true if the binary appears to be installed via `go install`.

func IsHomebrewBuild added in v0.0.10

func IsHomebrewBuild() bool

IsHomebrewBuild returns true when the binary was built for Homebrew.

func VerifyChecksum

func VerifyChecksum(filepath, expectedChecksum string) error

VerifyChecksum verifies a file's SHA256 checksum.

func VerifyMinisign added in v0.0.20

func VerifyMinisign(message, sig []byte, pubKeyB64 string) error

VerifyMinisign verifies that sig is a valid minisign signature over message, made by the key whose base64 public key is pubKeyB64. It returns nil on a valid signature and a non-nil error otherwise (including malformed inputs).

Types

type Asset

type Asset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
	Size               int64  `json:"size"`
	ContentType        string `json:"content_type"`
}

Asset represents a release asset.

func FindPlatformAsset

func FindPlatformAsset(release *Release) *Asset

FindPlatformAsset finds the appropriate asset for the current platform.

type CheckResult

type CheckResult struct {
	CurrentVersion  string
	LatestVersion   string
	UpdateAvailable bool
	ReleaseNotes    string
	Release         *Release
}

CheckResult contains the result of an update check.

type GitHubClient

type GitHubClient struct {
	// contains filtered or unexported fields
}

GitHubClient handles GitHub API interactions.

func NewGitHubClient

func NewGitHubClient() *GitHubClient

NewGitHubClient creates a new GitHub client.

func (*GitHubClient) DownloadAsset

func (c *GitHubClient) DownloadAsset(url string, w io.Writer) error

DownloadAsset downloads an asset to the specified writer.

func (*GitHubClient) FetchChecksums

func (c *GitHubClient) FetchChecksums(release *Release) (map[string]string, error)

FetchChecksums downloads and returns the parsed checksums.txt content.

func (*GitHubClient) FetchChecksumsRaw added in v0.0.20

func (c *GitHubClient) FetchChecksumsRaw(release *Release) ([]byte, error)

FetchChecksumsRaw downloads the raw checksums.txt bytes from the release. Callers that verify the release signature must use these exact bytes as the signed message; parsing first would discard the signed input.

func (*GitHubClient) FetchLatestRelease

func (c *GitHubClient) FetchLatestRelease() (*Release, error)

FetchLatestRelease fetches the latest release from GitHub.

func (*GitHubClient) FetchSignature added in v0.0.20

func (c *GitHubClient) FetchSignature(release *Release) ([]byte, error)

FetchSignature downloads the detached minisign signature over checksums.txt.

type Release

type Release struct {
	TagName     string    `json:"tag_name"`
	Name        string    `json:"name"`
	Body        string    `json:"body"`
	Draft       bool      `json:"draft"`
	Prerelease  bool      `json:"prerelease"`
	PublishedAt time.Time `json:"published_at"`
	Assets      []Asset   `json:"assets"`
}

Release represents a GitHub release.

type Updater

type Updater struct {

	// ForceDowngrade permits installing a release whose version is strictly
	// lower than the running version. Default false (safe): Upgrade refuses
	// downgrades so a re-pointed "latest" tag cannot roll back to an older,
	// still validly-signed release. Callers set it only for deliberate,
	// operator-driven downgrades.
	ForceDowngrade bool
	// contains filtered or unexported fields
}

Updater orchestrates the check and upgrade workflow.

func NewUpdater

func NewUpdater(version, commit, date string) *Updater

NewUpdater creates a new Updater.

func (*Updater) Check

func (u *Updater) Check() (*CheckResult, error)

Check checks for available updates.

func (*Updater) Upgrade

func (u *Updater) Upgrade(release *Release) error

Upgrade downloads and installs the latest version.

type Version

type Version struct {
	Major      int
	Minor      int
	Patch      int
	Prerelease string
	Raw        string
}

Version represents a semantic version.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a semantic version string.

func (Version) Compare

func (v Version) Compare(other Version) int

Compare returns -1 if v < other, 0 if v == other, 1 if v > other.

func (Version) LessThan

func (v Version) LessThan(other Version) bool

LessThan returns true if v < other.

func (Version) String

func (v Version) String() string

String returns the version string with "v" prefix.

Jump to

Keyboard shortcuts

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