From f68ddca370232eb96f8e1e2b17dfd32ec4427e1d Mon Sep 17 00:00:00 2001
From: yetone
Date: Sat, 31 Oct 2026 17:27:55 +0800
Subject: [PATCH] install.sh: a Linux desktop gets the desktop app, or the
command that installs its WebKitGTK; --gui and --tui choose (shuhai)
shuhai on Discord: on a Linux desktop install.sh installed the terminal
build, and a desktop user expects the app. The script chose by
`ldconfig -p` alone, and on Debian a user's PATH has no /sbin, so
ldconfig wasn't found and every Debian desktop got the terminal build
even with WebKitGTK 4.1 installed. Without the libraries, the only hint
was a line mid-output.
Now, with nothing asked (curl | sh stays unattended):
- the libraries are looked up with ldconfig from PATH, /sbin or /usr/sbin,
and in the usual lib folders when there is no cache (NixOS, Guix);
GTK 3 is checked beside WebKitGTK 4.1, which brings the rest the app
links (readelf -d of v0.1.2359's magpie-linux-amd64: gtk-3, webkit2gtk-4.1,
soup-3.0, javascriptcoregtk-4.1, glib, X11, wayland-client, glibc);
- libraries there: the desktop app, as before;
- a desktop without them: the terminal build, and last in the output the
distribution's command (apt/dnf/pacman/zypper/xbps/emerge from
os-release ID and ID_LIKE), "run this again", or --gui. A desktop is
DISPLAY, WAYLAND_DISPLAY, XDG_CURRENT_DESKTOP/XDG_SESSION_DESKTOP/
DESKTOP_SESSION, XDG_SESSION_TYPE x11/wayland, the user's logind
Display session when its Type is x11/wayland/mir (over ssh; logind
falls back to a tty login, which doesn't count), or a session file in
xsessions/wayland-sessions under XDG_DATA_DIRS;
- headless without them: the terminal build, with no desktop advice;
- --gui: the app even before its libraries, with the package to add;
--tui (or MAGPIE_CLI=1, kept) the terminal build on a desktop too;
- musl (Alpine): always the terminal build; --gui refuses, since the
app is built against glibc.
Docs: reference.md Install, README en/zh, docs start FAQ (en/zh/ja,
#linux-build).
Run:
- shellcheck -s sh: only SC2010 at the uninstall's `ls | grep`, there
before this change. sh -n and dash -n clean.
- site/install.test.mjs (5 new tests): 19/19 on mote (macOS sh) and on
magpie-desktop through wsl-run (dash); CI's site step
(sh -n + node --test site/*.test.mjs) 58/58 on magpie-desktop and 58/58
on mote.
- Red on the old install.sh: tests 16-19 fail (desktop advice, headless
advice, --gui, --tui). With the logind Type check taken out by hand,
the headless test fails on login "135 tty".
- Real installs on magpie-desktop (Ubuntu 24.04, XFCE, WSLg, /bin/sh =
dash), `cat install.sh | env ... sh -s`, stdin a pipe, into a /tmp
sandbox HOME/XDG dirs/MAGPIE_BIN_DIR, each removed after, v0.1.2360
downloaded from the real feed and `magpie version` run:
session with DISPLAY/WAYLAND_DISPLAY: desktop app + menu entry;
env -i with PATH=/usr/local/bin:/usr/bin:/bin: desktop app (the old
script gave the terminal build here, run the same way);
an ldconfig whose cache lacks the libs + DISPLAY=:0, and the same in
env -i (found by /usr/share/xsessions): terminal build + the apt line;
that with XDG_DATA_DIRS=/nonexistent: terminal build, quiet; --gui
there: desktop app + the apt line; --tui in the session: terminal build.
The first run found the tty-login fallback (logind's Display=135 is
this WSL user's pts session), fixed before commit.
- site/install.test.mjs on Windows (win-run): 0/19, the same 14 old
tests too: the box has no sh for spawnSync; CI runs this file on Linux
only.
Not tried: a real Debian, Fedora, Arch or openSUSE box, or a box without
WebKitGTK installed (simulated with a fake ldconfig); the package names
were checked against each index (Ubuntu noble, Debian bookworm, Arch,
Fedora mdapi, Tumbleweed oss, void-packages, Gentoo), not installed. The
installed app wasn't opened (only `magpie version`), to keep off ports
other sessions use there. Termux and macOS paths are unchanged and their
tests pass.
---
README.md | 2 +-
README.zh-CN.md | 2 +-
docs/reference.md | 19 ++++-
site/install.test.mjs | 127 +++++++++++++++++++++++++++++-
site/public/docs/ja/start.html | 3 +
site/public/docs/start.html | 3 +
site/public/docs/zh/start.html | 3 +
site/public/install.sh | 139 ++++++++++++++++++++++++++++++---
8 files changed, 281 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index c4eb243ef..cea54f86d 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). 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, or the terminal build where there is no desktop or its WebKitGTK isn't installed (it 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.
**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 6c2e14576..ea097c075 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)。 用 `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall` 卸载脚本装上的东西;`~/.config/magpie` 里的设置会保留,加 `--purge` 才会断开 Agent 并一起删除。
+Mac 版已签名并公证,每个版本都会自动更新。Linux 上脚本装桌面版;没有桌面或没装 WebKitGTK 时装终端版(并告诉你该装哪个包),用 `--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 并一起删除。
**2 · 添加 provider**。打开 magpie,进入 **Providers → 添加 provider**。选一个预设、粘贴 key,或者登录一个订阅。
diff --git a/docs/reference.md b/docs/reference.md
index b4793aaad..c45c5530c 100644
--- a/docs/reference.md
+++ b/docs/reference.md
@@ -2562,13 +2562,28 @@ with a link builder: .
Download the app for macOS, Windows or Linux from
[usemagpie.ai](https://usemagpie.ai), or install it from a terminal (on
-Linux, the desktop app when WebKitGTK 4.1 is installed, the command
-otherwise):
+Linux, the desktop app when GTK 3 and WebKitGTK 4.1 are installed, the
+terminal build otherwise):
```sh
curl -fsSL https://usemagpie.ai/install.sh | sh
```
+On Linux the installer asks nothing. A computer with a desktop (a
+graphical session, the user's graphical login when run over ssh, or a
+desktop installed in `xsessions` / `wayland-sessions`) but without the
+app's libraries gets the terminal build, and the installer ends with the
+command that installs them on that distribution (`sudo apt install
+libwebkit2gtk-4.1-0` on Debian and Ubuntu, `sudo dnf install
+webkit2gtk4.1` on Fedora, `sudo pacman -S --needed webkit2gtk-4.1` on
+Arch, `sudo zypper install libwebkit2gtk-4_1-0` on openSUSE); run it again
+afterwards for the app. `--gui` installs the app at once, before its
+libraries; `--tui` (or `MAGPIE_CLI=1`) installs the terminal build on a
+desktop too. The libraries are looked up with `ldconfig -p`, in `/sbin`
+as well, since a Debian user's `PATH` doesn't have it, and in the usual
+library folders where there is no cache. On musl (Alpine) it is always the
+terminal build.
+
Behind a firewall, or without access to GitHub, both the installer and
`magpie update` take `--proxy ` (http, https, socks5, socks5h; or
`MAGPIE_PROXY`, and `HTTPS_PROXY` / `ALL_PROXY` as usual) and
diff --git a/site/install.test.mjs b/site/install.test.mjs
index b6db00b90..a1e6373f2 100644
--- a/site/install.test.mjs
+++ b/site/install.test.mjs
@@ -9,7 +9,7 @@ import { fileURLToPath } from "node:url";
const installer = fileURLToPath(new URL("./public/install.sh", import.meta.url));
-function install(t, { termux = true, arch = "aarch64", override = false, prefixOnly = false, missing = false, corrupt = false, desktop = false, github = false, args = [], env: extra = {}, tamper = "" } = {}) {
+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 = "" } = {}) {
const dir = mkdtempSync(join(tmpdir(), "magpie-install-"));
t.after(() => rmSync(dir, { recursive: true, force: true }));
const tools = join(dir, "tools");
@@ -26,13 +26,34 @@ function install(t, { termux = true, arch = "aarch64", override = false, prefixO
const file = termux ? `magpie-cli-android-${cpu}` : desktop ? `magpie-linux-${cpu}` : `magpie-cli-linux-${cpu}`;
const assets = {};
// A Linux asset is present even when Android's is missing: never use it.
- for (const name of [file, `magpie-cli-linux-${cpu}`]) {
+ for (const name of new Set([file, `magpie-cli-linux-${cpu}`, `magpie-linux-${cpu}`])) {
if (missing && name === file) continue;
assets[name] = { url: github ? `https://github.com/yetone/magpie-releases/releases/download/vtest/${name}` : `https://download.invalid/${name}`, sha256: corrupt ? "0".repeat(64) : createHash("sha256").update(payload).digest("hex") };
}
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 });
+ // ldconfig -p as glibc prints it: the libraries the desktop app needs
+ // when libs, and another library always (a cache that was read)
+ const cache = ["libc.so.6", ...(libs ? ["libgtk-3.so.0", "libwebkit2gtk-4.1.so.0"] : [])]
+ .map((n) => `\t${n} (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/${n}`).join("\n");
+ writeFileSync(join(tools, "ldconfig.txt"), cache + "\n");
+ writeFileSync(join(tools, "ldconfig"), `#!/bin/sh\ncat "${join(tools, "ldconfig.txt").replaceAll("\\", "/")}"\n`, { mode: 0o755 });
+ // logind: the graphical session this user is logged in to, if any
+ // (INSTALL_LOGIN " "); logind names a tty login when there is
+ // no graphical one
+ writeFileSync(join(tools, "loginctl"), `#!/bin/sh
+set -- "$@" "" "" "" "" ""
+id=\${INSTALL_LOGIN%% *} type=\${INSTALL_LOGIN#* }
+[ "$1 $3 $4 $5" = "show-user -p Display --value" ] && [ -n "$id" ] && echo "$id"
+[ "$1 $2 $3 $4 $5" = "show-session $id -p Type --value" ] && [ -n "$id" ] && echo "$type"
+exit 0
+`, { mode: 0o755 });
+ const dataDirs = join(dir, "data-dirs");
+ for (const s of sessions) {
+ mkdirSync(join(dataDirs, s.split("/")[0]), { recursive: true });
+ writeFileSync(join(dataDirs, s), "[Desktop Entry]\n");
+ }
+ writeFileSync(join(dir, "os-release"), distro);
// xdg-mime as xdg-utils writes the default: one line in mimeapps.list
writeFileSync(join(tools, "xdg-mime"), `#!/bin/sh
[ "$1" = default ] || exit 0
@@ -56,7 +77,17 @@ else fs.writeFileSync(args[args.indexOf("-o") + 1], tamper && url.startsWith(tam
PREFIX: termux ? prefix : "",
TERMUX_VERSION: termux && !prefixOnly ? "test" : "",
MAGPIE_BIN_DIR: override ? bin : "",
- MAGPIE_CLI: desktop ? "" : "1",
+ MAGPIE_CLI: cli ? "1" : "",
+ // a headless shell unless a test gives it a desktop
+ DISPLAY: "",
+ WAYLAND_DISPLAY: "",
+ XDG_CURRENT_DESKTOP: "",
+ XDG_SESSION_DESKTOP: "",
+ DESKTOP_SESSION: "",
+ XDG_SESSION_TYPE: "",
+ XDG_DATA_DIRS: dataDirs,
+ INSTALL_LOGIN: login,
+ MAGPIE_OS_RELEASE: join(dir, "os-release"),
PATH: tools + ":" + process.env.PATH,
XDG_CONFIG_HOME: join(dir, "config"),
XDG_DATA_HOME: join(dir, "share"),
@@ -292,3 +323,91 @@ test("--uninstall in Termux takes off PREFIX/bin/magpie", (t) => {
assert.equal(existsSync(join(r.bin, "magpie")), false);
assert.match(u.stdout, /removed .*com\.termux\/files\/usr\/bin\/magpie/);
});
+
+// shuhai on Discord: on a Linux desktop the script installed the terminal
+// build, with one line at the end about WebKitGTK. The build is chosen with
+// nothing asked: the desktop app when its libraries are there; on a
+// desktop without them, the terminal build and, said last, the command
+// that installs them on this distribution; --gui and --tui choose instead.
+function linux(t, opts) {
+ const r = install(t, { termux: false, cli: false, ...opts });
+ assert.equal(r.status, 0, r.stderr);
+ const gui = /magpie-linux-arm64/.test(r.requests);
+ assert.notEqual(gui, /magpie-cli-linux-arm64/.test(r.requests), r.requests);
+ assert.equal(existsSync(join(r.share, "applications/magpie.desktop")), gui);
+ return { ...r, gui };
+}
+const last = (r, n) => r.stdout.trimEnd().split("\n").slice(-n).join("\n");
+
+test("Linux with GTK 3 and WebKitGTK 4.1 gets the desktop app, with nothing to install", (t) => {
+ for (const env of [{ DISPLAY: ":0" }, { WAYLAND_DISPLAY: "wayland-0" }, {}]) {
+ const r = linux(t, { libs: true, env });
+ assert.ok(r.gui, JSON.stringify(env));
+ assert.doesNotMatch(r.stdout, /WebKitGTK|apt install/);
+ }
+});
+
+test("a desktop without WebKitGTK gets the terminal build and its distribution's command, said last", (t) => {
+ const desktops = [
+ { env: { DISPLAY: ":0" } },
+ { env: { WAYLAND_DISPLAY: "wayland-0" } },
+ { env: { XDG_CURRENT_DESKTOP: "XFCE" } },
+ { env: { XDG_SESSION_TYPE: "wayland" } },
+ // ssh into a computer whose user is logged in to its desktop
+ { login: "2 x11" },
+ { login: "c3 wayland" },
+ // or that has a desktop to log in to
+ { sessions: ["xsessions/xfce.desktop"] },
+ { sessions: ["wayland-sessions/gnome.desktop"] },
+ ];
+ for (const opts of desktops) {
+ const r = linux(t, { libs: false, ...opts });
+ assert.equal(r.gui, false, JSON.stringify(opts));
+ assert.match(r.stdout, /has a desktop, but the desktop app needs GTK 3 and WebKitGTK 4\.1/);
+ assert.match(last(r, 4), /sudo apt install libwebkit2gtk-4\.1-0/, JSON.stringify(opts));
+ assert.match(last(r, 4), /install\.sh \| sh -s -- --gui/);
+ }
+ for (const [distro, want] of [
+ ["ID=fedora\n", /sudo dnf install webkit2gtk4\.1/],
+ ['ID="linuxmint"\nID_LIKE="ubuntu debian"\n', /sudo apt install libwebkit2gtk-4\.1-0/],
+ ["ID=endeavouros\nID_LIKE=arch\n", /sudo pacman -S --needed webkit2gtk-4\.1/],
+ ['ID="opensuse-tumbleweed"\nID_LIKE="opensuse suse"\n', /sudo zypper install libwebkit2gtk-4_1-0/],
+ ["ID=nixos\n", /install WebKitGTK 4\.1 \(webkit2gtk 4\.1\) from your distribution/],
+ ]) {
+ const r = linux(t, { libs: false, distro, env: { DISPLAY: ":0" } });
+ assert.match(r.stdout, want, distro);
+ }
+});
+
+test("a headless Linux without WebKitGTK gets the terminal build and no desktop advice", (t) => {
+ // no login at all, or a tty login (an ssh shell's, on a server or in WSL)
+ for (const login of ["", "135 tty"]) {
+ const r = linux(t, { libs: false, login });
+ assert.equal(r.gui, false);
+ assert.match(r.stdout, /installed the terminal build/);
+ assert.doesNotMatch(r.stdout, /WebKitGTK|apt install|--gui/, login);
+ }
+});
+
+test("--gui installs the desktop app before its libraries, and says what installs them", (t) => {
+ const r = linux(t, { libs: false, args: ["--gui"] });
+ assert.ok(r.gui);
+ assert.match(last(r, 2), /aren't installed; it opens once they are/);
+ assert.match(last(r, 2), /sudo apt install libwebkit2gtk-4\.1-0/);
+ // the flag wins over MAGPIE_CLI=1
+ const over = linux(t, { libs: true, cli: true, args: ["--gui"] });
+ assert.ok(over.gui);
+ assert.doesNotMatch(over.stdout, /aren't installed/);
+});
+
+test("--tui and MAGPIE_CLI=1 install the terminal build on a desktop with WebKitGTK", (t) => {
+ for (const opts of [{ args: ["--tui"] }, { cli: true }]) {
+ const r = linux(t, { libs: true, env: { DISPLAY: ":0" }, ...opts });
+ assert.equal(r.gui, false, JSON.stringify(opts));
+ assert.doesNotMatch(r.stdout, /WebKitGTK/);
+ }
+ const help = install(t, { termux: false, args: ["--help"] });
+ assert.equal(help.status, 0);
+ assert.match(help.stdout, /--gui .*desktop app/);
+ assert.match(help.stdout, /--tui .*terminal build/);
+});
diff --git a/site/public/docs/ja/start.html b/site/public/docs/ja/start.html
index 23295b6a3..aa2d9c380 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 を通ります。
+
+ GTK 3 と WebKitGTK 4.1 が入っていればデスクトップアプリ(ウィンドウ、トレイアイコン、アプリメニューの項目)です。デスクトップがあってもそれらが無いときはターミナル版(magpie tui、magpie web と CLI)を入れ、最後にそのディストリビューションで入れるコマンドを表示します。Debian・Ubuntu なら sudo apt install libwebkit2gtk-4.1-0、Fedora なら sudo dnf install webkit2gtk4.1 です。入れたあとインストーラをもう一度実行するとアプリになります。デスクトップ上で実行しても ssh 越しでも、グラフィカルなセッション、あなたのグラフィカルなログイン、ログインできるデスクトップ環境のどれかがあればデスクトップありと判断します。デスクトップの無いサーバーにはターミナル版です。何も質問しないので curl … | sh はそのまま無人で動きます。自分で選ぶには --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 と同じことを行い、プログラム本体は手動で削除します。
diff --git a/site/public/docs/start.html b/site/public/docs/start.html
index cf5250390..680ee8a7d 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.
+
+ The desktop app (window, tray icon and a menu entry) when GTK 3 and WebKitGTK 4.1 are installed. A computer with a desktop but without them gets the terminal build (magpie tui, magpie web and the CLI), and the installer ends with the command that installs them on your distribution, 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. Nothing is asked, so curl … | sh runs unattended; to choose yourself, add --gui (the app now, the libraries after) or --tui: 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.
diff --git a/site/public/docs/zh/start.html b/site/public/docs/zh/start.html
index 4037f74f3..8a319a3ed 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,而不是镜像,镜像改过的文件会被拒绝安装。应用自己的更新走 设置 → 代理。
+
+ 装了 GTK 3 和 WebKitGTK 4.1 时装桌面版(窗口、托盘图标和应用菜单项)。有桌面但缺这两个库时,先装终端版(magpie tui、magpie web 和命令行),脚本最后会给出你这个发行版装库的命令,比如 Debian、Ubuntu 上是 sudo apt install libwebkit2gtk-4.1-0,Fedora 上是 sudo dnf install webkit2gtk4.1;装好后再运行一次安装脚本就换成桌面版。在桌面上运行还是 ssh 进去运行都算有桌面:有图形会话、你登录着图形界面,或者装了可登录的桌面环境。没有桌面的服务器装终端版。脚本什么都不问,curl … | sh 可以无人值守;想自己选,加 --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 那些事,程序本身留给你删除。
diff --git a/site/public/install.sh b/site/public/install.sh
index 0e3bdafe8..9ba680846 100644
--- a/site/public/install.sh
+++ b/site/public/install.sh
@@ -3,9 +3,11 @@
#
# macOS: puts magpie.app in /Applications (~/Applications when that is not
# writable) and links the magpie command into ~/.local/bin.
-# Linux: puts magpie in ~/.local/bin — the desktop app when GTK 3 and
-# WebKitGTK 4.1 are installed (with a menu entry), the terminal build
-# otherwise or with MAGPIE_CLI=1.
+# Linux: puts magpie in ~/.local/bin — the desktop app (with a menu entry)
+# when GTK 3 and WebKitGTK 4.1 are installed, the terminal build otherwise.
+# A computer with a desktop but without them gets the terminal build and
+# the command that installs them on its distribution; --gui and --tui
+# choose instead (MAGPIE_CLI=1 is --tui). Nothing is asked.
# Termux: installs the Android terminal build into $PREFIX/bin.
# Every download is checked against the release's SHA-256.
#
@@ -20,6 +22,10 @@
# list and its SHA-256 still come from usemagpie.ai,
# never from the mirror, so a file the mirror changed is
# refused.
+# --gui the desktop app, on Linux even before its libraries are
+# installed (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
# command, and the app (macOS) or its menu entry, icon
# and magpie:// handler (Linux), and the service and
@@ -36,6 +42,9 @@ bin="${MAGPIE_BIN_DIR:-$HOME/.local/bin}"
proxy="${MAGPIE_PROXY:-}"
mirror="${MAGPIE_MIRROR:-}"
uninstall=
+build=
+nolibs=
+[ -z "${MAGPIE_CLI:-}" ] || build=tui
say() { printf ' %s\n' "$*"; }
die() { printf 'magpie: %s\n' "$*" >&2; exit 1; }
@@ -48,16 +57,20 @@ while [ $# -gt 0 ]; do
--mirror=*) mirror=${1#--mirror=}; shift ;;
--uninstall) [ "$uninstall" = purge ] || uninstall=1; shift ;;
--purge) uninstall=purge; shift ;;
+ --gui) build=gui; shift ;;
+ --tui|--cli) build=tui; shift ;;
-h|--help)
- printf '%s\n' "usage: curl -fsSL $site/install.sh | sh -s -- [--proxy ] [--mirror ]" \
+ printf '%s\n' "usage: curl -fsSL $site/install.sh | sh -s -- [--gui | --tui] [--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" \
+ " --gui Linux: the desktop app, even before GTK 3 and WebKitGTK 4.1 are installed" \
+ " --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)"
exit 0 ;;
- *) die "unknown option $1 (--proxy , --mirror , --uninstall, --purge)" ;;
+ *) die "unknown option $1 (--gui, --tui, --proxy , --mirror , --uninstall, --purge)" ;;
esac
done
case "$proxy" in
@@ -177,6 +190,93 @@ if [ -n "$uninstall" ]; then
exit 0
fi
+# has_gui_libs: GTK 3 and WebKitGTK 4.1 (which brings libsoup 3 and
+# JavaScriptCore) can be loaded, which is all the desktop app links beyond
+# glibc. ldconfig is in /sbin, off a Debian user's PATH, so it is looked for
+# there too; with no cache to ask (NixOS, Guix), the usual folders are.
+# musl: the desktop app is built against glibc and can't start on musl
+# (Alpine); the terminal build is static and runs anywhere
+musl() {
+ for l in /lib/ld-musl-*; do [ ! -e "$l" ] || return 0; done
+ return 1
+}
+has_gui_libs() {
+ libs=
+ for l in "$(command -v ldconfig 2>/dev/null)" /sbin/ldconfig /usr/sbin/ldconfig; do
+ [ -n "$l" ] && [ -x "$l" ] || continue
+ libs=$("$l" -p 2>/dev/null) && [ -n "$libs" ] && break
+ libs=
+ done
+ if [ -n "$libs" ]; then
+ printf '%s\n' "$libs" | grep -q 'libwebkit2gtk-4\.1\.so\.0 ' &&
+ printf '%s\n' "$libs" | grep -q 'libgtk-3\.so\.0 '
+ return
+ fi
+ for want in libwebkit2gtk-4.1.so.0 libgtk-3.so.0; do
+ found=
+ for d in /usr/lib/*-linux-gnu /lib/*-linux-gnu /usr/lib64 /lib64 /usr/lib /lib; do
+ [ ! -e "$d/$want" ] || { found=1; break; }
+ done
+ [ -n "$found" ] || return 1
+ done
+}
+
+# has_desktop: a graphical session here (DISPLAY, WAYLAND_DISPLAY, a
+# desktop's variables), a graphical login of this user that an ssh shell
+# doesn't inherit (logind), or a desktop installed to log in to
+has_desktop() {
+ [ -z "${DISPLAY:-}${WAYLAND_DISPLAY:-}${XDG_CURRENT_DESKTOP:-}${XDG_SESSION_DESKTOP:-}${DESKTOP_SESSION:-}" ] || return 0
+ case "${XDG_SESSION_TYPE:-}" in x11|wayland|mir) return 0 ;; esac
+ if command -v loginctl >/dev/null 2>&1; then
+ # Display falls back to a tty login when there is no graphical one,
+ # so the session's own type is what tells
+ s=$(loginctl show-user "$(id -un 2>/dev/null)" -p Display --value 2>/dev/null) || s=
+ if [ -n "$s" ]; then
+ case "$(loginctl show-session "$s" -p Type --value 2>/dev/null)" in
+ x11|wayland|mir) return 0 ;;
+ esac
+ fi
+ fi
+ dirs=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
+ old=$IFS; IFS=:
+ for d in $dirs; do
+ for f in "$d"/xsessions/*.desktop "$d"/wayland-sessions/*.desktop; do
+ [ ! -e "$f" ] || { IFS=$old; return 0; }
+ done
+ done
+ IFS=$old
+ return 1
+}
+
+# gui_packages: the command that installs the desktop app's libraries on
+# this distribution, or nothing when it isn't one we know
+gui_packages() {
+ id='' like=''
+ # MAGPIE_OS_RELEASE: another os-release, for the installer's tests
+ rel=${MAGPIE_OS_RELEASE:-/etc/os-release}
+ [ -r "$rel" ] || rel=/usr/lib/os-release
+ if [ -r "$rel" ]; then
+ id=$(sed -n 's/^ID=//p' "$rel" | tr -d "\"'" | head -n 1)
+ like=$(sed -n 's/^ID_LIKE=//p' "$rel" | tr -d "\"'" | head -n 1)
+ fi
+ for d in $id $like; do
+ case "$d" in
+ debian|ubuntu|linuxmint|pop|elementary|zorin|kali|raspbian|deepin|uos)
+ echo "sudo apt install libwebkit2gtk-4.1-0"; return ;;
+ fedora|rhel|centos|rocky|almalinux|nobara|openeuler|anolis)
+ echo "sudo dnf install webkit2gtk4.1"; return ;;
+ arch|manjaro|endeavouros|cachyos|garuda)
+ echo "sudo pacman -S --needed webkit2gtk-4.1"; return ;;
+ opensuse*|suse|sles)
+ echo "sudo zypper install libwebkit2gtk-4_1-0"; return ;;
+ void)
+ echo "sudo xbps-install -S libwebkit2gtk41"; return ;;
+ gentoo)
+ echo "sudo emerge net-libs/webkit-gtk:4.1"; return ;;
+ esac
+ done
+}
+
case "$(uname -m)" in
arm64|aarch64) arch=arm64 ;;
x86_64|amd64) arch=amd64 ;;
@@ -187,9 +287,14 @@ case "$os" in
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 ;;
+ case "$build" in
+ gui) ! musl || die "the desktop app is built for glibc and can't run on musl (Alpine): install the terminal build with --tui"
+ file="magpie-linux-$arch" ;;
+ tui) ;;
+ *) if musl; then :
+ elif has_gui_libs; then file="magpie-linux-$arch"
+ elif has_desktop; then nolibs=1; fi ;;
+ esac ;;
esac
tmp=$(mktemp -d)
@@ -258,7 +363,7 @@ EOF
elif [ "$os" = android ]; then
say "installed the Termux build; use magpie web for the browser UI or magpie tui for the terminal UI"
else
- say "installed the terminal build; for the desktop app, install WebKitGTK 4.1 (libwebkit2gtk-4.1-0) and run this again"
+ say "installed the terminal build (TUI, web UI and CLI)"
fi
fi
say "installed $bin/magpie"
@@ -272,3 +377,19 @@ case "$file" in
magpie-linux-*) say "open it from your app menu, or run: magpie app" ;;
*) say "run it: magpie" ;;
esac
+# the desktop app without what it needs: what installs it, said last so it
+# is what the user reads
+if [ "$file" = "magpie-linux-$arch" ] && ! has_gui_libs; then
+ pkgs=$(gui_packages)
+ say ""
+ say "the desktop app needs GTK 3 and WebKitGTK 4.1, which aren't installed; it opens once they are:"
+ say " ${pkgs:-install WebKitGTK 4.1 (webkit2gtk 4.1) from your distribution}"
+elif [ -n "${nolibs:-}" ]; then
+ pkgs=$(gui_packages)
+ say ""
+ say "this computer has a desktop, but the desktop app needs GTK 3 and WebKitGTK 4.1, which aren't installed,"
+ say "so the terminal build was installed. For the desktop app, install them and run this again:"
+ say " ${pkgs:-install WebKitGTK 4.1 (webkit2gtk 4.1) from your distribution}"
+ say " curl -fsSL $site/install.sh | sh"
+ say "or install the desktop app now and the libraries after: curl -fsSL $site/install.sh | sh -s -- --gui"
+fi