Files
LocalNav/scripts/install.sh
T
dekun fa90a29576 Fix curl-pipe-bash install menu on Linux.
Avoid unbound BASH_SOURCE under set -u, attach stdin to /dev/tty for interactive prompts, and handle empty menu input without looping.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-12 12:03:54 +08:00

58 lines
1.7 KiB
Bash

#!/usr/bin/env bash
# LocalNav 交互式部署管理(无需预先克隆)
# 用法:
# curl -fsSL https://git.bz121.com/dekun/LocalNav/raw/main/scripts/install.sh | bash
# bash install.sh
# curl -fsSL .../install.sh | bash -s -- install -y
set -euo pipefail
DEFAULT_REPO="https://git.bz121.com/dekun/LocalNav.git"
RAW_BASE="${DEFAULT_REPO%.git}/raw/main/scripts"
need_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "[FAIL] 未找到 $1,请先安装" >&2
exit 1
}
}
run_navctl() {
local navctl_py="$1"
shift
# curl | bash 时 stdin 是管道,无法交互;改从终端设备读取
if [ ! -t 0 ]; then
if [ ! -r /dev/tty ]; then
echo "[FAIL] 当前为非交互环境且无法打开 /dev/tty" >&2
echo "请改用: curl -fsSL .../install.sh -o install.sh && bash install.sh" >&2
echo "或非交互安装: curl -fsSL .../install.sh | bash -s -- install -y" >&2
exit 1
fi
exec python3 "$navctl_py" "$@" </dev/tty
fi
exec python3 "$navctl_py" "$@"
}
download_and_run() {
local tmp_dir
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
echo "[OK] 正在下载部署管理脚本..."
curl -fsSL "${RAW_BASE}/navctl.py" -o "${tmp_dir}/navctl.py"
curl -fsSL "${RAW_BASE}/nav_common.py" -o "${tmp_dir}/nav_common.py"
export PYTHONPATH="${tmp_dir}:${PYTHONPATH:-}"
run_navctl "${tmp_dir}/navctl.py" "$@"
}
need_cmd python3
# curl | bash 时 BASH_SOURCE 可能未设置;仅当脚本为真实文件时才走本地路径
script_path="${BASH_SOURCE[0]:-}"
if [[ -n "$script_path" && -f "$script_path" ]]; then
script_dir="$(cd "$(dirname "$script_path")" && pwd)"
if [[ -f "${script_dir}/navctl.py" ]]; then
run_navctl "${script_dir}/navctl.py" "$@"
fi
fi
download_and_run "$@"