uninstall: install.sh --uninstall disconnects every agent first, a deleted magpie too

whimsical_wolf_15477 (Discord): after uninstalling magpie, Codex didn't go
back to its own config. `install.sh --uninstall` deleted the magpie command
and app and left every agent wired to a gateway that no longer runs: Codex
kept openai_base_url (or model_provider = "magpie" and model_catalog_json)
pointing at 127.0.0.1. A magpie deleted by hand undid nothing either, and
`--purge` refused with no magpie left to run.

- `magpie uninstall --keep-data` (uninstall.KeepData): every agent
  disconnected and its own values put back from stash.json, the service,
  autostart, shortcut, scheme and helpers removed, magpie's settings,
  providers and usage kept.
- install.sh --uninstall runs `magpie uninstall --yes --keep-data` (--purge:
  `--yes`) before deleting anything, and stops if it fails. With no magpie
  of its own (deleted by hand) but magpie's config left, it fetches the
  newest release into a temporary folder, checks its sha256, runs that, and
  deletes it after. An older magpie without --keep-data gets the newest one
  for this too. A magpie on PATH that the script didn't install is left to
  its own `magpie uninstall`, and said so.
- MAGPIE_UNINSTALL_SCRIPT=1: under the script magpie doesn't ask to delete
  a path that the script deletes next.
