-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdl-clash-conf.sh
50 lines (40 loc) · 1.13 KB
/
dl-clash-conf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env sh
# 下载配置文件
ConfFile=$1
ConfPath=`dirname $ConfFile`
mkdir -p $ConfPath
wget -O $ConfFile -q "$CONF_URL"
# 若文件下载失败, 则返回并报错
if [ $? -ne 0 ];
then
echo "config file download fail"
exit $?
fi
modify_config(){
# 检查配置文件中是否包含指定的键
if grep -Eq "^$1:" "$ConfFile"; then
# 如果存在该键,则直接修改值
sed -i "s/^$1:.*/$1: $2/" "$ConfFile"
echo "已修改 $1 的值为 $2"
else
# 如果键不存在,则追加配置项
echo "$1: $2" >> "$ConfFile"
echo "配置项不存在,已添加新配置到 $ConfFile"
fi
}
# 写入 API端口
if [[ ! -z "$EXTERNAL_BIND" && ! -z "$EXTERNAL_PORT" ]]
then
modify_config "external-controller" "$EXTERNAL_BIND:$EXTERNAL_PORT"
modify_config "external-ui" "/etc/clash-dashboard"
fi
# 鉴权信息
if [[ ! -z "$EXTERNAL_SECRET" ]]
then
modify_config "secret" "$EXTERNAL_SECRET"
fi
# 必须开启局域网连接, 否则外部无法连接
modify_config "allow-lan" "true"
sed -i "/^port:/d" "$ConfFile"
sed -i "/^socks-port:/d" "$ConfFile"
modify_config "mixed-port" "$SOCKET_PORT"