feat(installer): support Linux hosts with XDG data root and ss port probe

- platform gate accepts Darwin and Linux; other platforms are refused
- default install root follows each platform's convention
  (~/Library/Application Support vs ~/.local/share)
- LAN IP discovery uses ip -4/hostname -I on Linux, ipconfig on macOS
- port occupancy checks fall back from lsof to ss
- API process gets MULTI_SIMADMIN_SECRET_BACKEND pinned per platform
- README documents the per-platform secret storage
This commit is contained in:
chick
2026-09-07 01:36:04 +08:00
parent e4c4bce75b
commit 3c5971e167
2 changed files with 39 additions and 14 deletions
+36 -11
View File
@@ -4,7 +4,15 @@ umask 077
REPO_URL=${MULTI_SIMADMIN_REPO_URL:-https://gitea.chickliu.fun/Hermes/multi-simadmin.git}
PNPM_VERSION="11.13.0"
APP_ROOT=${MULTI_SIMADMIN_HOME:-"$HOME/Library/Application Support/multi-simadmin"}
PLATFORM=$(uname -s)
default_app_root() {
case "$PLATFORM" in
Darwin) printf '%s' "$HOME/Library/Application Support/multi-simadmin" ;;
Linux) printf '%s' "${XDG_DATA_HOME:-$HOME/.local/share}/multi-simadmin" ;;
*) printf '' ;;
esac
}
APP_ROOT=${MULTI_SIMADMIN_HOME:-"$(default_app_root)"}
SOURCE_DIR="$APP_ROOT/source"
DATA_ROOT="$APP_ROOT/data"
RUNTIME_DIR="$APP_ROOT/run"
@@ -29,14 +37,17 @@ Multi SimAdmin 一键安装与服务管理
status 显示进程、端口与健康状态
uninstall 卸载程序,默认保留数据、令牌和日志
环境变量:
MULTI_SIMADMIN_HOME 安装根目录
MULTI_SIMADMIN_HOME 安装根目录(默认 macOS 为 ~/Library/Application Support/multi-simadminLinux 为 ~/.local/share/multi-simadmin
MULTI_SIMADMIN_ALLOWED_HOSTS 额外允许的 LAN 主机名/IP,逗号分隔
MULTI_SIMADMIN_REPO_URL 源码仓库地址
EOF
}
require_macos() {
[ "$(uname -s)" = Darwin ] || die "当前生产版仅支持 macOS(秘密存储依赖 macOS Keychain)。"
require_platform() {
case "$PLATFORM" in
Darwin|Linux) ;;
*) die "当前生产版仅支持 macOS 或 Linux。" ;;
esac
}
require_commands() {
@@ -61,14 +72,27 @@ pid_owned() {
}
port_free() {
! lsof -nP -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1
if command -v lsof >/dev/null 2>&1; then
! lsof -nP -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1
elif command -v ss >/dev/null 2>&1; then
! ss -ltn "( sport = :$1 )" 2>/dev/null | grep -q ":$1 "
else
die "缺少 lsof 或 ss,无法检查端口占用"
fi
}
lan_ip() {
for interface in en0 en1; do
value=$(ipconfig getifaddr "$interface" 2>/dev/null || true)
if [ -n "$value" ]; then printf '%s' "$value"; return; fi
done
if [ "$PLATFORM" = Darwin ]; then
for interface in en0 en1; do
value=$(ipconfig getifaddr "$interface" 2>/dev/null || true)
if [ -n "$value" ]; then printf '%s' "$value"; return; fi
done
else
value=$(ip -4 addr show scope global 2>/dev/null | awk '/inet /{print $2; exit}' | cut -d/ -f1)
if [ -n "${value:-}" ]; then printf '%s' "$value"; return; fi
value=$(hostname -I 2>/dev/null | awk '{print $1}')
if [ -n "${value:-}" ]; then printf '%s' "$value"; return; fi
fi
printf '127.0.0.1'
}
@@ -135,7 +159,7 @@ wait_for() {
}
start_service() {
require_macos
require_platform
require_commands
[ -f "$SOURCE_DIR/apps/web/dist/index.html" ] || die "尚未安装,请先运行 install"
[ -f "$TOKEN_FILE" ] && [ ! -L "$TOKEN_FILE" ] || die "Gateway token 缺失或不是安全的普通文件,请重新运行 install"
@@ -192,6 +216,7 @@ start_service() {
trap 'rollback_start' EXIT HUP INT TERM
MULTI_SIMADMIN_DATA_ROOT="$DATA_ROOT" \
MULTI_SIMADMIN_DATABASE_PATH="$DATA_ROOT/control-plane.sqlite3" \
MULTI_SIMADMIN_SECRET_BACKEND="$( [ "$PLATFORM" = Darwin ] && printf macos-keychain || printf secret-file )" \
MULTI_SIMADMIN_GATEWAY_TOKEN="$token" \
MULTI_SIMADMIN_WEB_DIST="$SOURCE_DIR/apps/web/dist" \
API_HOST=127.0.0.1 API_PORT=8790 \
@@ -256,7 +281,7 @@ status_service() {
}
install_app() {
require_macos
require_platform
require_commands
mkdir -p "$APP_ROOT" "$DATA_ROOT" "$RUNTIME_DIR" "$LOG_DIR"
chmod 700 "$APP_ROOT" "$DATA_ROOT" "$RUNTIME_DIR" "$LOG_DIR"