- docs (en/zh/ja start.html #uninstall) and READMEs: what the line does,
  that it works for a magpie already deleted, and Codex's lines by hand.

Run (WSL magpie-desktop; mote's disk is full, nothing run or deleted there):
- go test -tags nogui -run "Uninstall|Help|TestKeepData" ./internal/cli/
  ./internal/uninstall/: ok. node --test site/install.test.mjs: all pass.
- The new install tests against the old install.sh: 5 red. Broken by hand
  (--keep-data case removed, Data() back in KeepData): TestUninstallKeepData
  and TestKeepData red.
- Real e2e: magpie built from this tree, Codex wired in a sandbox HOME
  (not signed in, and ChatGPT signed in), magpie installed and deleted by
  hand; install.sh --uninstall with a local feed. config.toml's diff before
  wiring vs after is the [model_providers.magpie] table only (kept on
  purpose for threads started on magpie); model, effort, openai_base_url,
  model_provider and model_catalog_json are the user's again; settings kept.
- gofmt -l clean; go vet GOOS=windows/darwin/linux (nogui) for the two
  packages; sh -n and dash -n install.sh.

Not tried: macOS's zip path for a deleted magpie run for real (tests cover
it with fakes), Termux, Windows (no install.sh there; docs say download
magpie again and use Settings › Uninstall). The full internal/cli package
timed out at 10m under WSL load in providers_unreadable_cli_test (not
touched here); see the full suite record.
This commit is contained in:
yetone
2026-11-05 12:52:46 +08:00
parent 73c98ebc20
commit 9d143eacab
12 changed files with 320 additions and 84 deletions
+1 -1
View File
@@ -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
```
<sub>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.</sub>
<sub>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`.</sub>
**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.
+1 -1
View File
@@ -52,7 +52,7 @@
curl -fsSL https://usemagpie.ai/install.sh | sh
```
<sub>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 并一起删除。</sub>
<sub>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` 才一起删除。</sub>
**2 · 添加 provider**。打开 magpie,进入 **Providers → 添加 provider**。选一个预设、粘贴 key,或者登录一个订阅。
+1
View File
@@ -74,6 +74,7 @@ const usage = `magpie — one place to pick every agent's model
magpie restore [--no-agents] [--no-library] <file> 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 <address>|set k=v…|now|off] the same, kept the same on every computer through a WebDAV folder (magpie webdav help)
magpie s3 [on s3://<bucket>[/<prefix>]|set k=v…|now|off] the same through an S3-compatible bucket: AWS, R2, B2, MinIO… (magpie s3 help)
magpie github [on github://<owner>/<repo>[/<folder>]|set k=v…|now|off] the same in an encrypted GitHub repository (magpie github help)
+32 -7
View File
@@ -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
}
+42 -4
View File
@@ -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")
}
}
+14
View File
@@ -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 {
+19
View File
@@ -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) {
+103 -20
View File
@@ -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: <who> 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) => {
+2 -1
View File
@@ -297,7 +297,8 @@ magpie claude group/opus-anywhere <span class="c"># これを使う</span></p
<p>GTK 3 と WebKitGTK 4.1 が入っていればデスクトップアプリ(ウィンドウ、トレイアイコン、アプリメニューの項目)です。デスクトップがあってもそれらが無いときは、パッケージマネージャー(apt、dnf、pacman、zypper)で <code>sudo</code> を通して WebKitGTK 4.1 を入れ(sudo がパスワードを尋ねます)、それからアプリを入れます。パスワードを尋ねる前に何を入れるかを表示します。端末が無いとき(CI、Dockerfile)、<code>sudo</code> が無いとき、知らないディストリビューションやインストールに失敗したときはターミナル版(<code>magpie tui</code>、<code>magpie web</code> と CLI)を入れ、最後に入れるコマンドを表示します。Debian・Ubuntu なら <code>sudo apt install libwebkit2gtk-4.1-0</code>、Fedora なら <code>sudo dnf install webkit2gtk4.1</code> です。入れたあとインストーラをもう一度実行するとアプリになります。デスクトップ上で実行しても ssh 越しでも、グラフィカルなセッション、あなたのグラフィカルなログイン、ログインできるデスクトップ環境のどれかがあればデスクトップありと判断します。デスクトップの無いサーバーにはターミナル版です。自分で選ぶには <code>--gui</code>(ライブラリを今入れられなくてもアプリ)か <code>--tui</code>(ターミナル版、パッケージは入れない)を付けます:<code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --tui</code>。</p>
<h3 id="uninstall"><a class="anchor" href="#uninstall">magpie をアンインストールするには?</a></h3>
<p>スクリプトでインストールした場合:<code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall</code> で、スクリプトが置いたものを取り除きます。<code>magpie</code> コマンド、macOS ではアプリ、Linux ではメニュー項目・アイコン・<code>magpie://</code> のハンドラ、それに Linux ではもう無い magpie を起動してしまうサービスとログイン時の起動です。<code>~/.config/magpie</code> の設定・プロバイダ・使用量は残るので、再インストールすれば戻ります。接続したエージェントはそれまで magpie のアドレスを指したままです。<code>--purge</code> を付けると先に <code>magpie uninstall --yes</code> を実行し、すべてのエージェントの接続を外して元の設定に戻してから、magpie の設定・プロバイダ・使用量を削除します。ほかの方法でインストールした場合は、<code>magpie uninstall</code> または <span class="ui">Settings</span> → <span class="ui">magpie をアンインストール</span> が <code>--purge</code> と同じことを行い、プログラム本体は手動で削除します。</p>
<p>スクリプトでインストールした場合:<code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall</code> は、まず magpie にすべてのエージェントの接続を外させて元の設定に戻し、それからスクリプトが置いたものを取り除きます。<code>magpie</code> コマンド、macOS ではアプリ、Linux ではメニュー項目・アイコン・<code>magpie://</code> のハンドラ、それに Linux ではもう無い magpie を起動してしまうサービスとログイン時の起動です。<code>~/.config/magpie</code> の設定・プロバイダ・使用量は残るので、再インストールすれば戻ります。<code>--purge</code> を付けるとそれも削除します(<code>magpie uninstall --yes</code>)。ほかの方法でインストールした場合は、<code>magpie uninstall</code> または <span class="ui">Settings</span> → <span class="ui">magpie をアンインストール</span> が <code>--purge</code> と同じことを行い、プログラム本体は手動で削除します。</p>
<p>magpie をもう削除した(アプリをゴミ箱に入れた、フォルダーを消した)のに、エージェントが接続できないと言う場合:macOS と Linux では同じ <code>--uninstall</code> の行を実行してください。magpie が見つからないと最新版を一時フォルダーにダウンロードし(インストールと同じく検証します)、<code>~/.config/magpie</code> に各エージェントの元の設定が残っているうちに、それが元に戻します。Windows では magpie をもう一度ダウンロードして <span class="ui">Settings</span> → <span class="ui">magpie をアンインストール</span> を使います。Codex を手で戻すには、Codex を終了し、<code>~/.codex/config.toml</code> で <code># magpie:</code> コメントの下の行(<code>openai_base_url</code>、<code>model_provider = "magpie"</code>、<code>model_catalog_json</code>)を削除して、<code>model</code> を Codex 自身のモデルに戻します。magpie で始めたスレッドを残さないなら <code>[model_providers.magpie]</code> の表も消せます。<code>~/.codex/magpie-models.json</code> を削除し、Codex を開き直します。</p>
<h3 id="log">magpie のログはどこにありますか?</h3>
<p>アプリ(ウィンドウ、メニューバーやトレイのアイコン、パネル。どう開いたかによらず)は <code>app.log</code> を書きます。macOS では <code>~/Library/Logs/magpie/app.log</code>、Windows では <code>%LOCALAPPDATA%\magpie\logs\app.log</code>、Linux では <code>~/.local/state/magpie/app.log</code>(<code>$XDG_STATE_HOME</code> が設定されていれば <code>$XDG_STATE_HOME/magpie</code>)、ポータブル版ではデータフォルダーの <code>logs</code> です。<span class="ui">設定</span> → <span class="ui">情報</span> → <span class="ui">ログ</span>にパスがあり、<span class="ui">開く</span>でそのフォルダーを表示します。<code>magpie log</code> はパスを表示し、<code>magpie log -f</code> は追いかけます。5 MiB に達すると隣の <code>app.old.log</code> になり、残るのは最大 2 ファイルです。記録されるのは magpie がしたことと出会ったエラー(プロバイダーがリクエストを断った、再試行した、プラグインが起動しなかった)で、キー、プロンプト、返答は含みません。キーやトークンに見えるものも伏せられます。サービスとして動く <code>magpie serve</code> のログは別の場所です。macOS では <code>~/Library/Logs/magpie/serve.log</code>、Linux では <code>journalctl --user -u magpie</code>。<code>magpie log</code> はそれも示します。</p>
+2 -1
View File
@@ -297,7 +297,8 @@ magpie claude group/opus-anywhere <span class="c"># use it</span></pre>
<p>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 <code>sudo</code>, 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 <code>sudo</code>, on another distribution or when that install fails, it installs the terminal build (<code>magpie tui</code>, <code>magpie web</code> and the CLI) and ends with the command that installs them, such as <code>sudo apt install libwebkit2gtk-4.1-0</code> on Debian and Ubuntu or <code>sudo dnf install webkit2gtk4.1</code> 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 <code>--gui</code> (the app even when its libraries can't be installed now) or <code>--tui</code> (the terminal build, and no package installed): <code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --tui</code>.</p>
<h3 id="uninstall"><a class="anchor" href="#uninstall">How do I uninstall magpie?</a></h3>
<p>Installed with the script: <code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall</code> takes off what it put there: the <code>magpie</code> command, and the app on macOS or its menu entry, icon and <code>magpie://</code> 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 <code>~/.config/magpie</code> stay, for when you install again; agents you connected keep magpie’s address until then. Add <code>--purge</code> to have <code>magpie uninstall --yes</code> run first: it disconnects every agent and puts back what each had, then deletes magpie’s settings, providers and usage. Installed another way, <code>magpie uninstall</code> or <span class="ui">Settings</span> → <span class="ui">Uninstall magpie</span> does what <code>--purge</code> does and leaves the program itself for you to delete.</p>
<p>Installed with the script: <code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall</code> has magpie disconnect every agent and put back what each had first, then takes off what the script put there: the <code>magpie</code> command, and the app on macOS or its menu entry, icon and <code>magpie://</code> 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 <code>~/.config/magpie</code> stay, for when you install again. Add <code>--purge</code> to delete them too (<code>magpie uninstall --yes</code>). Installed another way, <code>magpie uninstall</code> or <span class="ui">Settings</span> → <span class="ui">Uninstall magpie</span> does what <code>--purge</code> does and leaves the program itself for you to delete.</p>
<p>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 <code>--uninstall</code> 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 <code>~/.config/magpie</code>. On Windows, download magpie again and use <span class="ui">Settings</span> → <span class="ui">Uninstall magpie</span>. To put Codex back by hand, quit it, then in <code>~/.codex/config.toml</code> delete each line under a <code># magpie:</code> comment (<code>openai_base_url</code>, <code>model_provider = "magpie"</code>, <code>model_catalog_json</code>) and set <code>model</code> to one of Codex’s own; the <code>[model_providers.magpie]</code> table can go too once no thread you keep was started on magpie. Delete <code>~/.codex/magpie-models.json</code>, and open Codex again.</p>
<h3 id="log">Where is magpie’s log?</h3>
<p>The app (its window, the menu bar or tray icon and the panel, however it was opened) writes <code>app.log</code>: <code>~/Library/Logs/magpie/app.log</code> on macOS, <code>%LOCALAPPDATA%\magpie\logs\app.log</code> on Windows, <code>~/.local/state/magpie/app.log</code> on Linux (<code>$XDG_STATE_HOME/magpie</code> when that is set), and <code>logs</code> in a portable magpie’s data folder. <span class="ui">Settings</span> → <span class="ui">About</span> → <span class="ui">Log</span> has its path and an <span class="ui">Open</span> that shows its folder; <code>magpie log</code> prints it, and <code>magpie log -f</code> follows it. At 5 MiB it becomes <code>app.old.log</code> 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. <code>magpie serve</code> run as a service logs elsewhere: <code>~/Library/Logs/magpie/serve.log</code> on macOS, <code>journalctl --user -u magpie</code> on Linux; <code>magpie log</code> names it too.</p>
+2 -1
View File
@@ -297,7 +297,8 @@ magpie claude group/opus-anywhere <span class="c"># 使用它</span></pre>
<p>装了 GTK 3 和 WebKitGTK 4.1 时装桌面版(窗口、托盘图标和应用菜单项)。有桌面但缺这两个库时,脚本会用系统的包管理器(apt、dnf、pacman 或 zypper)通过 <code>sudo</code> 装上 WebKitGTK 4.1(sudo 会要你的密码),再装桌面版;要密码之前会先说要装什么。没有终端(CI、Dockerfile)、没有 <code>sudo</code>、发行版不认识或者装库失败时,先装终端版(<code>magpie tui</code>、<code>magpie web</code> 和命令行),最后给出装库的命令,比如 Debian、Ubuntu 上是 <code>sudo apt install libwebkit2gtk-4.1-0</code>,Fedora 上是 <code>sudo dnf install webkit2gtk4.1</code>;装好后再运行一次安装脚本就换成桌面版。在桌面上运行还是 ssh 进去运行都算有桌面:有图形会话、你登录着图形界面,或者装了可登录的桌面环境。没有桌面的服务器装终端版。想自己选,加 <code>--gui</code>(库现在装不上也装桌面版)或 <code>--tui</code>(装终端版,不装任何系统包):<code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --tui</code>。</p>
<h3 id="uninstall"><a class="anchor" href="#uninstall">怎么卸载 magpie?</a></h3>
<p>用安装脚本装的:<code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall</code> 会拿掉它装上的东西:<code>magpie</code> 命令,macOS 上的应用,Linux 上的菜单项、图标和 <code>magpie://</code> 链接处理,以及 Linux 上会去启动一个已不存在的 magpie 的后台服务和开机启动。<code>~/.config/magpie</code> 里的设置、provider 和用量都保留,重新安装就回来;已连接的 Agent 在那之前仍指向 magpie 的地址。加上 <code>--purge</code> 会先运行 <code>magpie uninstall --yes</code>:断开每个 Agent 并恢复它原来的配置,再删除 magpie 的设置、provider 和用量。用其他方式装的,<code>magpie uninstall</code> 或 <span class="ui">设置</span> → <span class="ui">卸载 magpie</span> 做的就是 <code>--purge</code> 那些事,程序本身留给你删除。</p>
<p>用安装脚本装的:<code>curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall</code> 会先让 magpie 断开每个 Agent 并恢复它原来的配置,再拿掉脚本装上的东西:<code>magpie</code> 命令,macOS 上的应用,Linux 上的菜单项、图标和 <code>magpie://</code> 链接处理,以及 Linux 上会去启动一个已不存在的 magpie 的后台服务和开机启动。<code>~/.config/magpie</code> 里的设置、provider 和用量都保留,重新安装就回来。加上 <code>--purge</code> 会把它们也删掉(<code>magpie uninstall --yes</code>)。用其他方式装的,<code>magpie uninstall</code> 或 <span class="ui">设置</span> → <span class="ui">卸载 magpie</span> 做的就是 <code>--purge</code> 那些事,程序本身留给你删除。</p>
<p>已经把 magpie 删了(应用拖进了废纸篓、文件夹删掉了),Agent 还是连不上?macOS 和 Linux 上运行同一行 <code>--uninstall</code>:找不到 magpie 时它会把最新版下载到临时文件夹(和安装一样校验),由它趁 <code>~/.config/magpie</code> 里还记着每个 Agent 原来的配置时把它们恢复。Windows 上重新下载 magpie,用 <span class="ui">设置</span> → <span class="ui">卸载 magpie</span>。手动恢复 Codex:先退出 Codex,在 <code>~/.codex/config.toml</code> 里删掉每条 <code># magpie:</code> 注释下面的那一行(<code>openai_base_url</code>、<code>model_provider = "magpie"</code>、<code>model_catalog_json</code>),把 <code>model</code> 改回 Codex 自己的模型;没有要保留的、在 magpie 上开的对话时,<code>[model_providers.magpie]</code> 整段也可以删。再删掉 <code>~/.codex/magpie-models.json</code>,重新打开 Codex。</p>
<h3 id="log">magpie 的日志在哪里?</h3>
<p>应用(窗口、菜单栏或托盘图标、快捷面板,不论怎样打开)写入 <code>app.log</code>:macOS 上是 <code>~/Library/Logs/magpie/app.log</code>,Windows 上是 <code>%LOCALAPPDATA%\magpie\logs\app.log</code>,Linux 上是 <code>~/.local/state/magpie/app.log</code>(设置了 <code>$XDG_STATE_HOME</code> 时是 <code>$XDG_STATE_HOME/magpie</code>),便携版则在数据文件夹的 <code>logs</code> 里。<span class="ui">设置</span> → <span class="ui">关于</span> → <span class="ui">日志</span>里有它的路径,<span class="ui">打开</span>会显示它所在的文件夹;<code>magpie log</code> 打印路径,<code>magpie log -f</code> 持续跟随。满 5 MiB 后它变成旁边的 <code>app.old.log</code>,最多保留两个文件。它记的是 magpie 做了什么、遇到了哪些错误(服务商拒绝请求、重试、插件没能启动),不含你的密钥、提示词或回复;看起来像密钥或令牌的内容也会被遮掉。作为服务运行的 <code>magpie serve</code> 日志在别处:macOS 上是 <code>~/Library/Logs/magpie/serve.log</code>,Linux 上是 <code>journalctl --user -u magpie</code>;<code>magpie log</code> 也会列出它。</p>
+101 -48
View File
@@ -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 <url>, --mirror <prefix>, --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 <file>: the newest release's <file> 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 <exe>: 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 <file> <key>: 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