mirror of
https://github.com/wnlen/clash-for-linux.git
synced 2026-10-10 04:03:04 +08:00
This commit is contained in:
@@ -15,6 +15,9 @@ export CLASH_DNS_PORT="1053"
|
||||
# 订阅更新策略
|
||||
export CLASH_AUTO_UPDATE_SUBSCRIPTIONS="true"
|
||||
|
||||
# 登录 Shell 自动恢复代理变量(SSH 登录也会触发)。设为 false 可关闭自动注入,仍可手动执行 clashon。
|
||||
export CLASH_SHELL_AUTO_RESTORE_PROXY="true"
|
||||
|
||||
# 版本
|
||||
export MIHOMO_VERSION="v1.19.23"
|
||||
export CLASH_VERSION="v1.18.0"
|
||||
|
||||
@@ -292,10 +292,13 @@ SUBCONVERTER_VERSION=v0.9.9
|
||||
MIHOMO_DOWNLOAD_BASE=https://github.com/MetaCubeX/mihomo/releases/download
|
||||
CLASH_DOWNLOAD_BASE=https://github.com/WindSpiritSR/clash/releases/download
|
||||
CLASH_BUNDLED_ASSET_ENABLED=true
|
||||
CLASH_SHELL_AUTO_RESTORE_PROXY=true
|
||||
```
|
||||
|
||||
按需设置即可,不需要每项都写。
|
||||
|
||||
- `CLASH_SHELL_AUTO_RESTORE_PROXY`:控制登录 Shell 是否自动恢复上次 `clashon` 写入的代理变量。默认 `true` 保持兼容;如果不希望 SSH 远程登录后自动带上 `http_proxy` / `https_proxy`,设为 `false`,之后仍可手动执行 `clashon`。
|
||||
|
||||
#### GitHub 下载加速
|
||||
|
||||
所有来自 GitHub 的资源(内核、GEO 数据、yq、subconverter、Dashboard)在下载时会自动尝试内置镜像池(`gh-proxy.org`、`ghfast.top`、`ghproxy.net`、`kkgithub.com`),无需额外配置即可加速。
|
||||
|
||||
@@ -54,6 +54,35 @@ _clash_alias_yq_bin() {
|
||||
echo "$(_clash_alias_project_dir)/runtime/bin/yq"
|
||||
}
|
||||
|
||||
_clash_alias_env_value() {
|
||||
local key="$1"
|
||||
local env_file
|
||||
|
||||
if [ -n "${!key:-}" ]; then
|
||||
printf '%s' "${!key}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
env_file="$(_clash_alias_project_dir)/.env"
|
||||
[ -f "$env_file" ] || return 0
|
||||
|
||||
sed -nE "s/^[[:space:]]*(export[[:space:]]+)?${key}=['\"]?([^'\"]*)['\"]?$/\2/p" "$env_file" | tail -n 1
|
||||
}
|
||||
|
||||
_clash_alias_shell_auto_restore_enabled() {
|
||||
local value
|
||||
|
||||
value="$(_clash_alias_env_value CLASH_SHELL_AUTO_RESTORE_PROXY)"
|
||||
case "${value:-true}" in
|
||||
false|False|FALSE|0|no|No|NO|off|Off|OFF)
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_clash_alias_set_persist_enabled() {
|
||||
local enabled="$1"
|
||||
local state_file
|
||||
@@ -255,6 +284,7 @@ _clash_alias_run_off() {
|
||||
}
|
||||
|
||||
_clash_alias_auto_restore_proxy() {
|
||||
_clash_alias_shell_auto_restore_enabled || return 0
|
||||
_clash_alias_persist_enabled || return 0
|
||||
_clash_alias_export_proxy || return 0
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
|
||||
tmp_dir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmp_dir"' EXIT
|
||||
|
||||
test_project="$tmp_dir/project"
|
||||
mkdir -p "$test_project/scripts/core" "$test_project/runtime"
|
||||
cp "$PROJECT_DIR/scripts/core/alias.sh" "$test_project/scripts/core/alias.sh"
|
||||
|
||||
cat > "$test_project/runtime/config.yaml" <<'YAML'
|
||||
mixed-port: 7890
|
||||
YAML
|
||||
|
||||
cat > "$test_project/runtime/shell-proxy.env" <<'EOF'
|
||||
SHELL_PROXY_PERSIST_ENABLED="true"
|
||||
SHELL_PROXY_PERSIST_TIME="test"
|
||||
EOF
|
||||
|
||||
run_case() {
|
||||
local name="$1"
|
||||
local env_file_value="$2"
|
||||
local env_override="$3"
|
||||
local expected="$4"
|
||||
local output
|
||||
|
||||
if [ -n "$env_file_value" ]; then
|
||||
printf 'export CLASH_SHELL_AUTO_RESTORE_PROXY="%s"\n' "$env_file_value" > "$test_project/.env"
|
||||
else
|
||||
rm -f "$test_project/.env"
|
||||
fi
|
||||
|
||||
output="$(
|
||||
env -i \
|
||||
HOME="$tmp_dir/home" \
|
||||
PATH="$PATH" \
|
||||
CLASH_SHELL_AUTO_RESTORE_PROXY="$env_override" \
|
||||
bash --noprofile --norc -c '
|
||||
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY all_proxy ALL_PROXY no_proxy NO_PROXY
|
||||
source "'"$test_project"'/scripts/core/alias.sh"
|
||||
printf "%s\n" "${http_proxy:-}"
|
||||
'
|
||||
)"
|
||||
|
||||
if [ "$output" != "$expected" ]; then
|
||||
echo "not ok - $name: got '$output', expected '$expected'" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "ok - $name"
|
||||
}
|
||||
|
||||
run_case "default auto-restores persisted proxy" "" "" "http://127.0.0.1:7890"
|
||||
run_case "env file disables auto-restore" "false" "" ""
|
||||
run_case "environment override enables auto-restore" "false" "true" "http://127.0.0.1:7890"
|
||||
run_case "environment override disables auto-restore" "true" "false" ""
|
||||
Reference in New Issue
Block a user