diff --git a/README.md b/README.md index 7e143dc..627d4cb 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ bash install.sh - 上述命令使用了[加速前缀](https://gh-proxy.org/),如失效可更换其他[可用链接](https://ghproxy.link/)。 - 可通过 `.env` 文件或脚本参数自定义安装选项。 +- 在 WSL 环境中,不支持放在 Windows 挂载目录**/mnt/c/**下,请安装到 Linux 原生目录。 ------ diff --git a/install.sh b/install.sh index c3d3067..a45cc34 100755 --- a/install.sh +++ b/install.sh @@ -14,6 +14,7 @@ source "$PROJECT_DIR/scripts/init/script.sh" init_project_context "$PROJECT_DIR" load_env_if_exists detect_install_scope "${1:-auto}" +ensure_project_not_wsl_windows_mount ensure_openwrt_install_supported ensure_required_commands diff --git a/scripts/core/common.sh b/scripts/core/common.sh index a3cc889..34877f3 100644 --- a/scripts/core/common.sh +++ b/scripts/core/common.sh @@ -233,6 +233,33 @@ init_project_context() { RESOURCE_DIR="$PROJECT_DIR/resources" } +is_wsl_env() { + grep -qiE 'microsoft|wsl' /proc/sys/kernel/osrelease 2>/dev/null +} + +path_is_wsl_windows_mount() { + local path="$1" + + path="$(readlink -f "$path" 2>/dev/null || printf '%s' "$path")" + + case "$path" in + /mnt/[a-zA-Z]|/mnt/[a-zA-Z]/*) + return 0 + ;; + *) + return 1 + ;; + esac +} + +ensure_project_not_wsl_windows_mount() { + if is_wsl_env && path_is_wsl_windows_mount "$PROJECT_DIR"; then + die_state \ + "当前项目目录位于 WSL Windows 挂载盘:$PROJECT_DIR" \ + "请将项目移动到 Linux 原生目录后重新安装,例如:cd ~ && git clone clash-for-linux && cd clash-for-linux && bash install.sh" + fi +} + load_env_if_exists() { local env_file env_file="$PROJECT_DIR/.env"