Update install.sh

This commit is contained in:
wnlen
2026-01-17 21:13:31 +08:00
parent f278ae30a1
commit 8cf015ebd6

View File

@ -138,6 +138,36 @@ if [[ -z "${CpuArch:-}" ]]; then
fi fi
info "CPU architecture: ${CpuArch}" info "CPU architecture: ${CpuArch}"
# =========================
# .env 写入工具write_env_kv必须在 prompt 之前定义)
# - 自动创建文件
# - 存在则替换,不存在则追加
# - 统一写成export KEY="VALUE"
# - 自动转义双引号/反斜杠
# =========================
escape_env_value() {
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
}
write_env_kv() {
local file="$1"
local key="$2"
local val="$3"
mkdir -p "$(dirname "$file")" 2>/dev/null || true
[ -f "$file" ] || touch "$file"
val="$(printf '%s' "$val" | tr -d '\r')"
local esc
esc="$(escape_env_value "$val")"
if grep -qE "^[[:space:]]*(export[[:space:]]+)?${key}=" "$file"; then
sed -i -E "s|^[[:space:]]*(export[[:space:]]+)?${key}=.*|export ${key}=\"${esc}\"|g" "$file"
else
printf 'export %s="%s"\n' "$key" "$esc" >> "$file"
fi
}
# ========================= # =========================
# 交互式填写订阅地址(仅在 CLASH_URL 为空时触发) # 交互式填写订阅地址(仅在 CLASH_URL 为空时触发)
# - 若非 TTYCI/管道)则跳过交互 # - 若非 TTYCI/管道)则跳过交互
@ -248,19 +278,6 @@ wait_secret_ready() {
return 1 return 1
} }
write_env_kv() {
local file="$1"
local key="$2"
local val="$3"
# 统一成 export KEY="value"
if grep -qE "^(export[[:space:]]+)?${key}=" "$file"; then
sed -i -E "s|^(export[[:space:]]+)?${key}=.*|export ${key}=\"${val}\"|g" "$file"
else
printf '\nexport %s="%s"\n' "$key" "$val" >> "$file"
fi
}
# 计算字符串可视宽度:中文大概率按 2 宽处理(简单够用版) # 计算字符串可视宽度:中文大概率按 2 宽处理(简单够用版)
# 注:终端宽度/字体不统一时,中文宽度估算永远只能“近似” # 注:终端宽度/字体不统一时,中文宽度估算永远只能“近似”
vis_width() { vis_width() {