diff --git a/README.md b/README.md index b8dbb90e2..c4eb243ef 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. Behind a firewall, use `--proxy` or `--mirror`. Or `go install github.com/yetone/magpie@latest`, or the [Docker image](https://usemagpie.ai/docs/docker). +Mac builds are signed and notarised, and every build updates itself. 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. **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 3738665cc..6c2e14576 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -52,7 +52,7 @@ curl -fsSL https://usemagpie.ai/install.sh | sh ``` -Mac 版已签名并公证,每个版本都会自动更新。网络受限时可用 `--proxy` 或 `--mirror`。也可以 `go install github.com/yetone/magpie@latest`,或者用 [Docker 镜像](https://usemagpie.ai/docs/zh/docker)。 +Mac 版已签名并公证,每个版本都会自动更新。网络受限时可用 `--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 并一起删除。 **2 · 添加 provider**。打开 magpie,进入 **Providers → 添加 provider**。选一个预设、粘贴 key,或者登录一个订阅。 diff --git a/site/install.test.mjs b/site/install.test.mjs index a82b3678f..4c9f7b157 100644 --- a/site/install.test.mjs +++ b/site/install.test.mjs @@ -33,6 +33,13 @@ function install(t, { termux = true, arch = "aarch64", override = false, prefixO const requests = join(dir, "requests"); writeFileSync(join(tools, "uname"), `#!/bin/sh\ncase "$1" in -m) echo '${arch}';; -s) echo Linux;; esac\n`, { mode: 0o755 }); writeFileSync(join(tools, "ldconfig"), "#!/bin/sh\necho libwebkit2gtk-4.1.so.0\n", { mode: 0o755 }); + // xdg-mime as xdg-utils writes the default: one line in mimeapps.list + writeFileSync(join(tools, "xdg-mime"), `#!/bin/sh +[ "$1" = default ] || exit 0 +mkdir -p "$XDG_CONFIG_HOME" +printf '[Default Applications]\\n' >> "$XDG_CONFIG_HOME/mimeapps.list" +printf '%s=%s\\n' "$3" "$2" >> "$XDG_CONFIG_HOME/mimeapps.list" +`, { mode: 0o755 }); writeFileSync(join(tools, "curl"), `#!${process.execPath} const fs = require("node:fs"); const args = process.argv.slice(2); @@ -62,10 +69,15 @@ else fs.writeFileSync(args[args.indexOf("-o") + 1], tamper && url.startsWith(tam MAGPIE_MIRROR: "", ...extra, }; - const result = spawnSync("sh", [installer, ...args], { env, encoding: "utf8" }); const read = (p) => (existsSync(p) ? readFileSync(p, "utf8") : ""); - const calls = read(env.INSTALL_ARGS).trim().split("\n").filter(Boolean).map((l) => JSON.parse(l)); - return { ...result, bin, file, payload, share: env.XDG_DATA_HOME, requests: read(requests), calls }; + const run = (args) => { + rmSync(requests, { force: true }); + rmSync(env.INSTALL_ARGS, { force: true }); + const result = spawnSync("sh", [installer, ...args], { env, encoding: "utf8" }); + const calls = read(env.INSTALL_ARGS).trim().split("\n").filter(Boolean).map((l) => JSON.parse(l)); + return { ...result, requests: read(requests), calls }; + }; + return { ...run(args), run, bin, file, payload, home, env, share: env.XDG_DATA_HOME, config: env.XDG_CONFIG_HOME }; } test("Termux downloads Android arm64 into PREFIX/bin even with WebKit installed", (t) => { @@ -168,3 +180,110 @@ test("a file the mirror changed is refused and the installed magpie kept", (t) = assert.notEqual(bad.status, 0); assert.match(bad.stderr, /--mirror is an http\(s\) address/); }); + +// 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. +function installedDesktop(t, opts = {}) { + const r = install(t, { termux: false, desktop: true, ...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 }); + 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") }; +} + +test("--uninstall takes off the command, menu entry, icon and magpie:// default, and keeps the settings", (t) => { + const r = installedDesktop(t); + for (const p of [r.exe, r.entry, r.icon]) assert.ok(existsSync(p), p); + writeFileSync(r.mime, readFileSync(r.mime, "utf8") + "text/html=firefox.desktop\n"); + assert.match(readFileSync(r.mime, "utf8"), /^x-scheme-handler\/magpie=magpie\.desktop$/m); + const u = r.run(["--uninstall"]); + assert.equal(u.status, 0, u.stderr); + for (const p of [r.exe, r.entry, r.icon]) assert.equal(existsSync(p), false, p); + assert.equal(readFileSync(r.mime, "utf8"), "[Default Applications]\ntext/html=firefox.desktop\n"); + assert.ok(existsSync(r.settings), "the settings stay"); + assert.equal(r.calls(), "", "magpie isn't asked to uninstall"); + assert.equal(u.calls.length, 0, "nothing is downloaded"); + assert.match(u.stdout, /kept your settings.*--purge/); + // again: nothing there, nothing wrong + const again = r.run(["--uninstall"]); + assert.equal(again.status, 0, again.stderr); + assert.match(again.stdout, /no magpie installed by this script/); +}); + +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"); + const login = join(r.config, "autostart/magpie.desktop"); + mkdirSync(join(r.config, "systemd/user"), { recursive: true }); + mkdirSync(join(r.config, "autostart"), { recursive: true }); + writeFileSync(unit, `[Service]\nExecStart="${r.exe}" serve\n`); + writeFileSync(login, `[Desktop Entry]\nExec="${r.exe}" --autostart\n`); + const u = r.run(["--uninstall"]); + assert.equal(u.status, 0, u.stderr); + assert.equal(existsSync(unit), false); + assert.equal(existsSync(login), false); + assert.match(r.calls(), /^daemon uninstall$/m); + + // another magpie's (one still there) are left alone + const o = installedDesktop(t); + const other = join(o.home, "elsewhere/magpie"); + mkdirSync(join(o.home, "elsewhere"), { recursive: true }); + writeFileSync(other, "", { mode: 0o755 }); + mkdirSync(join(o.config, "systemd/user"), { recursive: true }); + mkdirSync(join(o.config, "autostart"), { recursive: true }); + const ounit = join(o.config, "systemd/user/magpie.service"); + const ologin = join(o.config, "autostart/magpie.desktop"); + writeFileSync(ounit, `[Service]\nExecStart="${other}" serve\n`); + writeFileSync(ologin, `[Desktop Entry]\nExec="${other}" --autostart\n`); + writeFileSync(o.entry, `[Desktop Entry]\nExec=${other} %u\n`); + const ou = o.run(["--uninstall"]); + assert.equal(ou.status, 0, ou.stderr); + for (const p of [ounit, ologin, o.entry]) assert.ok(existsSync(p), p); + assert.equal(existsSync(o.exe), false); +}); + +test("--purge has magpie uninstall itself first, then takes off the install", (t) => { + const r = installedDesktop(t); + const u = r.run(["--purge"]); + assert.equal(u.status, 0, u.stderr); + assert.match(r.calls(), /^uninstall --yes$/m); + for (const p of [r.exe, r.entry, r.icon, r.settings]) assert.equal(existsSync(p), false, p); + // magpie took the menu entry itself; its icon and magpie:// default go too + assert.doesNotMatch(readFileSync(r.mime, "utf8"), /magpie/); + assert.doesNotMatch(u.stdout, /kept your settings/); + + // magpie failing to: the command stays, to run it again + const f = installedDesktop(t, { env: { MAGPIE_FAIL: "1" } }); + const fu = f.run(["--uninstall", "--purge"]); + assert.notEqual(fu.status, 0); + 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) => { + const r = install(t, {}); + assert.equal(r.status, 0, r.stderr); + const u = r.run(["--uninstall"]); + assert.equal(u.status, 0, u.stderr); + assert.equal(existsSync(join(r.bin, "magpie")), false); + assert.match(u.stdout, /removed .*com\.termux\/files\/usr\/bin\/magpie/); +}); diff --git a/site/public/docs/ja/start.html b/site/public/docs/ja/start.html index 350e87264..23295b6a3 100644 --- a/site/public/docs/ja/start.html +++ b/site/public/docs/ja/start.html @@ -285,6 +285,9 @@ magpie claude group/opus-anywhere # これを使う

GitHub に届かない環境で、インストールや更新をするには?

インストーラと magpie update にプロキシを渡します:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --proxy http://127.0.0.1:7890、または magpie update --proxy socks5://127.0.0.1:1080(http・https・socks5・socks5h に対応。HTTPS_PROXY と ALL_PROXY も使われます)。--mirror <prefix> を付けると、指定した GitHub ダウンロードミラーから <prefix>https://github.com/… としてリリースファイルを取得します。magpie update mirror <prefix> でアプリ自身の更新を含め毎回使い、magpie update mirror off で解除します。指定しない限りミラーは使われず、ファイルの SHA-256 はミラーではなく常に usemagpie.ai から取得するので、ミラーが書き換えたファイルはインストールされません。アプリ自身の更新は Settings → Proxy を通ります。

+

magpie をアンインストールするには?

+

スクリプトでインストールした場合: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 と同じことを行い、プログラム本体は手動で削除します。

+

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 3956ce94f..cf5250390 100644 --- a/site/public/docs/start.html +++ b/site/public/docs/start.html @@ -285,6 +285,9 @@ magpie claude group/opus-anywhere # use it

Installing or updating behind a firewall, or without access to GitHub?

Give the installer and magpie update a proxy: curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --proxy http://127.0.0.1:7890, or magpie update --proxy socks5://127.0.0.1:1080 (http, https, socks5 and socks5h; HTTPS_PROXY and ALL_PROXY are honoured too). --mirror <prefix> fetches the release file from a GitHub download mirror you choose, as <prefix>https://github.com/…; magpie update mirror <prefix> keeps it for every update, the app’s too, and magpie update mirror off removes it. No mirror is used unless you give one, and the file’s SHA-256 still comes from usemagpie.ai, never from the mirror: a file the mirror changed is refused. The app’s own updates go through Settings → Proxy.

+

How do I uninstall magpie?

+

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.

+

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 e8035e0aa..4037f74f3 100644 --- a/site/public/docs/zh/start.html +++ b/site/public/docs/zh/start.html @@ -285,6 +285,9 @@ magpie claude group/opus-anywhere # 使用它

没有梯子,安装或更新连不上 GitHub 怎么办?

给安装脚本和 magpie update 加代理:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --proxy http://127.0.0.1:7890,或 magpie update --proxy socks5://127.0.0.1:1080(支持 http、https、socks5、socks5h;环境变量 HTTPS_PROXY、ALL_PROXY 同样生效)。--mirror <前缀> 从你指定的 GitHub 下载镜像取发布文件,即 <前缀>https://github.com/…;magpie update mirror <前缀> 让之后每次更新(包括应用自己的更新)都用它,magpie update mirror off 取消。不指定就不用任何镜像;文件的 SHA-256 始终来自 usemagpie.ai,而不是镜像,镜像改过的文件会被拒绝安装。应用自己的更新走 设置 → 代理。

+

怎么卸载 magpie?

+

用安装脚本装的: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 那些事,程序本身留给你删除。

+

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 a8f1628ef..3adb30ef5 100644 --- a/site/public/install.sh +++ b/site/public/install.sh @@ -20,12 +20,22 @@ # list and its SHA-256 still come from usemagpie.ai, # never from the mirror, so a file the mirror changed is # refused. +# --uninstall 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. set -eu site=https://usemagpie.ai bin="${MAGPIE_BIN_DIR:-$HOME/.local/bin}" proxy="${MAGPIE_PROXY:-}" mirror="${MAGPIE_MIRROR:-}" +uninstall= say() { printf ' %s\n' "$*"; } die() { printf 'magpie: %s\n' "$*" >&2; exit 1; } @@ -36,13 +46,18 @@ while [ $# -gt 0 ]; do --proxy=*) proxy=${1#--proxy=}; shift ;; --mirror) [ $# -ge 2 ] || die "--mirror needs a value"; mirror=$2; shift 2 ;; --mirror=*) mirror=${1#--mirror=}; shift ;; + --uninstall) [ "$uninstall" = purge ] || uninstall=1; shift ;; + --purge) uninstall=purge; shift ;; -h|--help) printf '%s\n' "usage: curl -fsSL $site/install.sh | sh -s -- [--proxy ] [--mirror ]" \ + " curl -fsSL $site/install.sh | sh -s -- --uninstall [--purge]" \ " --proxy http://, https://, socks5:// or socks5h:// proxy for the downloads (or MAGPIE_PROXY=)" \ " --mirror GitHub download mirror put before the release's github.com URL (or MAGPIE_MIRROR=);" \ - " the SHA-256 is still checked against $site's" + " the SHA-256 is still checked against $site's" \ + " --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)" exit 0 ;; - *) die "unknown option $1 (--proxy , --mirror )" ;; + *) die "unknown option $1 (--proxy , --mirror , --uninstall, --purge)" ;; esac done case "$proxy" in @@ -60,28 +75,120 @@ get() { if [ -n "$proxy" ]; then curl -fsSL --proxy "$proxy" "$@"; else curl -fsSL "$@"; fi } -case "$(uname -m)" in - arm64|aarch64) arch=arm64 ;; - x86_64|amd64) arch=amd64 ;; - *) die "unsupported CPU: $(uname -m)" ;; -esac case "$(uname -s)" in - Darwin) os=darwin; file="magpie-darwin-$arch.zip" ;; + Darwin) os=darwin ;; Linux) termux="${TERMUX_VERSION:-}" case "${PREFIX:-}" in */com.termux/files/usr) termux=1 ;; esac if [ -n "$termux" ]; then [ -n "${PREFIX:-}" ] || die "Termux requires PREFIX to locate its bin directory" - os=android; file="magpie-cli-android-$arch" + os=android bin="${MAGPIE_BIN_DIR:-$PREFIX/bin}" else - os=linux; file="magpie-cli-linux-$arch" - if [ -z "${MAGPIE_CLI:-}" ] && { ldconfig -p 2>/dev/null | grep -q 'libwebkit2gtk-4\.1\.so\.0'; }; then - file="magpie-linux-$arch" - fi + os=linux fi ;; *) die "unsupported system: $(uname -s); see $site" ;; esac +share="${XDG_DATA_HOME:-$HOME/.local/share}" +config="${XDG_CONFIG_HOME:-$HOME/.config}" + +# runs : the program an entry's Exec= or a unit's ExecStart= +# starts, its first word, quoted or not +runs() { + sed -n "s/^$2=//p" "$1" 2>/dev/null | head -n 1 | sed -e 's/^"\([^"]*\)".*/\1/' -e t -e 's/ .*//' +} + +# --uninstall: what the install below puts there, and nothing of the +# user's. The service and login entry go too while they start this +# 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" + fi + removed= + gone() { rm -rf "$1"; removed=1; say "removed $1"; } + if [ "$os" = darwin ]; then + for apps in /Applications "$HOME/Applications"; do + [ ! -d "$apps/magpie.app" ] || gone "$apps/magpie.app" + done + case "$(readlink "$exe" 2>/dev/null)" in + */magpie.app/Contents/MacOS/magpie) gone "$exe" ;; + esac + else + if [ "$os" = linux ]; then + unit="$config/systemd/user/magpie.service" + if [ "$(runs "$unit" ExecStart)" = "$exe" ]; then + if ! "$exe" daemon uninstall >/dev/null 2>&1; then + command -v systemctl >/dev/null && systemctl --user disable --now magpie.service >/dev/null 2>&1 || true + rm -f "$unit" + fi + removed=1; say "removed magpie's service ($unit)" + fi + login="$config/autostart/magpie.desktop" + [ "$(runs "$login" Exec)" != "$exe" ] || gone "$login" + fi + [ ! -f "$exe" ] || gone "$exe" + if [ "$os" = linux ]; then + apps="$share/applications" + # the menu entry and its icon while they start this magpie, or one + # that is gone; another magpie's stays + run=$(runs "$apps/magpie.desktop" Exec) + if [ -f "$apps/magpie.desktop" ] && { [ "$run" = "$exe" ] || [ ! -e "$run" ]; }; then + gone "$apps/magpie.desktop" + fi + # with no menu entry (this one, or the one magpie uninstall took), + # what came with it: the icon, the magpie:// default xdg-mime set + # (that line only) and the menu's cache when it lists nothing else + if [ ! -e "$apps/magpie.desktop" ]; then + icons="$share/icons/hicolor/256x256/apps" + [ ! -f "$icons/magpie.png" ] || gone "$icons/magpie.png" + rmdir "$icons" "$share/icons/hicolor/256x256" "$share/icons/hicolor" "$share/icons" 2>/dev/null || true + list="$config/mimeapps.list" + if [ -f "$list" ] && grep -qx 'x-scheme-handler/magpie=magpie\.desktop;\{0,1\}' "$list"; then + grep -vx 'x-scheme-handler/magpie=magpie\.desktop;\{0,1\}' "$list" > "$list.magpie-new" || true + mv "$list.magpie-new" "$list" + removed=1; say "removed magpie:// from $list" + fi + if [ -d "$apps" ] && ! ls "$apps" | grep -q '\.desktop$'; then + rm -f "$apps/mimeinfo.cache" + rmdir "$apps" 2>/dev/null || true + elif [ -d "$apps" ]; then + command -v update-desktop-database >/dev/null && update-desktop-database "$apps" 2>/dev/null || true + fi + fi + fi + fi + [ "$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" + exit 0 +fi + +case "$(uname -m)" in + arm64|aarch64) arch=arm64 ;; + x86_64|amd64) arch=amd64 ;; + *) die "unsupported CPU: $(uname -m)" ;; +esac +case "$os" in + darwin) file="magpie-darwin-$arch.zip" ;; + android) file="magpie-cli-android-$arch" ;; + *) + file="magpie-cli-linux-$arch" + if [ -z "${MAGPIE_CLI:-}" ] && { ldconfig -p 2>/dev/null | grep -q 'libwebkit2gtk-4\.1\.so\.0'; }; then + file="magpie-linux-$arch" + fi ;; +esac tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT @@ -128,7 +235,6 @@ if [ "$os" = darwin ]; then else install -m 755 "$tmp/$file" "$bin/magpie" if [ "$file" = "magpie-linux-$arch" ]; then - share="${XDG_DATA_HOME:-$HOME/.local/share}" mkdir -p "$share/applications" "$share/icons/hicolor/256x256/apps" get -o "$share/icons/hicolor/256x256/apps/magpie.png" "$site/img/icon-256.png" || true cat > "$share/applications/magpie.desktop" <