Documentation
¶
Overview ¶
Package update keeps shed current. It checks GitHub for new releases, downloads them and verifies their signed checksums, and swaps the shed binary on disk. Restarting into the new binary is up to the caller.
Index ¶
- Variables
- type Config
- type Release
- type Settings
- type State
- type Status
- type Updater
- func (u *Updater) Check(ctx context.Context) (Status, error)
- func (u *Updater) Download(ctx context.Context) (Status, error)
- func (u *Updater) Install(ctx context.Context) (Status, error)
- func (u *Updater) Run(ctx context.Context)
- func (u *Updater) SetAutoDownload(ctx context.Context, on bool) (Status, error)
- func (u *Updater) Status(ctx context.Context) (Status, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupported means this build cannot update itself. ErrUnsupported = errors.New("update: this build cannot update itself") // ErrNoUpdate means there is no newer release to download. ErrNoUpdate = errors.New("update: no newer release") // ErrBusy means a check, download, or install is already in progress. ErrBusy = errors.New("update: an update operation is in progress") // ErrNotStaged means no release has been downloaded to install. ErrNotStaged = errors.New("update: no update has been downloaded") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Repo is the GitHub repository releases are published to, "owner/name".
Repo string
// Version is the running version, a semver tag such as "v1.2.3".
// Anything else is a development build, which cannot update itself.
Version string
// PublicKey is the minisign public key that signs checksums.txt.
PublicKey string
// Binary is the path of the shed binary that Install replaces.
Binary string
// Dir holds downloaded releases until they are installed.
Dir string
Settings Settings
// HTTPClient makes the GitHub requests. Nil means a client with a
// 10-minute timeout.
HTTPClient *http.Client
// APIURL is the GitHub API base URL. Empty means api.github.com.
APIURL string
// Interval is the time between background checks. Zero means 6 hours.
Interval time.Duration
Log *slog.Logger
}
Config configures an Updater.
type Release ¶
type Release struct {
// Version is the release tag, such as "v1.2.3".
Version string
URL string
Notes string
PublishedAt time.Time
// contains filtered or unexported fields
}
Release is a published shed release.
type Settings ¶
type Settings interface {
// Setting returns the value of key, and false if it is not set.
Setting(ctx context.Context, key string) (string, bool, error)
SetSetting(ctx context.Context, key, value string) error
}
Settings stores the update preferences.
type Status ¶
type Status struct {
Current string
// Latest is the latest release, or nil until a check finds one.
Latest *Release
// Available reports whether Latest is newer than Current.
Available bool
// CheckedAt is the time of the last successful check.
CheckedAt time.Time
State State
// Staged is the version downloaded, verified, and ready to install.
Staged string
// Err is the last check or download failure.
Err string
AutoDownload bool
// Unsupported says why this build cannot update itself, or is empty.
Unsupported string
}
Status reports the running version, the latest release, and the progress of updating to it.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater checks for, downloads, and installs shed releases.
func (*Updater) Check ¶
Check asks GitHub for the latest release and, with automatic downloads on, starts downloading it if it is newer. A failed check is returned and also reported in the status.
func (*Updater) Download ¶
Download starts downloading the latest release in the background, unless it is already downloaded. Run performs the download.
func (*Updater) Install ¶
Install replaces the shed binary with the downloaded release, keeping the replaced one next to it with a .prev suffix. On success the Updater stays in the Restarting state: the caller is expected to restart shed.
func (*Updater) Run ¶
Run checks for a new release a minute after it starts and then periodically, and performs downloads, until ctx is done. It does nothing for builds that cannot update themselves.
func (*Updater) SetAutoDownload ¶
SetAutoDownload turns automatic downloads on or off. Turning them on starts downloading a newer release that is already known.