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
- func AssetName(goos, goarch string) string
- func ChecksumFor(sums, file string) (string, error)
- func CleanupOld(exePath string)
- func CurrentExecutable() (string, error)
- func IsRelease(raw string) bool
- func Newer(current, latest string) bool
- func Replace(exePath, newPath string) error
- func StatePath(runtimeRoot string) string
- type Client
- type Release
- type State
Constants ¶
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 )
const DefaultRepo = "KPO-Tech/seshat-runtime"
DefaultRepo is the repository the releases are read from.
const OldSuffix = ".old"
OldSuffix marks the previous binary kept aside during a replacement.
Variables ¶
This section is empty.
Functions ¶
func AssetName ¶
AssetName is the name of the binary of a release for a platform, as the release workflow and the installers name it.
func ChecksumFor ¶
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 ¶
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 ¶
IsRelease reports whether raw is a release version (vMAJOR.MINOR.PATCH...), as opposed to a development build.
func Newer ¶
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 ¶
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.
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 (*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.
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 (State) Offer ¶
Offer returns the tag to propose to the user: a release newer than current that they did not skip, outside a snooze.