安装说明
Link Agent 是跑在服务器上的 AI 守护进程:没有图形界面,装好后对 IDE 客户端和手机端提供 WebSocket 服务。桌面版 IDE 是另一个安装包,见下载区。
一行装完
把下面这一行粘进终端回车。装完新开一个终端,就能直接用 link-agent 命令。
curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh
不想直接执行?把行尾的 | sh 去掉,先用浏览器读本页最下面的源码——那是线上脚本的中文注释版,逻辑与它完全一致——再自己跑。
这条命令做了什么
- 读取版本清单,拿到最新版本号、包地址、sha256 与文件大小;
- 下载对应平台的安装包;
- 比对清单里的 sha256 与文件大小,不一致立即中止;
- 解包到临时目录,只取需要的可执行文件;
- 装到
~/.local/bin; - 把这个目录加进 PATH,注册开机自启并立即启动一次。
全程只写你自己的 home 目录,不需要 root;任何一步失败立刻退出,不会留下半成品。
可选参数
参数接在 sh -s -- 之后,例如只装二进制、不启服务:
curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh -s -- --no-service
| 参数 | 作用 |
|---|---|
--prefix=DIR | 装到别处,可执行文件进 DIR/bin(默认 ~/.local) |
--no-modify-path | 不改 shell 配置,只打印需要自己添加的那一行 |
--no-service | 只装二进制,不注册自启、不启动 |
--with-panel | 装带桌面面板的版本:多一个 link-agent-panel 命令,并在应用菜单里加一项 Link Agent Panel(面板包还没发布时会明确报错,不会装成半成品) |
--dry-run | 只预演:读清单、打印将要做什么,不下载也不写入 |
-h / --help | 显示用法 |
装完之后
link-agent status # 看守护进程状态
link-agent install --autostart --start # 手动注册自启并启动
link-agent uninstall # 移除开机自启
网页控制台:http://127.0.0.1:9876/admin,首次使用见说明文档。
安全说明
- 下载全程 HTTPS;包按清单里的 sha256 与文件大小校验,不一致就中止,不装任何文件;
- 只写用户目录,不碰
/usr、不需要 sudo,检测到 root 会直接拒绝运行; - PATH 只追加一行带
# added by link-agent installer标记的配置,重复执行不会重复追加,也可用--no-modify-path完全跳过; - 下面就是完整源码,可以先读再跑。
卸载
link-agent uninstall
rm -f ~/.local/bin/link-agent ~/.local/bin/rg
如果安装时改过 PATH,再把 shell 配置里那行带 # added by link-agent installer 的删掉。
完整源码(中文注释版 install.zh.sh)
页面最上面那条命令执行的是英文注释版 install.sh;下面是同一份脚本的中文注释版 install.zh.sh(共 268 行),逻辑与英文版逐行对应,只是注释和提示换成了中文,方便对照阅读。可以全选复制、存成文件后自己执行。
#!/bin/sh
# ─────────────────────────────────────────────────────────────────────────────
# Turtle Link · Link Agent —— 一行安装脚本(Linux x86_64)
#
# curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh
#
# 全文源码与说明页: https://www.turtle-link.com/install.html
# 脚本只写你自己的 home 目录,不需要 root;任何一步失败立即退出,不留半成品。
#
# 可选参数(接在 `sh -s --` 之后):
# --prefix=DIR 安装前缀,默认 $HOME/.local(可执行文件进 DIR/bin)
# --no-modify-path 不改 shell 配置文件,只打印需要添加的那一行
# --no-service 只装二进制,不注册开机自启、不后台启动
# --with-panel 包里带桌面面板时一并安装(含应用菜单图标)
# --dry-run 只打印将要做的事,不下载、不写入
# -h, --help 显示这份说明
# ─────────────────────────────────────────────────────────────────────────────
set -eu
BASE_URL="${LINK_AGENT_BASE_URL:-https://www.turtle-link.com/turtle-updates}"
PREFIX="${PREFIX:-${HOME:?HOME 未设置,无法确定安装位置}/.local}"
MODIFY_PATH=1
WANT_SERVICE=1
WANT_PANEL=0
DRY_RUN=0
if [ -t 1 ]; then
C_STEP='\033[36m'; C_WARN='\033[33m'; C_ERR='\033[31m'; C_OK='\033[32m'; C_OFF='\033[0m'
else
C_STEP=''; C_WARN=''; C_ERR=''; C_OK=''; C_OFF=''
fi
step() { printf "${C_STEP}▸ %s${C_OFF}\n" "$*"; }
say() { printf ' %s\n' "$*"; }
warn() { printf "${C_WARN}! %s${C_OFF}\n" "$*" >&2; }
die() { printf "${C_ERR}✗ %s${C_OFF}\n" "$*" >&2; exit 1; }
usage() {
cat <<'TXT'
Turtle Link · Link Agent 一行安装(Linux x86_64)
用法:
curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh
参数(接在 `sh -s --` 之后):
--prefix=DIR 安装前缀,默认 $HOME/.local(可执行文件进 DIR/bin)
--no-modify-path 不改 shell 配置文件,只打印需要添加的那一行
--no-service 只装二进制,不注册开机自启、不后台启动
--with-panel 包里带桌面面板时一并安装(含应用菜单图标)
--dry-run 只打印将要做的事,不下载、不写入
-h, --help 显示这份说明
环境变量:
PREFIX 同 --prefix
LINK_AGENT_BASE_URL 清单与包的基地址,默认 https://www.turtle-link.com/turtle-updates
脚本源码页:https://www.turtle-link.com/install.html
TXT
}
for arg in "$@"; do
case "$arg" in
--prefix=*) PREFIX="${arg#--prefix=}" ;;
--no-modify-path) MODIFY_PATH=0 ;;
--no-service) WANT_SERVICE=0 ;;
--with-panel) WANT_PANEL=1 ;;
--dry-run) DRY_RUN=1 ;;
-h|--help) usage; exit 0 ;;
*) die "未知参数:$arg(可用 --help 查看用法)" ;;
esac
done
BIN="$PREFIX/bin"
step "检查环境"
[ "$(id -u)" = 0 ] && die "请用普通用户运行,不要 sudo / root —— 脚本只写当前用户的 home 目录"
os=$(uname -s 2>/dev/null || echo unknown)
arch=$(uname -m 2>/dev/null || echo unknown)
[ "$os" = "Linux" ] || die "一行安装命令目前只支持 Linux(检测到 $os);macOS / Windows 请到官网下载离线包,解压后运行包内的 install.sh / install.ps1"
case "$arch" in
x86_64|amd64) ;;
*) die "目前只提供 x86_64 架构的包(检测到 $arch)" ;;
esac
say "系统:Linux $arch"
if command -v curl >/dev/null 2>&1; then
fetch() { curl -fsSL --retry 3 --retry-delay 1 -o "$2" "$1"; }
elif command -v wget >/dev/null 2>&1; then
fetch() { wget -q -O "$2" "$1"; }
else
die "需要 curl 或 wget 才能下载,请先安装其中一个"
fi
sha256_of() {
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}'
elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | awk '{print $1}'
elif command -v openssl >/dev/null 2>&1; then openssl dgst -sha256 "$1" | awk '{print $NF}'
else printf ''; fi
}
extract_zip() {
if command -v unzip >/dev/null 2>&1; then unzip -q "$1" -d "$2"
elif command -v python3 >/dev/null 2>&1; then
python3 -c 'import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])' "$1" "$2"
else die "需要 unzip 或 python3 才能解包"
fi
}
# 从清单里读一个字段。点号路径可深入嵌套对象(full.url / full.sha256 /
# full.size)—— 现在发布的清单是嵌套结构,所以交给 python3 做真正的 JSON
# 解析。没有 python3 时退回下面的 awk,只认扁平的老清单;嵌套清单下它取
# 不到值,会由后面的 size / sha256 校验拦下,不会装错包。
json_field() {
__key="$1"
__file="$2"
if command -v python3 >/dev/null 2>&1; then
python3 -c '
import json, sys
try:
node = json.load(open(sys.argv[2], encoding="utf-8"))
for part in sys.argv[1].split("."):
node = node[part]
except Exception:
sys.exit(3)
print("" if node is None else ("true" if node is True else ("false" if node is False else node)))
' "$__key" "$__file" 2>/dev/null || true
return 0
fi
awk -v k="\"${__key##*.}\"" 'index($0, k) {
v = $0
sub(/^[^:]*:[ \t]*/, "", v)
sub(/,[ \t]*$/, "", v)
gsub(/^"|"$/, "", v)
print v
exit
}' "$__file"
}
TMP=""
cleanup() { [ -n "$TMP" ] && [ -d "$TMP" ] && rm -rf "$TMP"; }
trap cleanup EXIT INT TERM
step "读取版本清单"
TMP=$(mktemp -d 2>/dev/null || mktemp -d -t linkagent) || die "无法创建临时目录"
# 桌面面板不再是独立包:它和主程序打在同一份 stable-link-agent 包里
# (1.0.2 起三个平台的包内都带 panel)
MANIFEST_NAME="stable-link-agent-linux.json"
if [ "$WANT_PANEL" = 1 ]; then
say "产品形态:无头服务端 + 桌面面板(同一个包)"
else
say "产品形态:无头服务端"
fi
MANIFEST="$TMP/$MANIFEST_NAME"
fetch "$BASE_URL/$MANIFEST_NAME" "$MANIFEST" || die "拉取清单失败:$BASE_URL/$MANIFEST_NAME(网络或地址不可用)
只想装无头服务端,去掉 --with-panel 再跑一次:
curl -fsSL $BASE_URL/install.sh | sh"
version=$(json_field version "$MANIFEST")
url=$(json_field full.url "$MANIFEST"); [ -n "$url" ] || url=$(json_field url "$MANIFEST")
sha=$(json_field full.sha256 "$MANIFEST"); [ -n "$sha" ] || sha=$(json_field sha256 "$MANIFEST")
size=$(json_field full.size "$MANIFEST"); [ -n "$size" ] || size=$(json_field size "$MANIFEST")
[ -n "$version" ] && [ -n "$url" ] && [ -n "$sha" ] || die "清单格式异常:缺少 version / url / sha256"
say "最新版本:$version"
say "包的地址:$url"
say "安装到: $BIN"
if [ "$DRY_RUN" = 1 ]; then
step "预演模式(--dry-run):不下载、不写入"
say "接下来会:下载包 → 校验 sha256 → 解包 → 装到 $BIN → 处理 PATH → 注册自启并启动"
say "去掉 --dry-run 才会真正执行。"
exit 0
fi
step "下载安装包"
ZIP="$TMP/link-agent.zip"
fetch "$url" "$ZIP" || die "下载失败:$url"
actual_bytes=$(wc -c < "$ZIP" | tr -d ' ')
say "已下载 $((actual_bytes / 1048576)) MB"
if [ -n "$size" ] && [ "$actual_bytes" != "$size" ]; then
die "大小不符:清单 $size 字节,实际 $actual_bytes 字节,已中止(未安装任何文件)"
fi
step "校验文件摘要"
want=$(printf '%s' "$sha" | tr 'A-Z' 'a-z')
got=$(sha256_of "$ZIP" | tr 'A-Z' 'a-z')
[ -n "$got" ] || die "找不到 sha256sum / shasum / openssl,无法校验,已中止"
[ "$got" = "$want" ] || die "sha256 不符,包可能被篡改或下载不完整,已中止
期望 $want
实际 $got"
say "sha256 一致:$(printf '%s' "$got" | cut -c1-16)…"
step "解包"
STAGE="$TMP/stage"
mkdir -p "$STAGE"
extract_zip "$ZIP" "$STAGE"
[ -f "$STAGE/link-agent" ] || die "包里没有 link-agent 可执行文件,包结构异常"
step "安装到 $BIN"
mkdir -p "$BIN" || die "无法创建 $BIN"
install -m 755 "$STAGE/link-agent" "$BIN/link-agent" || die "写入 $BIN/link-agent 失败"
for extra in rg link-agent-panel; do
if [ -f "$STAGE/$extra" ]; then install -m 755 "$STAGE/$extra" "$BIN/$extra" || true; fi
done
say "已安装 $BIN/link-agent"
if [ "$WANT_PANEL" = 1 ]; then
[ -f "$STAGE/link-agent-panel" ] || die "面板包里没有 link-agent-panel,包结构异常,已中止(未注册服务)"
[ -x "$BIN/link-agent-panel" ] || die "写入 $BIN/link-agent-panel 失败"
say "已安装 $BIN/link-agent-panel(桌面面板)"
fi
if [ "$WANT_PANEL" = 1 ]; then
step "安装桌面菜单项"
DATA="${XDG_DATA_HOME:-$HOME/.local/share}"
ICON_DIR="$DATA/icons/hicolor/256x256/apps"
APP_DIR="$DATA/applications"
mkdir -p "$ICON_DIR" "$APP_DIR" || die "无法创建 $APP_DIR"
if [ -f "$STAGE/link-agent.png" ]; then
install -m 644 "$STAGE/link-agent.png" "$ICON_DIR/link-agent.png" || warn "图标写入失败,不影响使用"
fi
cat > "$APP_DIR/link-agent-panel.desktop" <<DESKTOP
[Desktop Entry]
Type=Application
Name=Link Agent Panel
Comment=Turtle Link · Link Agent 桌面面板
Exec=$BIN/link-agent-panel
Icon=link-agent
Terminal=false
Categories=Development;Utility;
DESKTOP
command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$APP_DIR" >/dev/null 2>&1 || true
say "已加入应用菜单:Link Agent Panel"
fi
step "检查 PATH"
if printf ':%s:' "$PATH" | grep -qF ":$BIN:"; then
say "$BIN 已在 PATH 中"
else
marker='# added by link-agent installer'
shell_name=$(basename "${SHELL:-sh}")
rc=""
if [ "$shell_name" = "zsh" ]; then
rc="$HOME/.zshrc"
line="export PATH=\"$BIN:\$PATH\" $marker"
elif [ "$shell_name" = "bash" ]; then
if [ "$os" = "Darwin" ] && [ -f "$HOME/.bash_profile" ]; then rc="$HOME/.bash_profile"; else rc="$HOME/.bashrc"; fi
line="export PATH=\"$BIN:\$PATH\" $marker"
elif [ "$shell_name" = "fish" ]; then
rc="$HOME/.config/fish/config.fish"
line="fish_add_path $BIN $marker"
fi
if [ "$MODIFY_PATH" = 1 ] && [ -n "$rc" ]; then
mkdir -p "$(dirname "$rc")"
if [ -f "$rc" ] && grep -qF "$marker" "$rc"; then
say "$rc 里已有安装器写入的 PATH 行,跳过"
else
printf '\n%s\n' "$line" >> "$rc" || die "写入 $rc 失败"
say "已把 $BIN 加进 $rc(行尾带 $marker 标记,方便日后删除)"
fi
say "新开一个终端后生效;当前终端可先执行: export PATH=\"$BIN:\$PATH\""
else
warn "$BIN 不在 PATH 里。请把这一行加进你的 shell 配置:"
say "export PATH=\"$BIN:\$PATH\""
fi
fi
step "验证可执行文件"
"$BIN/link-agent" --version || die "安装成功但 link-agent 无法运行(可能 glibc 版本过低或文件损坏)"
say "二进制可正常运行"
if [ "$WANT_SERVICE" = 1 ]; then
step "注册开机自启并启动一次"
if "$BIN/link-agent" install --autostart --start --aliases; then
say "服务已启动,查看状态: link-agent status"
else
warn "自动启动注册失败,不影响二进制本身。稍后可手动执行:"
say "$BIN/link-agent install --autostart --start"
fi
else
say "已跳过服务注册(--no-service)。需要时执行: link-agent install --autostart --start"
fi
printf '\n%s\n' "${C_OK}装好了${C_OFF}"
say "查看状态: link-agent status"
say "网页控制台: http://127.0.0.1:9876/admin"
if [ "$WANT_PANEL" = 1 ]; then
say "桌面面板: 从应用菜单打开 Link Agent Panel,或在终端执行 link-agent-panel"
fi
say "移除自启: link-agent uninstall"
Install guide
Link Agent is an AI daemon that runs on a server: no graphical interface, it serves WebSocket connections to IDE clients and phones once installed. The desktop IDE is a separate download — see Downloads.
One line
Paste this into a terminal and press Enter. Open a new terminal afterwards and link-agent is ready to use.
curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh
Prefer not to pipe straight into a shell? Drop | sh, read the full source at the bottom of this page first, then run it yourself.
What that command does
- Reads the version manifest to get the latest version, package URL, sha256 and size;
- Downloads the package for your platform;
- Compares sha256 and size against the manifest, aborting on any mismatch;
- Extracts into a temporary directory and picks out the executables;
- Installs them into
~/.local/bin; - Adds that directory to PATH, registers autostart and starts the daemon once.
Everything stays inside your home directory and no root is needed. Any failing step aborts immediately, leaving nothing half-installed.
Options
Options go after sh -s --, for example to install binaries only and skip the service:
curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh -s -- --no-service
| Option | Effect |
|---|---|
--prefix=DIR | Install elsewhere; executables go to DIR/bin (default ~/.local) |
--no-modify-path | Leave shell config alone and print the line to add yourself |
--no-service | Binaries only: no autostart, no start |
--with-panel | Install the desktop-panel build: adds a link-agent-panel command and a Link Agent Panel entry in your application menu (if the panel build is not published yet the installer stops with a clear error instead of half-installing) |
--dry-run | Read the manifest and print what would happen; no download, no writes |
-h / --help | Show usage |
After installing
link-agent status # daemon status
link-agent install --autostart --start # register autostart and start
link-agent uninstall # remove autostart
Web console: http://127.0.0.1:9876/admin — see the docs for first use.
Security notes
- Downloads use HTTPS throughout; the package is verified against the manifest sha256 and size, and any mismatch aborts before anything is installed;
- Only user directories are written — no
/usr, no sudo, and the script refuses to run as root; - PATH gets exactly one appended line marked
# added by link-agent installer; running the installer again will not add it twice, and--no-modify-pathskips it entirely; - The complete source is below — read it before running if you like.
Uninstall
link-agent uninstall
rm -f ~/.local/bin/link-agent ~/.local/bin/rg
If the installer added a PATH line, delete the one marked # added by link-agent installer.
Full source (install.sh)
This page and the installer share one source: the complete install.sh, 271 lines, with English comments and English output. Copy it, save it, run it yourself. A Chinese-commented copy of the same script is published as install.zh.sh.
#!/bin/sh
# ─────────────────────────────────────────────────────────────────────────────
# Turtle Link · Link Agent — one-line installer (Linux x86_64)
#
# curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh
#
# Full source and docs: https://www.turtle-link.com/install.html
# The script writes only inside your own home directory and needs no root;
# the first failing step aborts it, leaving nothing half-installed.
#
# Options (pass them after `sh -s --`):
# --prefix=DIR install prefix, default $HOME/.local (binaries go to DIR/bin)
# --no-modify-path leave shell rc files untouched, just print the line to add
# --no-service install binaries only: no autostart, no background start
# --with-panel also install the desktop panel if the package contains it (menu entry)
# --dry-run print what would happen; no download, no writes
# -h, --help show this help
# ─────────────────────────────────────────────────────────────────────────────
set -eu
BASE_URL="${LINK_AGENT_BASE_URL:-https://www.turtle-link.com/turtle-updates}"
PREFIX="${PREFIX:-${HOME:?HOME is not set, cannot determine the install location}/.local}"
MODIFY_PATH=1
WANT_SERVICE=1
WANT_PANEL=0
DRY_RUN=0
if [ -t 1 ]; then
C_STEP='\033[36m'; C_WARN='\033[33m'; C_ERR='\033[31m'; C_OK='\033[32m'; C_OFF='\033[0m'
else
C_STEP=''; C_WARN=''; C_ERR=''; C_OK=''; C_OFF=''
fi
step() { printf "${C_STEP}▸ %s${C_OFF}\n" "$*"; }
say() { printf ' %s\n' "$*"; }
warn() { printf "${C_WARN}! %s${C_OFF}\n" "$*" >&2; }
die() { printf "${C_ERR}✗ %s${C_OFF}\n" "$*" >&2; exit 1; }
usage() {
cat <<'TXT'
Turtle Link · Link Agent one-line installer (Linux x86_64)
Usage:
curl -fsSL https://www.turtle-link.com/turtle-updates/install.sh | sh
Options (pass them after `sh -s --`):
--prefix=DIR install prefix, default $HOME/.local (binaries go to DIR/bin)
--no-modify-path leave shell rc files untouched, just print the line to add
--no-service install binaries only: no autostart, no background start
--with-panel also install the desktop panel if the package contains it (menu entry)
--dry-run print what would happen; no download, no writes
-h, --help show this help
Environment:
PREFIX same as --prefix
LINK_AGENT_BASE_URL base URL for manifests and packages,
default https://www.turtle-link.com/turtle-updates
Script source: https://www.turtle-link.com/install.html
TXT
}
for arg in "$@"; do
case "$arg" in
--prefix=*) PREFIX="${arg#--prefix=}" ;;
--no-modify-path) MODIFY_PATH=0 ;;
--no-service) WANT_SERVICE=0 ;;
--with-panel) WANT_PANEL=1 ;;
--dry-run) DRY_RUN=1 ;;
-h|--help) usage; exit 0 ;;
*) die "Unknown option: $arg (run --help to see the usage)" ;;
esac
done
BIN="$PREFIX/bin"
step "Checking the environment"
[ "$(id -u)" = 0 ] && die "Run this as a regular user, not root/sudo — it only writes to this user's home directory"
os=$(uname -s 2>/dev/null || echo unknown)
arch=$(uname -m 2>/dev/null || echo unknown)
[ "$os" = "Linux" ] || die "The one-line installer only covers Linux (detected $os); for macOS / Windows, download the offline package from https://www.turtle-link.com and run the install.sh / install.ps1 inside it"
case "$arch" in
x86_64|amd64) ;;
*) die "Only x86_64 packages are available so far (detected $arch)" ;;
esac
say "System: Linux $arch"
if command -v curl >/dev/null 2>&1; then
fetch() { curl -fsSL --retry 3 --retry-delay 1 -o "$2" "$1"; }
elif command -v wget >/dev/null 2>&1; then
fetch() { wget -q -O "$2" "$1"; }
else
die "curl or wget is required to download files; install one of them first"
fi
sha256_of() {
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}'
elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | awk '{print $1}'
elif command -v openssl >/dev/null 2>&1; then openssl dgst -sha256 "$1" | awk '{print $NF}'
else printf ''; fi
}
extract_zip() {
if command -v unzip >/dev/null 2>&1; then unzip -q "$1" -d "$2"
elif command -v python3 >/dev/null 2>&1; then
python3 -c 'import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])' "$1" "$2"
else die "unzip or python3 is required to extract the package"
fi
}
# Read one field out of the JSON manifest. Dotted paths reach into nested
# objects (full.url / full.sha256 / full.size) - the manifest we publish is
# nested now, so python3 does the real parsing. Without python3 the awk
# fallback below still reads a flat, pretty-printed manifest; on a nested
# one it returns nothing, and the size / sha256 checks abort instead of
# installing the wrong package.
json_field() {
__key="$1"
__file="$2"
if command -v python3 >/dev/null 2>&1; then
python3 -c '
import json, sys
try:
node = json.load(open(sys.argv[2], encoding="utf-8"))
for part in sys.argv[1].split("."):
node = node[part]
except Exception:
sys.exit(3)
print("" if node is None else ("true" if node is True else ("false" if node is False else node)))
' "$__key" "$__file" 2>/dev/null || true
return 0
fi
awk -v k="\"${__key##*.}\"" 'index($0, k) {
v = $0
sub(/^[^:]*:[ \t]*/, "", v)
sub(/,[ \t]*$/, "", v)
gsub(/^"|"$/, "", v)
print v
exit
}' "$__file"
}
TMP=""
cleanup() { [ -n "$TMP" ] && [ -d "$TMP" ] && rm -rf "$TMP"; }
trap cleanup EXIT INT TERM
step "Reading the version manifest"
TMP=$(mktemp -d 2>/dev/null || mktemp -d -t linkagent) || die "Cannot create a temporary directory"
# The desktop panel is no longer a separate build: it ships inside the same
# stable-link-agent package (every 1.0.2 platform package contains it).
MANIFEST_NAME="stable-link-agent-linux.json"
if [ "$WANT_PANEL" = 1 ]; then
say "Product: headless server + desktop panel (same package)"
else
say "Product: headless server"
fi
MANIFEST="$TMP/$MANIFEST_NAME"
fetch "$BASE_URL/$MANIFEST_NAME" "$MANIFEST" || die "Could not fetch the manifest: $BASE_URL/$MANIFEST_NAME (network down or wrong URL)
To install the headless server only, drop --with-panel:
curl -fsSL $BASE_URL/install.sh | sh"
version=$(json_field version "$MANIFEST")
url=$(json_field full.url "$MANIFEST"); [ -n "$url" ] || url=$(json_field url "$MANIFEST")
sha=$(json_field full.sha256 "$MANIFEST"); [ -n "$sha" ] || sha=$(json_field sha256 "$MANIFEST")
size=$(json_field full.size "$MANIFEST"); [ -n "$size" ] || size=$(json_field size "$MANIFEST")
[ -n "$version" ] && [ -n "$url" ] && [ -n "$sha" ] || die "Malformed manifest: version / url / sha256 is missing"
say "Latest version: $version"
say "Package URL: $url"
say "Installing to: $BIN"
if [ "$DRY_RUN" = 1 ]; then
step "Dry run (--dry-run): no download, no writes"
say "Next it would: download package → verify sha256 → extract → install to $BIN → handle PATH → register autostart and start"
say "Drop --dry-run to actually run these steps."
exit 0
fi
step "Downloading the package"
ZIP="$TMP/link-agent.zip"
fetch "$url" "$ZIP" || die "Download failed: $url"
actual_bytes=$(wc -c < "$ZIP" | tr -d ' ')
say "Downloaded $((actual_bytes / 1048576)) MB"
if [ -n "$size" ] && [ "$actual_bytes" != "$size" ]; then
die "Size mismatch: manifest says $size bytes, got $actual_bytes bytes — aborted (no file installed)"
fi
step "Verifying the checksum"
want=$(printf '%s' "$sha" | tr 'A-Z' 'a-z')
got=$(sha256_of "$ZIP" | tr 'A-Z' 'a-z')
[ -n "$got" ] || die "No sha256sum / shasum / openssl found, cannot verify — aborted"
[ "$got" = "$want" ] || die "sha256 mismatch: the package may be tampered with or incompletely downloaded — aborted
expected $want
actual $got"
say "sha256 matches: $(printf '%s' "$got" | cut -c1-16)…"
step "Extracting"
STAGE="$TMP/stage"
mkdir -p "$STAGE"
extract_zip "$ZIP" "$STAGE"
[ -f "$STAGE/link-agent" ] || die "The package has no link-agent executable; unexpected archive layout"
step "Installing to $BIN"
mkdir -p "$BIN" || die "Cannot create $BIN"
install -m 755 "$STAGE/link-agent" "$BIN/link-agent" || die "Failed to write $BIN/link-agent"
for extra in rg link-agent-panel; do
if [ -f "$STAGE/$extra" ]; then install -m 755 "$STAGE/$extra" "$BIN/$extra" || true; fi
done
say "Installed $BIN/link-agent"
if [ "$WANT_PANEL" = 1 ]; then
[ -f "$STAGE/link-agent-panel" ] || die "The panel package has no link-agent-panel; unexpected archive layout — aborted (service not registered)"
[ -x "$BIN/link-agent-panel" ] || die "Failed to write $BIN/link-agent-panel"
say "Installed $BIN/link-agent-panel (desktop panel)"
fi
if [ "$WANT_PANEL" = 1 ]; then
step "Adding the desktop menu entry"
DATA="${XDG_DATA_HOME:-$HOME/.local/share}"
ICON_DIR="$DATA/icons/hicolor/256x256/apps"
APP_DIR="$DATA/applications"
mkdir -p "$ICON_DIR" "$APP_DIR" || die "Cannot create $APP_DIR"
if [ -f "$STAGE/link-agent.png" ]; then
install -m 644 "$STAGE/link-agent.png" "$ICON_DIR/link-agent.png" || warn "Could not write the icon; nothing else is affected"
fi
cat > "$APP_DIR/link-agent-panel.desktop" <<DESKTOP
[Desktop Entry]
Type=Application
Name=Link Agent Panel
Comment=Turtle Link · Link Agent desktop panel
Exec=$BIN/link-agent-panel
Icon=link-agent
Terminal=false
Categories=Development;Utility;
DESKTOP
command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$APP_DIR" >/dev/null 2>&1 || true
say "Added to the application menu: Link Agent Panel"
fi
step "Checking PATH"
if printf ':%s:' "$PATH" | grep -qF ":$BIN:"; then
say "$BIN is already on PATH"
else
marker='# added by link-agent installer'
shell_name=$(basename "${SHELL:-sh}")
rc=""
if [ "$shell_name" = "zsh" ]; then
rc="$HOME/.zshrc"
line="export PATH=\"$BIN:\$PATH\" $marker"
elif [ "$shell_name" = "bash" ]; then
if [ "$os" = "Darwin" ] && [ -f "$HOME/.bash_profile" ]; then rc="$HOME/.bash_profile"; else rc="$HOME/.bashrc"; fi
line="export PATH=\"$BIN:\$PATH\" $marker"
elif [ "$shell_name" = "fish" ]; then
rc="$HOME/.config/fish/config.fish"
line="fish_add_path $BIN $marker"
fi
if [ "$MODIFY_PATH" = 1 ] && [ -n "$rc" ]; then
mkdir -p "$(dirname "$rc")"
if [ -f "$rc" ] && grep -qF "$marker" "$rc"; then
say "$rc already has the PATH line from a previous install, skipping"
else
printf '\n%s\n' "$line" >> "$rc" || die "Failed to write $rc"
say "Added $BIN to $rc (the line ends with the $marker marker so it is easy to remove later)"
fi
say "Open a new terminal for it to take effect; in this one run: export PATH=\"$BIN:\$PATH\""
else
warn "$BIN is not on PATH. Add this line to your shell config:"
say "export PATH=\"$BIN:\$PATH\""
fi
fi
step "Verifying the executable"
"$BIN/link-agent" --version || die "Installed, but link-agent does not run (glibc too old or a corrupted file)"
say "The binary runs"
if [ "$WANT_SERVICE" = 1 ]; then
step "Registering autostart and starting once"
if "$BIN/link-agent" install --autostart --start --aliases; then
say "Service started, check it with: link-agent status"
else
warn "Autostart registration failed; the binary itself is fine. Run it manually later with:"
say "$BIN/link-agent install --autostart --start"
fi
else
say "Skipped service registration (--no-service). Run when needed: link-agent install --autostart --start"
fi
printf '\n%s\n' "${C_OK}Done${C_OFF}"
say "Status: link-agent status"
say "Web console: http://127.0.0.1:9876/admin"
if [ "$WANT_PANEL" = 1 ]; then
say "Desktop panel: open Link Agent Panel from the application menu, or run link-agent-panel"
fi
say "Remove autostart: link-agent uninstall"