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>
This commit is contained in:
+36
-13
@@ -3,6 +3,7 @@
|
||||
# 用法:
|
||||
# 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"
|
||||
@@ -15,20 +16,42 @@ need_cmd() {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || true)"
|
||||
NAVCTL_PY="${SCRIPT_DIR}/navctl.py"
|
||||
|
||||
if [ ! -f "$NAVCTL_PY" ]; then
|
||||
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:-}"
|
||||
exec python3 "${TMP_DIR}/navctl.py" "$@"
|
||||
# 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
|
||||
|
||||
cd "$(dirname "$NAVCTL_PY")"
|
||||
exec python3 "$NAVCTL_PY" "$@"
|
||||
download_and_run "$@"
|
||||
|
||||
Reference in New Issue
Block a user