update

package
v0.1.876 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package update keeps magpie current. Builds are published as GitHub releases of yetone/magpie-releases; usemagpie.ai/api/latest describes the newest one: its version, notes, and every file with its SHA-256.

The macOS app replaces its own bundle: the new zip is downloaded, checked against its hash, unpacked, and accepted only if it is signed by the same team as the app already installed. A bare binary (the terminal build, and the desktop app on Windows and Linux) replaces itself the same way, minus the signature.

Index

Constants

View Source
const MaxNotes = 40

MaxNotes is how many releases' notes are shown at most: magpie releases often, and a long-unopened one would have pages of them.

View Source
const Site = "https://usemagpie.ai"

Site is magpie's home; its /api/latest is the update feed.

Variables

View Source
var ErrCanceled = errors.New("the update was canceled")

ErrCanceled is the administrator's password prompt dismissed.

View Source
var GUI bool

GUI says this binary has the desktop app in it. Off the Mac that app is a single binary too, and it updates from its own build, not the terminal one.

Functions

func Alive added in v0.1.550

func Alive(pid int) bool

Alive reports whether the process pid is still running.

func AppAsset

func AppAsset() string

AppAsset and BinaryAsset name the files this machine would install.

func AwaitPredecessor added in v0.1.3

func AwaitPredecessor()

AwaitPredecessor blocks, for a while at most, until the magpie that relaunched this one has exited.

func BinaryAsset

func BinaryAsset() string

func Bundle

func Bundle() string

Bundle is the .app the running binary lives in, or "" when it is not in one.

func CanElevate added in v0.1.38

func CanElevate() bool

CanElevate reports whether this system can ask for the administrator's password: always on a Mac, with polkit on Linux, not on Windows.

func CheckMirror added in v0.1.775

func CheckMirror(prefix string) error

CheckMirror says what is wrong with a mirror prefix, nil when it is one.

func CheckProxy added in v0.1.775

func CheckProxy(proxy string) error

CheckProxy says what is wrong with a proxy address, nil when it is one.

func CopiedCLI added in v0.1.709

func CopiedCLI() string

CopiedCLI is the command's path when it's a plain copied file rather than install.sh's link, or "" when it's absent, a link, or not a regular file. A bare Lstat — nothing is run, nothing is written — so the app's window can ask on every launch. It can't tell a stale copy from a current one (that needs the copy's version, which only `magpie update` may read), so what the window says off it is advice with a dismiss, not a warning that knows. Only on the Mac; on Linux the app and the command are one file.

func Executable added in v0.1.3

func Executable() (string, error)

Executable is the running binary, symlinks resolved.

func Feed

func Feed() string

Feed is where the newest release is described. MAGPIE_UPDATE_FEED points it elsewhere, for testing an update against a local server.

func Homebrew added in v0.1.126

func Homebrew(exe string) bool

Homebrew is whether exe was installed by Homebrew (brew install magpie), which keeps it in its Cellar and has to be the one to upgrade it: a binary replaced under it leaves brew thinking the old version is there.

func InLang added in v0.1.627

func InLang(md, lang string) string

InLang is a release's notes in lang, as the site cuts them (a site from before it did, or a feed elsewhere, hands them whole): "zh" the Chinese where there is some, else the English, everything above the marker. Notes from before the marker are English alone, in any language.

func Install

func Install(staged, bundle string) error

Install swaps the staged app in for bundle. The running copy keeps going until it quits; the next launch is the new one. Where the folder is not magpie's to change the error is a permission one (NeedsAdmin), and InstallAsAdmin can do it instead.

func InstallAsAdmin added in v0.1.38

func InstallAsAdmin(staged, bundle string) error

InstallAsAdmin is Install with the administrator's password, asked for by the system.

func InstallBinary added in v0.1.3

func InstallBinary(staged, exe string) error

InstallBinary swaps a staged binary in for exe, the running one, which keeps going until it exits.

func InstallBinaryAsAdmin added in v0.1.38

func InstallBinaryAsAdmin(staged, exe string) error

InstallBinaryAsAdmin is InstallBinary with the administrator's password.

func Mirror added in v0.1.775

func Mirror(ctx context.Context) string

Mirror is the mirror downloads under ctx go through, "" for none.

func NeedsAdmin added in v0.1.38

func NeedsAdmin(err error) bool

NeedsAdmin reports whether err is magpie not being allowed to change the folder it lives in, which the administrator's password gets past.

func Newer

func Newer(a, b string) bool

Newer reports whether version a comes after b. A pre-release comes before the release it leads up to.

func NotesFeed added in v0.1.606

func NotesFeed() string

NotesFeed is where the notes of past releases are listed: beside the update feed, on magpie's site. MAGPIE_NOTES_FEED points it elsewhere.

func Reexec added in v0.1.191

func Reexec(exe string, args, env []string) error

Reexec runs exe in this process's place with args and env: the same process, in the same terminal or under the same service manager, now running the new version (magpie web's restart to update).

func Relaunch

func Relaunch(bundle string) error

Relaunch opens bundle again once this process (pid) has exited.

func RelaunchArgs added in v0.1.458

func RelaunchArgs(window bool, view string) []string

RelaunchArgs is what RelaunchBinary starts magpie with: `gui [view]` for the window, `tray` for the tray icon alone.

func RelaunchBinary added in v0.1.3

func RelaunchBinary(exe string, window bool, view string) error

RelaunchBinary starts exe again: with its window on view when window is set (the window was open), else as the tray app alone, as autostart starts it. The new process waits for this one to exit before it takes the gateway's port; see AwaitPredecessor.

func ReleasePage added in v0.1.741

func ReleasePage(version string) string

