updater

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 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 updater lets the seshat binary find out that a newer release exists and replace itself with it.

A release is a GitHub release of KPO-Tech/seshat-runtime that holds one binary per platform (seshat-linux-amd64, seshat-windows-amd64.exe, ...) and a SHA256SUMS.txt, the same files scripts/install.sh and scripts/install.ps1 download. The binary is checked against the sums of the same release before it replaces the running one. That proves the download is intact; it does not prove who published it, which is the trust a user already places in the GitHub release when running the installer.

Index

Constants

View Source
const (
	// CheckInterval is how long a result of the release check is kept before asking GitHub again.
	CheckInterval = 24 * time.Hour

	// SnoozeFor is how long "not now" silences the offer.
	SnoozeFor = 24 * time.Hour
)
View Source
const DefaultRepo = "KPO-Tech/seshat-runtime"

DefaultRepo is the repository the releases are read from.

View Source
const OldSuffix = ".old"

OldSuffix marks the previous binary kept aside during a replacement.

Variables

This section is empty.

Functions

func AssetName

func AssetName(goos, goarch string) string

AssetName is the name of the binary of a release for a platform, as the release workflow and the installers name it.

func ChecksumFor

func ChecksumFor(sums, file string) (string, error)

ChecksumFor finds the sum of file in the text of a SHA256SUMS.txt ("<hex> <name>" or "<hex> *<name>").

func CleanupOld

func CleanupOld(exePath string)

CleanupOld removes the previous binary a replacement left aside. It never fails.

func CurrentExecutable

func CurrentExecutable() (string, error)

CurrentExecutable is the path of the running binary with symbolic links resolved, so that an update replaces the file and not a link to it.

func IsRelease

func IsRelease(raw string) bool

IsRelease reports whether raw is a release version (vMAJOR.MINOR.PATCH...), as opposed to a development build.

func Newer

func Newer(current, latest string) bool

Newer reports whether latest is a higher release than current. Both are "vMAJOR.MINOR.PATCH" with an optional "-prerelease" and "+build"; anything else (a development build is "dev") is never updated, because there is nothing to compare it with. A prerelease is lower than its release.

func Replace

func Replace(exePath, newPath string) error

Replace puts the file at newPath in the place of the binary at exePath. The old binary is renamed aside first (a running executable can be renamed on every system, but only Unix lets it be overwritten), the new one is renamed into place, and the old one is put back if that fails. The renamed-aside file is removed by CleanupOld at the next start, or at once where the system allows it.

func StatePath

func StatePath(runtimeRoot string) string

StatePath is where the state is kept inside the runtime root.

Types

type Client

type Client struct {
	// APIBase is the GitHub API root; tests point it at a local server.
	APIBase string
	Repo    string
	HTTP    *http.Client
}

Client reads releases and downloads their files.

func NewClient

func NewClient() *Client

NewClient returns a client for the official repository.

func (*Client) Download

func (c *Client) Download(ctx context.Context, release Release, goos, goarch, dir string) (string, error)

Download fetches the binary of release for this platform into a new file in dir, checks it against the sums of the release and returns its path. Nothing is left behind on failure.

func (*Client) Latest

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

Latest returns the latest published release.

func (*Client) Update

func (c *Client) Update(ctx context.Context, release Release, exePath string) error

Update downloads the release and replaces the binary at exePath with it.

type Release

type Release struct {
	Tag    string
	Assets map[string]string // asset name -> download URL
}

Release is the part of a GitHub release the updater needs.

type State

type State struct {
	CheckedAt   time.Time `json:"checked_at"`
	Latest      string    `json:"latest"`
	SkippedTag  string    `json:"skipped_tag,omitempty"`
	SnoozeUntil time.Time `json:"snooze_until,omitempty"`
}

State is what the updater remembers between two runs of seshat, so that a launch does not wait for the network and a user who said no is not asked at every start.

func LoadState

func LoadState(path string) State

LoadState reads the state; a missing or damaged file is an empty state.

func (State) Due

func (st State) Due(now time.Time) bool

Due reports whether the release check is old enough to be done again.

func (State) Offer

func (st State) Offer(current string, now time.Time) (string, bool)

Offer returns the tag to propose to the user: a release newer than current that they did not skip, outside a snooze.

func (*State) Refresh

func (st *State) Refresh(ctx context.Context, c *Client, now time.Time)

Refresh asks GitHub for the latest release when the check is due and records the answer. When GitHub cannot be reached the check is tried again in an hour, not at every start.

func (State) Save

func (st State) Save(path string) error

Save writes the state. A failure is returned but is never worth stopping the program for.

Jump to

Keyboard shortcuts

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