mirror of
https://github.com/wnlen/clash-for-linux.git
synced 2026-03-21 22:06:45 +08:00
Update install.sh
This commit is contained in:
57
install.sh
57
install.sh
@ -388,43 +388,68 @@ fi
|
||||
PROFILED_FILE="/etc/profile.d/clash-for-linux.sh"
|
||||
|
||||
install_profiled() {
|
||||
local http_port="${MIXED_PORT:-7890}"
|
||||
# 兼容你后面可能支持 auto:auto 就先用 7890
|
||||
[ "$http_port" = "auto" ] && http_port="7890"
|
||||
local install_dir="$Install_Dir"
|
||||
|
||||
# 只写 IPv4 loopback,避免某些环境 ::1 解析问题
|
||||
sudo tee "$PROFILED_FILE" >/dev/null <<EOF
|
||||
# Clash for Linux proxy helpers
|
||||
# Auto-generated by clash-for-linux installer.
|
||||
|
||||
# Default proxy endpoint (HTTP)
|
||||
export CLASH_HTTP_PROXY="http://127.0.0.1:${http_port}"
|
||||
# Default proxy endpoint (SOCKS5)
|
||||
export CLASH_SOCKS_PROXY="socks5://127.0.0.1:${http_port}"
|
||||
# ===== 自动加载 .env =====
|
||||
CLASH_INSTALL_DIR="${install_dir}"
|
||||
ENV_FILE="\${CLASH_INSTALL_DIR}/.env"
|
||||
|
||||
if [ -f "\$ENV_FILE" ]; then
|
||||
set +u
|
||||
. "\$ENV_FILE" >/dev/null 2>&1 || true
|
||||
set -u
|
||||
fi
|
||||
|
||||
# ===== 默认值(兜底)=====
|
||||
CLASH_LISTEN_IP="\${CLASH_LISTEN_IP:-127.0.0.1}"
|
||||
CLASH_HTTP_PORT="\${CLASH_HTTP_PORT:-7890}"
|
||||
CLASH_SOCKS_PORT="\${CLASH_SOCKS_PORT:-7891}"
|
||||
|
||||
# ===== 开启代理 =====
|
||||
proxy_on() {
|
||||
export http_proxy="\$CLASH_HTTP_PROXY"
|
||||
export https_proxy="\$CLASH_HTTP_PROXY"
|
||||
export all_proxy="\$CLASH_SOCKS_PROXY"
|
||||
export HTTP_PROXY="\$CLASH_HTTP_PROXY"
|
||||
export HTTPS_PROXY="\$CLASH_HTTP_PROXY"
|
||||
export ALL_PROXY="\$CLASH_SOCKS_PROXY"
|
||||
echo "[OK] Proxy enabled: \$CLASH_HTTP_PROXY"
|
||||
export http_proxy="http://\${CLASH_LISTEN_IP}:\${CLASH_HTTP_PORT}"
|
||||
export https_proxy="http://\${CLASH_LISTEN_IP}:\${CLASH_HTTP_PORT}"
|
||||
export HTTP_PROXY="http://\${CLASH_LISTEN_IP}:\${CLASH_HTTP_PORT}"
|
||||
export HTTPS_PROXY="http://\${CLASH_LISTEN_IP}:\${CLASH_HTTP_PORT}"
|
||||
export all_proxy="socks5://\${CLASH_LISTEN_IP}:\${CLASH_SOCKS_PORT}"
|
||||
export ALL_PROXY="socks5://\${CLASH_LISTEN_IP}:\${CLASH_SOCKS_PORT}"
|
||||
export no_proxy="127.0.0.1,localhost,::1"
|
||||
export NO_PROXY="127.0.0.1,localhost,::1"
|
||||
echo "[OK] Proxy enabled: http://\${CLASH_LISTEN_IP}:\${CLASH_HTTP_PORT}"
|
||||
}
|
||||
|
||||
# ===== 关闭代理 =====
|
||||
proxy_off() {
|
||||
unset http_proxy https_proxy all_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY
|
||||
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
|
||||
unset all_proxy ALL_PROXY no_proxy NO_PROXY
|
||||
echo "[OK] Proxy disabled"
|
||||
}
|
||||
|
||||
# ===== 状态 =====
|
||||
proxy_status() {
|
||||
echo "http_proxy=\${http_proxy:-<empty>}"
|
||||
echo "https_proxy=\${https_proxy:-<empty>}"
|
||||
echo "all_proxy=\${all_proxy:-<empty>}"
|
||||
echo "CLASH_HTTP_PORT=\${CLASH_HTTP_PORT}"
|
||||
echo "CLASH_SOCKS_PORT=\${CLASH_SOCKS_PORT}"
|
||||
}
|
||||
EOF
|
||||
|
||||
sudo chmod 644 "$PROFILED_FILE"
|
||||
|
||||
# ===== 自动写入 bashrc(关键!)=====
|
||||
local BASHRC_FILE="/root/.bashrc"
|
||||
local SOURCE_LINE='[ -f /etc/profile.d/clash-for-linux.sh ] && source /etc/profile.d/clash-for-linux.sh'
|
||||
|
||||
if [ -f "$BASHRC_FILE" ]; then
|
||||
if ! grep -Fq "$SOURCE_LINE" "$BASHRC_FILE"; then
|
||||
echo "$SOURCE_LINE" >> "$BASHRC_FILE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
install_profiled || true
|
||||
|
||||
Reference in New Issue
Block a user