ReleasePage is version's page on GitHub, where its notes are when the site can't give them (#661).

func Released

func Released(v string) bool

Released reports whether v is a release version rather than a build from source ("dev", "0bcb2cc-dirty", git describe's "v0.1.0-3-g0bcb2cc"); only releases update themselves.

func RemoveOld added in v0.1.92

func RemoveOld(exe string)

RemoveOld removes what earlier updates moved aside of exe, those no longer running.

func RemoveStaleNew added in v0.1.107

func RemoveStaleNew(exe string)

RemoveStaleNew removes exe.new when it is exe over again: the update a magpie left running from before it downloaded once more.

func ReplaceBinary

func ReplaceBinary(ctx context.Context, rel *Release) error

ReplaceBinary puts the release's build for this binary where the running one is.

func Replaced added in v0.1.107

func Replaced(exe string, started os.FileInfo) bool

Replaced reports whether exe is no longer the binary that was there when this process looked (started, from os.Stat): another magpie installed an update over it, and this one runs from where it was moved aside.

func ShowNotes added in v0.1.606

func ShowNotes(last, current string, existed bool) (after string, show bool)

ShowNotes decides, as magpie starts on current having last run as last ("" when it never said), whether to show what changed since, and from which version on (exclusive). Only an upgrade between releases shows: not a fresh install, the same version again, a downgrade, or a build from source. A magpie from before versions were kept has no last; when it was already in use (existed) its own version's notes are shown, from "", which Between takes as upto's alone.

func Stage

func Stage(ctx context.Context, rel *Release, bundle string) (string, error)

Stage downloads the app in rel and unpacks it next to the installed bundle, ready for Install. It returns the unpacked app.

func StageBinary added in v0.1.3

func StageBinary(ctx context.Context, rel *Release) (string, error)

StageBinary downloads the release's build for this binary next to it (or to the cache, where magpie may not write there), ready for InstallBinary.

func StaleCLI added in v0.1.709

func StaleCLI(appVersion string) string

StaleCLI is the path of a `magpie` command that is a copied file behind the app, or "" when there's nothing to say. install.sh links the command to magpie.app's binary so it follows every GUI update for free; a command that arrived as a copy — an older installer, a hand cp, or the standalone magpie-cli build — keeps running its own build once the app moves on, and a command behind the app is a stale build: one that predates the WebDAV short-write check (#531) truncated a remote backup on `magpie webdav now`, wedging the sync.

A copy is only worth mentioning when it actually trails the app, so this reads the copy's version and stays quiet when it is at or ahead of appVersion, or isn't a release at all (a build from source, or one that won't run — none of those is a stale release to nag about). Reading the version runs the old binary, and that isn't read-only: magpie's start-up runs its migrations before `version` answers. So only `magpie update`, which the user started, asks this — the app's window uses CopiedCLI and its advice can be dismissed instead. magpie doesn't rewrite the user's PATH — the fix is theirs: re-run install.sh, or link it by hand, which is what the advice says. Only on the Mac, where the app and the command are two places; on Linux they are one file.

func StripInstall added in v0.1.606

func StripInstall(md string) string

StripInstall takes a release's "Install" section (in any language) out of its notes: the download links, which mean nothing to a magpie that just updated itself. The section runs to the next heading of its level or above.

func Stuck added in v0.1.38

func Stuck(bundle string) string

Stuck says why the app at bundle cannot be replaced where it is, or "" when it can: opened from its disk image, or moved aside by macOS (App Translocation) because it was never moved out of Downloads.

func WithMirror added in v0.1.775

func WithMirror(ctx context.Context, prefix string) context.Context

WithMirror has the downloads made under ctx go through the mirror prefix; "off" goes through none, whatever Settings say, and "" leaves ctx as it is.

func WithProgress added in v0.1.17

func WithProgress(ctx context.Context, f func(done, total int64)) context.Context

WithProgress has downloads made under ctx report how far along they are; total is 0 while the size is unknown.

func WithProxy added in v0.1.775

func WithProxy(ctx context.Context, proxy string) context.Context

WithProxy has the update feed and the downloads asked under ctx go through proxy (http://, https://, socks5://, socks5h://; host:port is http; "direct" for none), over Settings' Proxy and the environment's.

func Writable

func Writable(dir string) bool

Writable reports whether magpie may replace what lives in dir.

Types

type Asset

type Asset struct {
	URL    string `json:"url"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
}

Asset is one downloadable file of a release.

type Note added in v0.1.606

type Note struct {
	Version string `json:"version"` // no v
	Notes   string `json:"notes"`   // markdown, its Install section taken out
	URL     string `json:"url,omitempty"`
}

Note is one release's notes, as the app shows them after an update.

func Between added in v0.1.606

func Between(notes []Note, after, upto string) []Note

Between keeps the notes of the releases after after up to and including upto, newest first, at most MaxNotes; with after "" only upto's. Each one's Install section is taken out, and one left empty is dropped.

func NotesBetween added in v0.1.606

func NotesBetween(ctx context.Context, after, upto, lang string) ([]Note, error)

NotesBetween asks the site for the notes of every release after after (none when "") up to and including upto, newest first, in lang (see InLang).

type Release

type Release struct {
	Version string           `json:"version"` // "0.2.0", no v
	Notes   string           `json:"notes"`   // markdown
	URL     string           `json:"url"`     // the release page
	Assets  map[string]Asset `json:"assets"`  // by file name
}

Release is one published version.

func Latest

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

Latest asks the feed for the newest release, its notes in English.

func LatestIn added in v0.1.627

func LatestIn(ctx context.Context, lang string) (*Release, error)

LatestIn asks the feed for the newest release, its notes in lang (see InLang): the app's language, which What's new follows.

Jump to

Keyboard shortcuts

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