diff --git a/README.md b/README.md
index 760f09c9b..82b0cc769 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,7 @@ Runs on macOS, Windows and Linux (menu bar app, window, TUI, web UI and CLI), in
curl -fsSL https://usemagpie.ai/install.sh | sh
```
-Mac builds are signed and notarised, and every build updates itself. On Linux the script installs the desktop app, and on a desktop without WebKitGTK 4.1 installs it first with your package manager (sudo asks for your password); with no desktop, or no terminal to ask at, it installs the terminal build and says which package to add. `--gui` or `--tui` chooses. Behind a firewall, use `--proxy` or `--mirror`. Or `go install github.com/yetone/magpie@latest`, or the [Docker image](https://usemagpie.ai/docs/docker). Remove what the script installed with `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall`; your settings in `~/.config/magpie` stay unless you add `--purge`, which disconnects your agents and deletes them too.
+Mac builds are signed and notarised, and every build updates itself. On Linux the script installs the desktop app, and on a desktop without WebKitGTK 4.1 installs it first with your package manager (sudo asks for your password); with no desktop, or no terminal to ask at, it installs the terminal build and says which package to add. `--gui` or `--tui` chooses. Behind a firewall, use `--proxy` or `--mirror`. Or `go install github.com/yetone/magpie@latest`, or the [Docker image](https://usemagpie.ai/docs/docker). Remove magpie with `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall`: it puts your agents back as they were, then takes off what the script installed (with magpie deleted already, it downloads one to put them back); your settings in `~/.config/magpie` stay unless you add `--purge`.
**2 · Add a provider.** Open magpie and go to **Providers → Add provider**. Pick a preset and paste a key, or sign in with a subscription.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 63b8764be..4a1d1c6f0 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -52,7 +52,7 @@
curl -fsSL https://usemagpie.ai/install.sh | sh
```
-Mac 版已签名并公证,每个版本都会自动更新。Linux 上脚本装桌面版,桌面上没装 WebKitGTK 4.1 时会先用系统的包管理器装上(sudo 会要密码);没有桌面或没有终端可问时装终端版,并告诉你该装哪个包。用 `--gui` 或 `--tui` 可以自己选。网络受限时可用 `--proxy` 或 `--mirror`。也可以 `go install github.com/yetone/magpie@latest`,或者用 [Docker 镜像](https://usemagpie.ai/docs/zh/docker)。 用 `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall` 卸载脚本装上的东西;`~/.config/magpie` 里的设置会保留,加 `--purge` 才会断开 Agent 并一起删除。
+Mac 版已签名并公证,每个版本都会自动更新。Linux 上脚本装桌面版,桌面上没装 WebKitGTK 4.1 时会先用系统的包管理器装上(sudo 会要密码);没有桌面或没有终端可问时装终端版,并告诉你该装哪个包。用 `--gui` 或 `--tui` 可以自己选。网络受限时可用 `--proxy` 或 `--mirror`。也可以 `go install github.com/yetone/magpie@latest`,或者用 [Docker 镜像](https://usemagpie.ai/docs/zh/docker)。 用 `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall` 卸载:先把 Agent 恢复成原来的配置,再拿掉脚本装上的东西(magpie 已被删掉时会临时下载一个来恢复);`~/.config/magpie` 里的设置会保留,加 `--purge` 才一起删除。
**2 · 添加 provider**。打开 magpie,进入 **Providers → 添加 provider**。选一个预设、粘贴 key,或者登录一个订阅。
diff --git a/internal/cli/main.go b/internal/cli/main.go
index e5a3090a3..4c0375f74 100644
--- a/internal/cli/main.go
+++ b/internal/cli/main.go
@@ -74,6 +74,7 @@ const usage = `magpie — one place to pick every agent's model
magpie restore [--no-agents] [--no-library] put a backup in on this machine
--sign-ins on backup: the subscriptions' and plugins' sign-ins too, sealed (off unless given); --no-sign-ins on restore leaves them out
magpie uninstall [--yes] disconnect every agent, putting back what each had, then remove magpie's service and files
+ --keep-data: all but deleting magpie's settings, providers and usage
magpie webdav [on |set k=v…|now|off] the same, kept the same on every computer through a WebDAV folder (magpie webdav help)
magpie s3 [on s3://[/]|set k=v…|now|off] the same through an S3-compatible bucket: AWS, R2, B2, MinIO… (magpie s3 help)
magpie github [on github:///[/]|set k=v…|now|off] the same in an encrypted GitHub repository (magpie github help)
diff --git a/internal/cli/uninstall_cli.go b/internal/cli/uninstall_cli.go
index fd44b4454..29204a7c9 100644
--- a/internal/cli/uninstall_cli.go
+++ b/internal/cli/uninstall_cli.go
@@ -15,26 +15,31 @@ import (
"github.com/yetone/magpie/internal/uninstall"
)
-const uninstallUsage = "usage: magpie uninstall [--yes]"
+const uninstallUsage = "usage: magpie uninstall [--yes] [--keep-data]"
// what uninstallCmd asks of the system; the tests put fakes in
var (
servedBy = gateway.ServedBy
serviceStatus = daemon.Get
runUninstall = uninstall.Run
+ runKeepData = uninstall.KeepData
)
// magpie uninstall [--yes]: every agent disconnected and put back as it
// was, magpie's service, login item and shortcuts removed, then its own
// files (uninstall.Run). Deleting magpie's folders by hand left Codex
// pointed at a gateway that was gone (Jevik_AI on X). It asks first on a
-// terminal; with no terminal to ask on, only --yes does it.
+// terminal; with no terminal to ask on, only --yes does it. --keep-data
+// does all but deleting its files, for install.sh --uninstall, which keeps
+// them for a magpie installed again.
func uninstallCmd(args []string) error {
- yes := false
+ yes, keepData := false, false
for _, a := range args {
switch a {
case "--yes", "-y":
yes = true
+ case "--keep-data":
+ keepData = true
default:
return fmt.Errorf("unknown %q: nothing was changed\n%s", a, uninstallUsage)
}
@@ -60,8 +65,14 @@ func uninstallCmd(args []string) error {
}
connected := uninstall.Connected()
remove, keep := uninstall.Folders()
+ if keepData {
+ remove, keep = nil, ""
+ }
if !yes {
if !term.IsTerminal(int(os.Stdin.Fd())) {
+ if keepData {
+ return fmt.Errorf("this disconnects every agent and removes magpie's service and shortcuts; run it with --yes to do so without being asked")
+ }
return fmt.Errorf("this disconnects every agent and deletes magpie's settings, providers and usage; run it with --yes to do so without being asked")
}
fmt.Println("This takes magpie off this computer:")
@@ -79,13 +90,22 @@ func uninstallCmd(args []string) error {
if keep != "" {
fmt.Println(" · keeps", keep, "(skills and servers your agents use)")
}
- fmt.Print("Uninstall magpie? Your providers, keys and usage in magpie can't be brought back. [y/N] ")
+ if keepData {
+ fmt.Println(" · keeps magpie's settings, providers and usage, for a magpie installed again")
+ fmt.Print("Uninstall magpie? [y/N] ")
+ } else {
+ fmt.Print("Uninstall magpie? Your providers, keys and usage in magpie can't be brought back. [y/N] ")
+ }
line, _ := stdin().ReadString('\n')
if a := strings.ToLower(strings.TrimSpace(line)); a != "y" && a != "yes" {
return fmt.Errorf("nothing was changed")
}
}
- r := runUninstall(context.Background())
+ run := runUninstall
+ if keepData {
+ run = runKeepData
+ }
+ r := run(context.Background())
for _, l := range r.Says() {
switch {
case strings.HasPrefix(l, "✓"):
@@ -99,13 +119,18 @@ func uninstallCmd(args []string) error {
if r.CodexApp {
fmt.Println(amber.Render("!"), "the Codex app is still on what it read before: quit it and open it again")
}
- if r.Exe != "" {
+ // install.sh --uninstall deletes magpie itself after this (a
+ // downloaded copy too) and says so, so the lines about it are its own.
+ script := os.Getenv("MAGPIE_UNINSTALL_SCRIPT") == "1"
+ if r.Exe != "" && !script {
fmt.Println(muted.Render(" magpie itself is left at " + r.Exe + ": delete it to finish"))
}
if r.Failed() {
return fmt.Errorf("some of magpie couldn't be taken off; what is marked ! above is left")
}
- fmt.Println(green.Render("✓"), "magpie is uninstalled")
+ if !script {
+ fmt.Println(green.Render("✓"), "magpie is uninstalled")
+ }
return nil
}
diff --git a/internal/cli/uninstall_cli_test.go b/internal/cli/uninstall_cli_test.go
index 37a75ac17..49a56ab04 100644
--- a/internal/cli/uninstall_cli_test.go
+++ b/internal/cli/uninstall_cli_test.go
@@ -15,14 +15,51 @@ import (
func fakeUninstall(t *testing.T, served gateway.Served, service daemon.Status) *int {
t.Helper()
ran := 0
- wasServed, wasStatus, wasRun := servedBy, serviceStatus, runUninstall
- t.Cleanup(func() { servedBy, serviceStatus, runUninstall = wasServed, wasStatus, wasRun })
+ wasServed, wasStatus, wasRun, wasKeep := servedBy, serviceStatus, runUninstall, runKeepData
+ t.Cleanup(func() { servedBy, serviceStatus, runUninstall, runKeepData = wasServed, wasStatus, wasRun, wasKeep })
servedBy = func() gateway.Served { return served }
serviceStatus = func() (daemon.Status, error) { return service, nil }
runUninstall = func(context.Context) *uninstall.Report { ran++; return &uninstall.Report{} }
+ runKeepData = func(context.Context) *uninstall.Report { ran += 100; return &uninstall.Report{} }
return &ran
}
+// install.sh --uninstall keeps magpie's settings, and took the gateway
+// away with Codex still pointed at it (whimsical_wolf_15477 on Discord):
+// --keep-data disconnects every agent and deletes none of magpie's files.
+func TestUninstallKeepData(t *testing.T) {
+ ran := fakeUninstall(t, gateway.Served{}, daemon.Status{})
+ if err := uninstallCmd([]string{"--yes", "--keep-data"}); err != nil || *ran != 100 {
+ t.Fatalf("err %v, ran %d", err, *ran)
+ }
+ // without --yes and no terminal: nothing, and the refusal doesn't
+ // say the settings go
+ ran = fakeUninstall(t, gateway.Served{}, daemon.Status{})
+ err := uninstallCmd([]string{"--keep-data"})
+ if err == nil || strings.Contains(err.Error(), "deletes") || *ran != 0 {
+ t.Fatalf("err %v, ran %d", err, *ran)
+ }
+}
+
+// install.sh --uninstall deletes magpie after it runs, a downloaded copy
+// in a temporary folder too: under the script, magpie doesn't tell the
+// user to delete a path that is about to be gone.
+func TestUninstallScriptLeavesExeToIt(t *testing.T) {
+ fakeUninstall(t, gateway.Served{}, daemon.Status{})
+ runKeepData = func(context.Context) *uninstall.Report {
+ return &uninstall.Report{Exe: "/tmp/tmp.x/magpie-cli-linux-amd64"}
+ }
+ out, err := stdoutOf(t, func() error { return uninstallCmd([]string{"--yes", "--keep-data"}) })
+ if err != nil || !strings.Contains(out, "/tmp/tmp.x/magpie-cli-linux-amd64") {
+ t.Fatalf("by hand: err %v, out %q", err, out)
+ }
+ t.Setenv("MAGPIE_UNINSTALL_SCRIPT", "1")
+ out, err = stdoutOf(t, func() error { return uninstallCmd([]string{"--yes", "--keep-data"}) })
+ if err != nil || strings.Contains(out, "magpie-cli-linux-amd64") || strings.Contains(out, "magpie is uninstalled") {
+ t.Fatalf("under the script: err %v, out %q", err, out)
+ }
+}
+
// A magpie still serving that isn't the background service, which
// uninstalling removes first, would keep writing its files after its
// folders are gone: it is quit first, and nothing is changed.
@@ -59,10 +96,11 @@ func TestUninstallAsksFirst(t *testing.T) {
}
}
-// --help prints its usage and uninstalls nothing.
+// --help prints its usage and uninstalls nothing; install.sh reads
+// --keep-data in it to know this magpie can disconnect and keep its files.
func TestUninstallHelp(t *testing.T) {
ran := fakeUninstall(t, gateway.Served{}, daemon.Status{})
- if !helpAsked([]string{"uninstall", "--help"}) || !strings.Contains(helpFor([]string{"uninstall"}), "magpie uninstall [--yes]") || *ran != 0 {
+ if !helpAsked([]string{"uninstall", "--help"}) || !strings.Contains(helpFor([]string{"uninstall"}), "magpie uninstall [--yes]") || !strings.Contains(helpFor([]string{"uninstall"}), "--keep-data") || *ran != 0 {
t.Fatal("no help for uninstall")
}
}
diff --git a/internal/uninstall/uninstall.go b/internal/uninstall/uninstall.go
index 65aced3fa..279198808 100644
--- a/internal/uninstall/uninstall.go
+++ b/internal/uninstall/uninstall.go
@@ -282,6 +282,20 @@ func Run(ctx context.Context) *Report {
return r
}
+// KeepData is Run without Data: every agent put back as it was and
+// magpie's service, login item and shortcuts removed, with its settings,
+// providers and usage kept for a magpie installed again. install.sh
+// --uninstall runs it, so an agent never stays pointed at a gateway the
+// script took away (whimsical_wolf_15477 on Discord: Codex after
+// uninstalling).
+func KeepData(ctx context.Context) *Report {
+ r := &Report{}
+ System(r)
+ Agents(ctx, r)
+ r.Exe, _ = executable()
+ return r
+}
+
// AfterExit waits for process pid to end, for up to wait, then removes
// magpie's files: what the app starts as it quits.
func AfterExit(pid int, wait time.Duration) *Report {
diff --git a/internal/uninstall/uninstall_test.go b/internal/uninstall/uninstall_test.go
index 845f986c4..04d39f836 100644
--- a/internal/uninstall/uninstall_test.go
+++ b/internal/uninstall/uninstall_test.go
@@ -107,6 +107,25 @@ func TestRunOrder(t *testing.T) {
}
}
+// KeepData, for install.sh --uninstall, does Run's agents and system and
+// leaves magpie's files for a magpie installed again.
+func TestKeepData(t *testing.T) {
+ codex := &agent.Agent{ID: "codex", Name: "Codex"}
+ did := fakes(t, []*agent.Agent{codex}, map[string]bool{"codex": true}, nil)
+ settings := filepath.Join(appdir.Config(), "settings.json")
+ write(t, settings, "{}")
+
+ r := KeepData(context.Background())
+
+ want := []string{"service", "autostart", "shortcut", "scheme", "pii", "failover", "disconnect codex", "rollouts", "codex app"}
+ if !slices.Equal(*did, want) {
+ t.Fatalf("did %q, want %q", *did, want)
+ }
+ if gone(t, settings) || len(r.Data) != 0 || r.Failed() {
+ t.Fatalf("settings gone or data touched: %+v", r)
+ }
+}
+
// An agent that can't be disconnected is said, and the rest are still
// done; Codex not among them leaves the Codex app alone.
func TestRunSaysWhatFailed(t *testing.T) {
diff --git a/site/install.test.mjs b/site/install.test.mjs
index 0965db900..16456a2f6 100644
--- a/site/install.test.mjs
+++ b/site/install.test.mjs
@@ -21,7 +21,7 @@ function systemPath(dir) {
return sys;
}
-function install(t, { termux = true, arch = "aarch64", override = false, prefixOnly = false, missing = false, corrupt = false, desktop = false, github = false, args = [], env: extra = {}, tamper = "", libs = desktop, cli = !desktop, distro = "ID=ubuntu\nID_LIKE=debian\n", sessions = [], login = "", tty = false, uid = 1000, sudo = true, pmFails = false } = {}) {
+function install(t, { termux = true, arch = "aarch64", override = false, prefixOnly = false, missing = false, corrupt = false, desktop = false, github = false, args = [], env: extra = {}, tamper = "", libs = desktop, cli = !desktop, distro = "ID=ubuntu\nID_LIKE=debian\n", sessions = [], login = "", tty = false, uid = 1000, sudo = true, pmFails = false, payload = "test binary\n" } = {}) {
const dir = mkdtempSync(join(tmpdir(), "magpie-install-"));
t.after(() => rmSync(dir, { recursive: true, force: true }));
const tools = join(dir, "tools");
@@ -33,7 +33,6 @@ function install(t, { termux = true, arch = "aarch64", override = false, prefixO
mkdirSync(tools, { recursive: true });
mkdirSync(bin, { recursive: true });
writeFileSync(join(bin, "magpie"), "old installation");
- const payload = "test binary\n";
const cpu = arch === "aarch64" ? "arm64" : "amd64";
const file = termux ? `magpie-cli-android-${cpu}` : desktop ? `magpie-linux-${cpu}` : `magpie-cli-linux-${cpu}`;
const assets = {};
@@ -252,23 +251,33 @@ test("a file the mirror changed is refused and the installed magpie kept", (t) =
// pota on Discord: the script installed magpie and had no way to take it
// off. --uninstall takes off what it put there and keeps the user's
-// settings; --purge has magpie disconnect the agents and delete them first.
+// settings; --purge has magpie delete them too. Both have magpie
+// disconnect the agents first: taken off alone, it left Codex pointed at
+// a gateway that was gone (whimsical_wolf_15477 on Discord).
+//
+// magpie itself, as far as the uninstall asks it anything: in each
+// call it logs; old, one from before --keep-data
+const fakeMagpie = (who, old = false) => `#!/bin/sh
+echo "${who}$*" >> "$HOME/magpie-calls"
+[ "$1 $2" = "uninstall --help" ] && { echo "usage: magpie uninstall [--yes]${old ? "" : " [--keep-data]"}"; exit 0; }
+[ "$1 $2" = "daemon uninstall" ] && rm -f "$XDG_CONFIG_HOME/systemd/user/magpie.service"
+[ "$1 $2 $3" = "uninstall --yes --keep-data" ] && { [ -z "$MAGPIE_FAIL" ] || exit 1; ${old ? "exit 2" : "echo disconnected > \"$HOME/agents\""}; }
+[ "$1 $2 $3" = "uninstall --yes " ] && { [ -z "$MAGPIE_FAIL" ] || exit 1; echo disconnected > "$HOME/agents"; rm -rf "$XDG_CONFIG_HOME/magpie" "$XDG_DATA_HOME/applications/magpie.desktop"; }
+exit 0
+`;
function installedDesktop(t, opts = {}) {
- const r = install(t, { termux: false, desktop: true, ...opts });
+ // sudo: false, the system's tools only: a magpie on this computer's
+ // PATH would be another one
+ const r = install(t, { termux: false, desktop: true, sudo: false, payload: fakeMagpie("downloaded: "), ...opts });
assert.equal(r.status, 0, r.stderr);
const exe = join(r.bin, "magpie");
- // magpie itself, as far as the uninstall asks it anything
- writeFileSync(exe, `#!/bin/sh
-echo "$*" >> "$HOME/magpie-calls"
-[ "$1 $2" = "daemon uninstall" ] && rm -f "$XDG_CONFIG_HOME/systemd/user/magpie.service"
-[ "$1 $2" = "uninstall --yes" ] && { [ -z "$MAGPIE_FAIL" ] || exit 1; rm -rf "$XDG_CONFIG_HOME/magpie" "$XDG_DATA_HOME/applications/magpie.desktop"; }
-exit 0
-`, { mode: 0o755 });
+ writeFileSync(exe, fakeMagpie("", opts.old), { mode: 0o755 });
const settings = join(r.config, "magpie", "settings.json");
mkdirSync(join(r.config, "magpie"), { recursive: true });
writeFileSync(settings, "{}");
const calls = () => (existsSync(join(r.home, "magpie-calls")) ? readFileSync(join(r.home, "magpie-calls"), "utf8") : "");
- return { ...r, exe, settings, calls, entry: join(r.share, "applications/magpie.desktop"), icon: join(r.share, "icons/hicolor/256x256/apps/magpie.png"), mime: join(r.config, "mimeapps.list") };
+ const agents = () => existsSync(join(r.home, "agents"));
+ return { ...r, exe, settings, calls, agents, entry: join(r.share, "applications/magpie.desktop"), icon: join(r.share, "icons/hicolor/256x256/apps/magpie.png"), mime: join(r.config, "mimeapps.list") };
}
test("--uninstall takes off the command, menu entry, icon and magpie:// default, and keeps the settings", (t) => {
@@ -286,7 +295,9 @@ test("--uninstall takes off the command, menu entry, icon and magpie:// default,
assert.equal(bu.status, 0, bu.stderr);
assert.equal(existsSync(bare.mime), false);
assert.ok(existsSync(r.settings), "the settings stay");
- assert.equal(r.calls(), "", "magpie isn't asked to uninstall");
+ assert.match(r.calls(), /^uninstall --yes --keep-data$/m, "magpie disconnects the agents first");
+ assert.ok(r.agents());
+ assert.doesNotMatch(r.calls(), /^uninstall --yes$/m);
assert.equal(u.calls.length, 0, "nothing is downloaded");
assert.match(u.stdout, /kept your settings.*--purge/);
// again: nothing there, nothing wrong
@@ -295,6 +306,85 @@ test("--uninstall takes off the command, menu entry, icon and magpie:// default,
assert.match(again.stdout, /no magpie installed by this script/);
});
+// magpie deleted by hand (or the app dragged to the Trash) left the agents
+// on its gateway, with nothing left to put them back: the newest magpie is
+// downloaded, checked, and does it, and nothing of it stays.
+test("--uninstall with magpie deleted already downloads one to disconnect the agents", (t) => {
+ const r = installedDesktop(t);
+ rmSync(r.exe);
+ const u = r.run(["--uninstall"]);
+ assert.equal(u.status, 0, u.stderr);
+ assert.match(u.requests, /\/api\/latest\n.*magpie-cli-linux-arm64$/m, "the terminal build, which needs no libraries");
+ assert.match(r.calls(), /^downloaded: uninstall --yes --keep-data$/m);
+ assert.ok(r.agents());
+ assert.ok(existsSync(r.settings), "the settings stay");
+ for (const p of [r.entry, r.icon]) assert.equal(existsSync(p), false, p);
+ assert.equal(existsSync(r.exe), false, "the download isn't installed");
+
+ // --purge the same, deleting the settings
+ const p = installedDesktop(t);
+ rmSync(p.exe);
+ const pu = p.run(["--purge"]);
+ assert.equal(pu.status, 0, pu.stderr);
+ assert.match(p.calls(), /^downloaded: uninstall --yes$/m);
+ assert.equal(existsSync(p.settings), false);
+
+ // a download that isn't the release's: never run, nothing taken off
+ const c = installedDesktop(t, { env: {} });
+ rmSync(c.exe);
+ c.env.INSTALL_PAYLOAD = "changed\n";
+ const cu = c.run(["--uninstall"]);
+ assert.notEqual(cu.status, 0);
+ assert.match(cu.stderr, /does not match its checksum/);
+ assert.equal(c.calls(), "");
+ assert.ok(existsSync(c.entry));
+
+ // magpie never run here (no settings): nothing to put back, nothing downloaded
+ const n = installedDesktop(t);
+ rmSync(n.exe);
+ rmSync(join(n.config, "magpie"), { recursive: true });
+ const nu = n.run(["--uninstall"]);
+ assert.equal(nu.status, 0, nu.stderr);
+ assert.equal(nu.calls.length, 0);
+});
+
+// another magpie on the PATH (not this script's) serves the agents still:
+// it is the one to ask, and nothing is downloaded
+test("--uninstall with magpie deleted leaves another magpie's agents to it", (t) => {
+ const r = installedDesktop(t);
+ rmSync(r.exe);
+ const other = join(r.env.PATH.split(":")[0], "magpie");
+ writeFileSync(other, fakeMagpie("other: "), { mode: 0o755 });
+ const u = r.run(["--uninstall"]);
+ assert.equal(u.status, 0, u.stderr);
+ assert.equal(u.calls.length, 0);
+ assert.equal(r.calls(), "");
+ assert.match(u.stdout, /magpie at .*tools\/magpie isn't one this script installed.*uninstall/);
+});
+
+// one from before --keep-data refuses it and changes nothing: the newest
+// does it instead
+test("--uninstall with an older magpie disconnects with the newest", (t) => {
+ const r = installedDesktop(t, { old: true });
+ const u = r.run(["--uninstall"]);
+ assert.equal(u.status, 0, u.stderr);
+ assert.doesNotMatch(r.calls(), /^uninstall --yes --keep-data$/m);
+ assert.match(r.calls(), /^downloaded: uninstall --yes --keep-data$/m);
+ assert.ok(r.agents());
+ assert.ok(existsSync(r.settings));
+ assert.equal(existsSync(r.exe), false);
+});
+
+// magpie unable to (an agent it couldn't put back, an app still open): the
+// command stays, to run it again
+test("--uninstall leaves the install when magpie can't disconnect the agents", (t) => {
+ const f = installedDesktop(t, { env: { MAGPIE_FAIL: "1" } });
+ const fu = f.run(["--uninstall"]);
+ assert.notEqual(fu.status, 0);
+ assert.match(fu.stderr, /couldn't disconnect your agents/);
+ for (const p of [f.exe, f.entry, f.settings]) assert.ok(existsSync(p), p);
+});
+
test("--uninstall takes the service and login entry that start this magpie, never another's", (t) => {
const r = installedDesktop(t);
const unit = join(r.config, "systemd/user/magpie.service");
@@ -344,13 +434,6 @@ test("--purge has magpie uninstall itself first, then takes off the install", (t
assert.match(fu.stderr, /magpie uninstall didn't finish/);
for (const p of [f.exe, f.entry, f.settings]) assert.ok(existsSync(p), p);
- // no magpie to ask: refused, the settings kept
- const n = installedDesktop(t);
- rmSync(n.exe);
- const nu = n.run(["--purge"]);
- assert.notEqual(nu.status, 0);
- assert.match(nu.stderr, /no magpie at .* --uninstall alone/);
- assert.ok(existsSync(n.settings));
});
test("--uninstall in Termux takes off PREFIX/bin/magpie", (t) => {
diff --git a/site/public/docs/ja/start.html b/site/public/docs/ja/start.html
index 720f3eb49..4d5b1fc75 100644
--- a/site/public/docs/ja/start.html
+++ b/site/public/docs/ja/start.html
@@ -297,7 +297,8 @@ magpie claude group/opus-anywhere # これを使う
GTK 3 と WebKitGTK 4.1 が入っていればデスクトップアプリ(ウィンドウ、トレイアイコン、アプリメニューの項目)です。デスクトップがあってもそれらが無いときは、パッケージマネージャー(apt、dnf、pacman、zypper)で sudo を通して WebKitGTK 4.1 を入れ(sudo がパスワードを尋ねます)、それからアプリを入れます。パスワードを尋ねる前に何を入れるかを表示します。端末が無いとき(CI、Dockerfile)、sudo が無いとき、知らないディストリビューションやインストールに失敗したときはターミナル版(magpie tui、magpie web と CLI)を入れ、最後に入れるコマンドを表示します。Debian・Ubuntu なら sudo apt install libwebkit2gtk-4.1-0、Fedora なら sudo dnf install webkit2gtk4.1 です。入れたあとインストーラをもう一度実行するとアプリになります。デスクトップ上で実行しても ssh 越しでも、グラフィカルなセッション、あなたのグラフィカルなログイン、ログインできるデスクトップ環境のどれかがあればデスクトップありと判断します。デスクトップの無いサーバーにはターミナル版です。自分で選ぶには --gui(ライブラリを今入れられなくてもアプリ)か --tui(ターミナル版、パッケージは入れない)を付けます:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --tui。
- スクリプトでインストールした場合:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall で、スクリプトが置いたものを取り除きます。magpie コマンド、macOS ではアプリ、Linux ではメニュー項目・アイコン・magpie:// のハンドラ、それに Linux ではもう無い magpie を起動してしまうサービスとログイン時の起動です。~/.config/magpie の設定・プロバイダ・使用量は残るので、再インストールすれば戻ります。接続したエージェントはそれまで magpie のアドレスを指したままです。--purge を付けると先に magpie uninstall --yes を実行し、すべてのエージェントの接続を外して元の設定に戻してから、magpie の設定・プロバイダ・使用量を削除します。ほかの方法でインストールした場合は、magpie uninstall または Settings → magpie をアンインストール が --purge と同じことを行い、プログラム本体は手動で削除します。
+ スクリプトでインストールした場合:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall は、まず magpie にすべてのエージェントの接続を外させて元の設定に戻し、それからスクリプトが置いたものを取り除きます。magpie コマンド、macOS ではアプリ、Linux ではメニュー項目・アイコン・magpie:// のハンドラ、それに Linux ではもう無い magpie を起動してしまうサービスとログイン時の起動です。~/.config/magpie の設定・プロバイダ・使用量は残るので、再インストールすれば戻ります。--purge を付けるとそれも削除します(magpie uninstall --yes)。ほかの方法でインストールした場合は、magpie uninstall または Settings → magpie をアンインストール が --purge と同じことを行い、プログラム本体は手動で削除します。
+ magpie をもう削除した(アプリをゴミ箱に入れた、フォルダーを消した)のに、エージェントが接続できないと言う場合:macOS と Linux では同じ --uninstall の行を実行してください。magpie が見つからないと最新版を一時フォルダーにダウンロードし(インストールと同じく検証します)、~/.config/magpie に各エージェントの元の設定が残っているうちに、それが元に戻します。Windows では magpie をもう一度ダウンロードして Settings → magpie をアンインストール を使います。Codex を手で戻すには、Codex を終了し、~/.codex/config.toml で # magpie: コメントの下の行(openai_base_url、model_provider = "magpie"、model_catalog_json)を削除して、model を Codex 自身のモデルに戻します。magpie で始めたスレッドを残さないなら [model_providers.magpie] の表も消せます。~/.codex/magpie-models.json を削除し、Codex を開き直します。
magpie のログはどこにありますか?
アプリ(ウィンドウ、メニューバーやトレイのアイコン、パネル。どう開いたかによらず)は app.log を書きます。macOS では ~/Library/Logs/magpie/app.log、Windows では %LOCALAPPDATA%\magpie\logs\app.log、Linux では ~/.local/state/magpie/app.log($XDG_STATE_HOME が設定されていれば $XDG_STATE_HOME/magpie)、ポータブル版ではデータフォルダーの logs です。設定 → 情報 → ログにパスがあり、開くでそのフォルダーを表示します。magpie log はパスを表示し、magpie log -f は追いかけます。5 MiB に達すると隣の app.old.log になり、残るのは最大 2 ファイルです。記録されるのは magpie がしたことと出会ったエラー(プロバイダーがリクエストを断った、再試行した、プラグインが起動しなかった)で、キー、プロンプト、返答は含みません。キーやトークンに見えるものも伏せられます。サービスとして動く magpie serve のログは別の場所です。macOS では ~/Library/Logs/magpie/serve.log、Linux では journalctl --user -u magpie。magpie log はそれも示します。
diff --git a/site/public/docs/start.html b/site/public/docs/start.html
index b67a6ab06..f434c1925 100644
--- a/site/public/docs/start.html
+++ b/site/public/docs/start.html
@@ -297,7 +297,8 @@ magpie claude group/opus-anywhere # use it
The desktop app (window, tray icon and a menu entry) when GTK 3 and WebKitGTK 4.1 are installed. On a computer with a desktop but without them, the installer installs WebKitGTK 4.1 with your package manager (apt, dnf, pacman or zypper), through sudo, which asks for your password, and then the app; it says what it installs before it asks. Run without a terminal (CI, a Dockerfile), without sudo, on another distribution or when that install fails, it installs the terminal build (magpie tui, magpie web and the CLI) and ends with the command that installs them, such as sudo apt install libwebkit2gtk-4.1-0 on Debian and Ubuntu or sudo dnf install webkit2gtk4.1 on Fedora; run the installer again afterwards for the app. A desktop counts whether you run it there or over ssh: a graphical session, your graphical login, or a desktop installed to log in to. A server without one gets the terminal build. To choose yourself, add --gui (the app even when its libraries can't be installed now) or --tui (the terminal build, and no package installed): curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --tui.
- Installed with the script: curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall takes off what it put there: the magpie command, and the app on macOS or its menu entry, icon and magpie:// handler on Linux, with magpie’s service and opening at login there, which would start a magpie that is gone. Your settings, providers and usage in ~/.config/magpie stay, for when you install again; agents you connected keep magpie’s address until then. Add --purge to have magpie uninstall --yes run first: it disconnects every agent and puts back what each had, then deletes magpie’s settings, providers and usage. Installed another way, magpie uninstall or Settings → Uninstall magpie does what --purge does and leaves the program itself for you to delete.
+ Installed with the script: curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall has magpie disconnect every agent and put back what each had first, then takes off what the script put there: the magpie command, and the app on macOS or its menu entry, icon and magpie:// handler on Linux, with magpie’s service and opening at login there, which would start a magpie that is gone. Your settings, providers and usage in ~/.config/magpie stay, for when you install again. Add --purge to delete them too (magpie uninstall --yes). Installed another way, magpie uninstall or Settings → Uninstall magpie does what --purge does and leaves the program itself for you to delete.
+ Deleted magpie already (the app in the Trash, the folder removed) and an agent still says it can’t connect? On macOS and Linux run the same --uninstall line: with no magpie left it downloads the newest to a temporary folder, checked like an install, and that one puts your agents back while magpie’s record of what each had is still in ~/.config/magpie. On Windows, download magpie again and use Settings → Uninstall magpie. To put Codex back by hand, quit it, then in ~/.codex/config.toml delete each line under a # magpie: comment (openai_base_url, model_provider = "magpie", model_catalog_json) and set model to one of Codex’s own; the [model_providers.magpie] table can go too once no thread you keep was started on magpie. Delete ~/.codex/magpie-models.json, and open Codex again.
Where is magpie’s log?
The app (its window, the menu bar or tray icon and the panel, however it was opened) writes app.log: ~/Library/Logs/magpie/app.log on macOS, %LOCALAPPDATA%\magpie\logs\app.log on Windows, ~/.local/state/magpie/app.log on Linux ($XDG_STATE_HOME/magpie when that is set), and logs in a portable magpie’s data folder. Settings → About → Log has its path and an Open that shows its folder; magpie log prints it, and magpie log -f follows it. At 5 MiB it becomes app.old.log beside it, so two files at most are kept. It holds what magpie did and the errors it met (a provider refusing a request, a retry, a plugin that failed to start), not your keys, prompts or replies; what looks like a key or token is masked anyway. magpie serve run as a service logs elsewhere: ~/Library/Logs/magpie/serve.log on macOS, journalctl --user -u magpie on Linux; magpie log names it too.
diff --git a/site/public/docs/zh/start.html b/site/public/docs/zh/start.html
index 474a24531..134f15587 100644
--- a/site/public/docs/zh/start.html
+++ b/site/public/docs/zh/start.html
@@ -297,7 +297,8 @@ magpie claude group/opus-anywhere # 使用它
装了 GTK 3 和 WebKitGTK 4.1 时装桌面版(窗口、托盘图标和应用菜单项)。有桌面但缺这两个库时,脚本会用系统的包管理器(apt、dnf、pacman 或 zypper)通过 sudo 装上 WebKitGTK 4.1(sudo 会要你的密码),再装桌面版;要密码之前会先说要装什么。没有终端(CI、Dockerfile)、没有 sudo、发行版不认识或者装库失败时,先装终端版(magpie tui、magpie web 和命令行),最后给出装库的命令,比如 Debian、Ubuntu 上是 sudo apt install libwebkit2gtk-4.1-0,Fedora 上是 sudo dnf install webkit2gtk4.1;装好后再运行一次安装脚本就换成桌面版。在桌面上运行还是 ssh 进去运行都算有桌面:有图形会话、你登录着图形界面,或者装了可登录的桌面环境。没有桌面的服务器装终端版。想自己选,加 --gui(库现在装不上也装桌面版)或 --tui(装终端版,不装任何系统包):curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --tui。
- 用安装脚本装的:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall 会拿掉它装上的东西:magpie 命令,macOS 上的应用,Linux 上的菜单项、图标和 magpie:// 链接处理,以及 Linux 上会去启动一个已不存在的 magpie 的后台服务和开机启动。~/.config/magpie 里的设置、provider 和用量都保留,重新安装就回来;已连接的 Agent 在那之前仍指向 magpie 的地址。加上 --purge 会先运行 magpie uninstall --yes:断开每个 Agent 并恢复它原来的配置,再删除 magpie 的设置、provider 和用量。用其他方式装的,magpie uninstall 或 设置 → 卸载 magpie 做的就是 --purge 那些事,程序本身留给你删除。
+ 用安装脚本装的:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall 会先让 magpie 断开每个 Agent 并恢复它原来的配置,再拿掉脚本装上的东西:magpie 命令,macOS 上的应用,Linux 上的菜单项、图标和 magpie:// 链接处理,以及 Linux 上会去启动一个已不存在的 magpie 的后台服务和开机启动。~/.config/magpie 里的设置、provider 和用量都保留,重新安装就回来。加上 --purge 会把它们也删掉(magpie uninstall --yes)。用其他方式装的,magpie uninstall 或 设置 → 卸载 magpie 做的就是 --purge 那些事,程序本身留给你删除。
+ 已经把 magpie 删了(应用拖进了废纸篓、文件夹删掉了),Agent 还是连不上?macOS 和 Linux 上运行同一行 --uninstall:找不到 magpie 时它会把最新版下载到临时文件夹(和安装一样校验),由它趁 ~/.config/magpie 里还记着每个 Agent 原来的配置时把它们恢复。Windows 上重新下载 magpie,用 设置 → 卸载 magpie。手动恢复 Codex:先退出 Codex,在 ~/.codex/config.toml 里删掉每条 # magpie: 注释下面的那一行(openai_base_url、model_provider = "magpie"、model_catalog_json),把 model 改回 Codex 自己的模型;没有要保留的、在 magpie 上开的对话时,[model_providers.magpie] 整段也可以删。再删掉 ~/.codex/magpie-models.json,重新打开 Codex。
magpie 的日志在哪里?
应用(窗口、菜单栏或托盘图标、快捷面板,不论怎样打开)写入 app.log:macOS 上是 ~/Library/Logs/magpie/app.log,Windows 上是 %LOCALAPPDATA%\magpie\logs\app.log,Linux 上是 ~/.local/state/magpie/app.log(设置了 $XDG_STATE_HOME 时是 $XDG_STATE_HOME/magpie),便携版则在数据文件夹的 logs 里。设置 → 关于 → 日志里有它的路径,打开会显示它所在的文件夹;magpie log 打印路径,magpie log -f 持续跟随。满 5 MiB 后它变成旁边的 app.old.log,最多保留两个文件。它记的是 magpie 做了什么、遇到了哪些错误(服务商拒绝请求、重试、插件没能启动),不含你的密钥、提示词或回复;看起来像密钥或令牌的内容也会被遮掉。作为服务运行的 magpie serve 日志在别处:macOS 上是 ~/Library/Logs/magpie/serve.log,Linux 上是 journalctl --user -u magpie;magpie log 也会列出它。
diff --git a/site/public/install.sh b/site/public/install.sh
index 4ef044c0b..f9029a351 100644
--- a/site/public/install.sh
+++ b/site/public/install.sh
@@ -29,15 +29,20 @@
# be installed now (it opens once they are)
# --tui the terminal build (TUI, web UI and CLI), on Linux even
# with a desktop (MAGPIE_CLI=1 does the same)
-# --uninstall takes off what this script put there: the magpie
+# --uninstall `magpie uninstall --yes --keep-data` first (every
+# agent disconnected and put back as it was), then
+# takes off what this script put there: the magpie
# command, and the app (macOS) or its menu entry, icon
# and magpie:// handler (Linux), and the service and
# opening at login that would start a magpie no longer
# there. Your settings, providers and usage in
# ~/.config/magpie stay, for when you install again.
-# --purge --uninstall, and before it `magpie uninstall --yes`:
-# every agent disconnected and put back as it was, and
-# magpie's settings, providers and usage deleted.
+# --purge the same with `magpie uninstall --yes`: magpie's
+# settings, providers and usage deleted too.
+# With magpie deleted by hand already (or one too old
+# to keep its files), both download the newest magpie
+# to a temporary folder, checked like an install, to
+# disconnect the agents with; nothing of it stays.
set -eu
site=https://usemagpie.ai
@@ -70,8 +75,9 @@ while [ $# -gt 0 ]; do
" the SHA-256 is still checked against $site's" \
" --gui Linux: the desktop app, even when GTK 3 and WebKitGTK 4.1 can't be installed now" \
" --tui Linux: the terminal build (TUI, web UI, CLI), even on a desktop (or MAGPIE_CLI=1)" \
- " --uninstall take off what this script installed; your settings in ~/.config/magpie stay" \
- " --purge with --uninstall: also disconnect every agent and delete magpie's settings (magpie uninstall)"
+ " --uninstall disconnect every agent, putting back what each had, and take off what this script installed;" \
+ " your settings in ~/.config/magpie stay (a magpie deleted already is downloaded to do it)" \
+ " --purge with --uninstall: also delete magpie's settings, providers and usage (magpie uninstall)"
exit 0 ;;
*) die "unknown option $1 (--gui, --tui, --proxy , --mirror , --uninstall, --purge)" ;;
esac
@@ -108,6 +114,54 @@ esac
share="${XDG_DATA_HOME:-$HOME/.local/share}"
config="${XDG_CONFIG_HOME:-$HOME/.config}"
+case "$(uname -m)" in
+ arm64|aarch64) arch=arm64 ;;
+ x86_64|amd64) arch=amd64 ;;
+ *) arch= ;;
+esac
+
+tmp=
+# fetch : the newest release's downloaded into $tmp and
+# checked against the SHA-256 the site gives, never a mirror's
+fetch() {
+ file=$1
+ if [ -z "$tmp" ]; then
+ tmp=$(mktemp -d)
+ trap 'rm -rf "$tmp"' EXIT
+ fi
+ # the release list and its checksums: always from the site, never a mirror
+ feed=$(get "$site/api/latest") || die "could not reach $site${proxy:+ through $proxy}"
+ # The feed is one line of JSON; pull this file's url and hash out of it.
+ entry=$(printf '%s' "$feed" | sed -n "s/.*\"$file\":{\([^}]*\)}.*/\1/p")
+ url=$(printf '%s' "$entry" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p')
+ sum=$(printf '%s' "$entry" | sed -n 's/.*"sha256":"\([^"]*\)".*/\1/p')
+ version=$(printf '%s' "$feed" | sed -n 's/.*"version":"\([^"]*\)".*/\1/p')
+ if [ "$os" = android ] && { [ -z "$url" ] || [ -z "$sum" ]; }; then
+ die "the newest release has no $file; build in Termux with go build -tags nogui (see $site/docs/start)"
+ fi
+ [ -n "$url" ] && [ -n "$sum" ] || die "the newest release has no $file"
+
+ from=$url
+ case "$url" in
+ https://github.com/*) [ -z "$mirror" ] || from="$mirror$url" ;;
+ esac
+ if [ "$from" != "$url" ]; then say "downloading magpie $version ($file) through $mirror"
+ else say "downloading magpie $version ($file)"; fi
+ get -o "$tmp/$file" "$from" || die "could not download $from"
+ if command -v sha256sum >/dev/null; then got=$(sha256sum "$tmp/$file" | cut -d' ' -f1)
+ else got=$(shasum -a 256 "$tmp/$file" | cut -d' ' -f1); fi
+ if [ "$got" != "$sum" ]; then
+ [ "$from" = "$url" ] || die "$file from $mirror does not match its checksum from $site; not installed"
+ die "$file does not match its checksum"
+ fi
+}
+
+# keeps : whether this magpie can disconnect the agents and keep its
+# files (magpie uninstall --keep-data, which an older one doesn't know)
+keeps() {
+ "$1" uninstall --help 2>&1 | grep -q -- --keep-data
+}
+
# runs : the program an entry's Exec= or a unit's ExecStart=
# starts, its first word, quoted or not
runs() {
@@ -119,12 +173,45 @@ runs() {
# magpie: left, they would start a program that is gone at each login.
if [ -n "$uninstall" ]; then
exe="$bin/magpie"
- if [ "$uninstall" = purge ]; then
- # magpie disconnects the agents it connected and deletes its own
- # folders; deleting them here by hand would leave the agents pointed
- # at a gateway that is gone
- [ -x "$exe" ] || die "no magpie at $exe to disconnect your agents and delete its settings: install it again and run this again, or run --uninstall alone to keep them"
- "$exe" uninstall --yes || die "magpie uninstall didn't finish (see above), so the magpie command and app are left: run this again once it does"
+ # magpie disconnects the agents it connected first, putting back what
+ # each had: taking it off alone left them pointed at a gateway that is
+ # gone (Codex, whimsical_wolf_15477 on Discord). The one installed does
+ # it; with none (deleted by hand: a broken link, an app in the Trash)
+ # or one too old to keep its files, the newest is downloaded to do it,
+ # while magpie's settings (and the record of what each agent had) are
+ # still here.
+ with=
+ if [ -x "$exe" ]; then with=$exe
+ elif [ "$os" = darwin ]; then
+ for apps in /Applications "$HOME/Applications"; do
+ [ -n "$with" ] || [ ! -x "$apps/magpie.app/Contents/MacOS/magpie" ] || with="$apps/magpie.app/Contents/MacOS/magpie"
+ done
+ fi
+ if [ -n "$with" ] && [ "$uninstall" != purge ] && ! keeps "$with"; then with=; fi
+ if [ -z "$with" ] && [ -d "$config/magpie" ]; then
+ other=$(command -v magpie 2>/dev/null || true)
+ if [ -n "$other" ] && [ "$other" != "$exe" ] && [ -x "$other" ]; then
+ # another magpie, not this script's, serves the agents still: it
+ # is the one to take off, and its agents are its own to put back
+ say "magpie at $other isn't one this script installed, so your agents are left on it: run $other uninstall to disconnect them and take it off"
+ else
+ [ -n "$arch" ] || die "unsupported CPU: $(uname -m)"
+ case "$os" in
+ darwin) fetch "magpie-darwin-$arch.zip"
+ ditto -x -k "$tmp/$file" "$tmp/x"
+ with="$tmp/x/magpie.app/Contents/MacOS/magpie" ;;
+ android) fetch "magpie-cli-android-$arch"; chmod 755 "$tmp/$file"; with="$tmp/$file" ;;
+ *) fetch "magpie-cli-linux-$arch"; chmod 755 "$tmp/$file"; with="$tmp/$file" ;;
+ esac
+ say "disconnecting your agents with it (it is deleted after)"
+ fi
+ fi
+ if [ -n "$with" ]; then
+ if [ "$uninstall" = purge ]; then
+ MAGPIE_UNINSTALL_SCRIPT=1 "$with" uninstall --yes || die "magpie uninstall didn't finish (see above), so the magpie command and app are left: run this again once it does"
+ else
+ MAGPIE_UNINSTALL_SCRIPT=1 "$with" uninstall --yes --keep-data || die "magpie couldn't disconnect your agents (see above), so the magpie command and app are left: run this again once it can"
+ fi
fi
removed=
gone() { rm -rf "$1"; removed=1; say "removed $1"; }
@@ -184,9 +271,6 @@ if [ -n "$uninstall" ]; then
[ "$removed" ] || say "no magpie installed by this script at $exe"
if [ "$uninstall" != purge ]; then
say "kept your settings, providers and usage in $config/magpie: install again to have them back, or run with --purge to delete them"
- if pid=$(pgrep -f "^$exe( |\$)" 2>/dev/null) && [ -n "$pid" ]; then
- say "magpie is still running (pid $(printf '%s' "$pid" | tr '\n' ' ' | sed 's/ $//')) and ends when you quit it; agents connected to it reach its gateway until then"
- fi
fi
# magpie uninstall said so already
[ "$uninstall" = purge ] || say "magpie is uninstalled"
@@ -321,11 +405,7 @@ install_gui_libs() {
has_gui_libs
}
-case "$(uname -m)" in
- arm64|aarch64) arch=arm64 ;;
- x86_64|amd64) arch=amd64 ;;
- *) die "unsupported CPU: $(uname -m)" ;;
-esac
+[ -n "$arch" ] || die "unsupported CPU: $(uname -m)"
case "$os" in
darwin) file="magpie-darwin-$arch.zip" ;;
android) file="magpie-cli-android-$arch" ;;
@@ -344,34 +424,7 @@ case "$os" in
esac ;;
esac
-tmp=$(mktemp -d)
-trap 'rm -rf "$tmp"' EXIT
-
-# the release list and its checksums: always from the site, never a mirror
-feed=$(get "$site/api/latest") || die "could not reach $site${proxy:+ through $proxy}"
-# The feed is one line of JSON; pull this file's url and hash out of it.
-entry=$(printf '%s' "$feed" | sed -n "s/.*\"$file\":{\([^}]*\)}.*/\1/p")
-url=$(printf '%s' "$entry" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p')
-sum=$(printf '%s' "$entry" | sed -n 's/.*"sha256":"\([^"]*\)".*/\1/p')
-version=$(printf '%s' "$feed" | sed -n 's/.*"version":"\([^"]*\)".*/\1/p')
-if [ "$os" = android ] && { [ -z "$url" ] || [ -z "$sum" ]; }; then
- die "the newest release has no $file; build in Termux with go build -tags nogui (see $site/docs/start)"
-fi
-[ -n "$url" ] && [ -n "$sum" ] || die "the newest release has no $file"
-
-from=$url
-case "$url" in
- https://github.com/*) [ -z "$mirror" ] || from="$mirror$url" ;;
-esac
-if [ "$from" != "$url" ]; then say "downloading magpie $version ($file) through $mirror"
-else say "downloading magpie $version ($file)"; fi
-get -o "$tmp/$file" "$from" || die "could not download $from"
-if command -v sha256sum >/dev/null; then got=$(sha256sum "$tmp/$file" | cut -d' ' -f1)
-else got=$(shasum -a 256 "$tmp/$file" | cut -d' ' -f1); fi
-if [ "$got" != "$sum" ]; then
- [ "$from" = "$url" ] || die "$file from $mirror does not match its checksum from $site; not installed"
- die "$file does not match its checksum"
-fi
+fetch "$file"
mkdir -p "$bin"
if [ "$os" = darwin ]; then