mirror of
https://github.com/wnlen/clash-for-linux.git
synced 2026-02-04 10:11:28 +08:00
Update start.sh
This commit is contained in:
26
start.sh
26
start.sh
@ -191,27 +191,29 @@ ensure_ui_links() {
|
|||||||
force_write_controller_and_ui() {
|
force_write_controller_and_ui() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local controller="${EXTERNAL_CONTROLLER:-127.0.0.1:9090}"
|
local controller="${EXTERNAL_CONTROLLER:-127.0.0.1:9090}"
|
||||||
|
local MIHOMO_UI_DIR="/opt/clash-for-linux/.config/mihomo/ui"
|
||||||
# external-ui:必须在 conf 子目录(SAFE_PATH)
|
|
||||||
local ui_dir="${EXTERNAL_UI_DIR:-$Conf_Dir/external-ui}"
|
|
||||||
|
|
||||||
[ -n "$file" ] || return 1
|
[ -n "$file" ] || return 1
|
||||||
|
|
||||||
# 1) external-controller
|
# 1) external-controller
|
||||||
upsert_yaml_kv "$file" "external-controller" "$controller" || true
|
upsert_yaml_kv "$file" "external-controller" "$controller" || true
|
||||||
|
|
||||||
# 2) external-ui(落在 SAFE_PATH)
|
# 2) external-ui:写 mihomo SAFE_PATH
|
||||||
ensure_ui_links
|
mkdir -p "$MIHOMO_UI_DIR" 2>/dev/null || true
|
||||||
|
|
||||||
if [ -d "$ui_dir" ]; then
|
# 如果 SAFE_PATH 下没有 index.html,尝试从 conf/ui 同步一次
|
||||||
upsert_yaml_kv "$file" "external-ui" "$ui_dir" || true
|
if [ ! -f "$MIHOMO_UI_DIR/index.html" ] && [ -d "$Conf_Dir/ui" ]; then
|
||||||
else
|
rm -rf "$MIHOMO_UI_DIR"/* 2>/dev/null || true
|
||||||
# 目标目录不存在则不写,避免写死路径导致 mihomo fatal
|
cp -a "$Conf_Dir/ui/." "$MIHOMO_UI_DIR/" 2>/dev/null || true
|
||||||
# 如果你没有 delete_yaml_key 函数,就注释掉这行也没关系
|
fi
|
||||||
delete_yaml_key "$file" "external-ui" 2>/dev/null || true
|
|
||||||
|
# 只有真的有 UI 文件才写 external-ui(否则写了也白屏)
|
||||||
|
if [ -f "$MIHOMO_UI_DIR/index.html" ]; then
|
||||||
|
upsert_yaml_kv "$file" "external-ui" "$MIHOMO_UI_DIR" || true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fix_external_ui_by_safe_paths() {
|
fix_external_ui_by_safe_paths() {
|
||||||
local bin="$1"
|
local bin="$1"
|
||||||
local cfg="$2"
|
local cfg="$2"
|
||||||
@ -595,8 +597,6 @@ if [ "$SKIP_CONFIG_REBUILD" != "true" ]; then
|
|||||||
OLD_CFG="${Conf_Dir}/config.yaml"
|
OLD_CFG="${Conf_Dir}/config.yaml"
|
||||||
TEST_OUT="$Temp_Dir/config.test.out"
|
TEST_OUT="$Temp_Dir/config.test.out"
|
||||||
|
|
||||||
TEST_OUT="$Temp_Dir/config.test.out"
|
|
||||||
|
|
||||||
if [ -x "$BIN" ] && [ -f "$NEW_CFG" ]; then
|
if [ -x "$BIN" ] && [ -f "$NEW_CFG" ]; then
|
||||||
# 先尝试自动修复 external-ui 的 SAFE_PATH 问题(内部会跑 -t)
|
# 先尝试自动修复 external-ui 的 SAFE_PATH 问题(内部会跑 -t)
|
||||||
set +e
|
set +e
|
||||||
|
|||||||
Reference in New Issue
Block a user