Documentation
¶
Overview ¶
Package selfupdate finds the desktop app's newest release, verifies it with the release's Sigstore signature, and installs it over the running app when enbu manages the installation itself.
Index ¶
- Constants
- Variables
- func AssetName(version, goos, goarch string) (string, bool)
- func ChecksumFor(checksums []byte, name string) ([]byte, error)
- func CleanUp(target string)
- func Install(ctx context.Context, goos string, archive *os.File, target string) error
- func IsRelease(version string) bool
- func Newer(current, latest string) bool
- func Relaunch(executable string) error
- func Target(goos, executable string) (string, bool)
- func VerifyChecksums(trusted root.TrustedMaterial, checksums, bundleJSON []byte) error
- func VerifyFile(r io.Reader, want []byte) error
- func WaitForPrevious(c clock.Clock, timeout time.Duration)
- type Installation
- type Method
- type Release
- type Status
- type Updater
Constants ¶
const Repository = "enbu-net/enbu"
Repository is where the desktop app is released.
Variables ¶
var ErrDownload = errors.New("download failed")
ErrDownload marks a failure to reach GitHub or to download a release file; trying again later may work.
var ErrNotSelfManaged = errors.New("this installation is not updated by the app")
ErrNotSelfManaged means the installation is updated some other way.
var ErrUnverified = errors.New("update failed verification")
ErrUnverified marks an update whose signature or checksum did not match; nothing of it is installed.
Functions ¶
func AssetName ¶
AssetName is the desktop archive a release builds for one platform; the names come from .github/workflows/release-build.yaml.
func ChecksumFor ¶
ChecksumFor finds a file's SHA-256 in a sha256sum listing.
func CleanUp ¶
func CleanUp(target string)
CleanUp removes what an earlier update left beside target: the old Windows binary, which could not be deleted while it ran, and a new copy an interrupted update did not rename into place.
func Install ¶
Install replaces target (see Target) with the app in a verified release archive. It reads the archive through the handle that was verified, not by its name, so the file cannot be swapped in between (the disk image, which hdiutil opens by name, lives in the user's private cache directory). The new copy is written beside target first and then renamed into place, so a failure leaves the running app as it was.
func IsRelease ¶
IsRelease reports whether version names a release (vMAJOR.MINOR.PATCH, without a prerelease or build suffix such as -dirty).
func Relaunch ¶
Relaunch starts executable again, telling it to wait until this process has exited. The caller quits right after.
func Target ¶
Target is what an update replaces: the .app bundle on macOS, the binary elsewhere. ok is false for a macOS binary outside an app bundle.
func VerifyChecksums ¶
func VerifyChecksums(trusted root.TrustedMaterial, checksums, bundleJSON []byte) error
VerifyChecksums checks the Sigstore bundle of checksums.txt against the trusted root: a Fulcio certificate for the release workflow, an SCT, and an entry in the Rekor transparency log.
func VerifyFile ¶
VerifyFile checks that r hashes to want.
Types ¶
type Installation ¶
type Installation struct {
GOOS string
Version string
Executable string // the running binary, symlinks resolved
// Writable reports whether this user may create and rename files in dir.
Writable func(dir string) bool
// Exists reports whether a path exists.
Exists func(path string) bool
}
Installation is what Detect looks at; the fields are inputs so that tests can describe any machine.
type Method ¶
type Method string
Method says who updates an installation, and so what the app may offer.
const ( // MethodSelf: unpacked from a release archive into a place this user may // write; the app replaces itself. MethodSelf Method = "self" // MethodHomebrew: installed with Homebrew; `brew upgrade` updates it. MethodHomebrew Method = "homebrew" // MethodSystemPackage: installed from the .deb or .rpm; the system's // package manager updates it. MethodSystemPackage Method = "system_package" // MethodEditor: the enbu binary inside an editor extension (VS Code), // which the editor's extension updates replace. MethodEditor Method = "editor" // MethodDevelopment: a build without a release version. MethodDevelopment Method = "development" // MethodManual: a release build in a place this user may not write; // the person downloads the release. MethodManual Method = "manual" )
func Detect ¶
func Detect(in Installation) Method
Detect decides who updates the installation. The checks go from the most specific to the most general: a build without a release version never updates, a package manager's files belong to it, and only then may the app replace itself where it can write.
type Release ¶
type Release struct {
Version string
URL string // the release page
Assets map[string]string // file name -> download URL
}
Release is a published release and the files the updater needs from it.
type Status ¶
type Status struct {
Method Method `json:"method"`
Current string `json:"current"`
// Latest is empty when the method does not look for releases
// (development builds and editor extensions).
Latest string `json:"latest,omitempty"`
// Available is true when Latest is newer than Current.
Available bool `json:"available"`
URL string `json:"url,omitempty"`
}
Status is what a check found.
type Updater ¶
type Updater struct {
Client *http.Client
Method Method
Version string
GOOS string
GOARCH string
// Target is what Install replaces (see Target).
Target string
// CacheDir keeps the Sigstore trusted root and the downloads.
CacheDir string
// TrustedRoot returns the Sigstore trusted root; nil fetches it over
// TUF (the root of trust embedded in sigstore-go), cached in CacheDir.
TrustedRoot func(ctx context.Context) (root.TrustedMaterial, error)
// Clock bounds the release lookup; nil uses the real clock.
Clock clock.Clock
// contains filtered or unexported fields
}
Updater checks for and installs releases of one installation.