Skip to content

Commit a8c98c0

Browse files
authored
Merge pull request #237 from wnlen/dev
fix: block WSL installs under Windows mount paths
2 parents 26e1dea + 8938aaf commit a8c98c0

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ bash install.sh
4848

4949
- 上述命令使用了[加速前缀](https://gh-proxy.org/),如失效可更换其他[可用链接](https://ghproxy.link/)
5050
- 可通过 `.env` 文件或脚本参数自定义安装选项。
51+
- 在 WSL 环境中,不支持放在 Windows 挂载目录**/mnt/c/**下,请安装到 Linux 原生目录。
5152

5253
------
5354

install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ source "$PROJECT_DIR/scripts/init/script.sh"
1414
init_project_context "$PROJECT_DIR"
1515
load_env_if_exists
1616
detect_install_scope "${1:-auto}"
17+
ensure_project_not_wsl_windows_mount
1718

1819
ensure_openwrt_install_supported
1920
ensure_required_commands

scripts/core/common.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,33 @@ init_project_context() {
233233
RESOURCE_DIR="$PROJECT_DIR/resources"
234234
}
235235

236+
is_wsl_env() {
237+
grep -qiE 'microsoft|wsl' /proc/sys/kernel/osrelease 2>/dev/null
238+
}
239+
240+
path_is_wsl_windows_mount() {
241+
local path="$1"
242+
243+
path="$(readlink -f "$path" 2>/dev/null || printf '%s' "$path")"
244+
245+
case "$path" in
246+
/mnt/[a-zA-Z]|/mnt/[a-zA-Z]/*)
247+
return 0
248+
;;
249+
*)
250+
return 1
251+
;;
252+
esac
253+
}
254+
255+
ensure_project_not_wsl_windows_mount() {
256+
if is_wsl_env && path_is_wsl_windows_mount "$PROJECT_DIR"; then
257+
die_state \
258+
"当前项目目录位于 WSL Windows 挂载盘:$PROJECT_DIR" \
259+
"请将项目移动到 Linux 原生目录后重新安装,例如:cd ~ && git clone <repo> clash-for-linux && cd clash-for-linux && bash install.sh"
260+
fi
261+
}
262+
236263
load_env_if_exists() {
237264
local env_file
238265
env_file="$PROJECT_DIR/.env"

0 commit comments

Comments
 (0)