Skip to content

Commit 23bf91d

Browse files
committed
support set log level
1 parent 1eace31 commit 23bf91d

7 files changed

Lines changed: 63 additions & 23 deletions

File tree

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ install_pkg() {
159159
download() {
160160
case $1 in
161161
core)
162-
[[ ! $is_core_ver ]] && is_core_ver=$(_wget -qO- "https://api.github.com/repos/${is_core_repo}/releases/latest?v=$RANDOM" | grep tag_name | egrep -o 'v([0-9.]+)')
162+
[[ ! $is_core_ver ]] && is_core_ver=$(_wget -qO- "https://api.github.com/repos/${is_core_repo}/releases/latest?v=$RANDOM" | grep tag_name | grep -E -o 'v([0-9.]+)')
163163
[[ $is_core_ver ]] && link="https://github.com/${is_core_repo}/releases/download/${is_core_ver}/${is_core}-${is_core_ver:1}-linux-${is_arch}.tar.gz"
164164
name=$is_core_name
165165
tmpfile=$tmpcore

sing-box.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
args=$@
4-
is_sh_ver=v1.08
4+
is_sh_ver=v1.09
55

66
. /etc/sing-box/sh/src/init.sh

src/core.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ show_list() {
159159
is_test() {
160160
case $1 in
161161
number)
162-
echo $2 | egrep '^[1-9][0-9]?+$'
162+
echo $2 | grep -E '^[1-9][0-9]?+$'
163163
;;
164164
port)
165165
if [[ $(is_test number $2) ]]; then
@@ -170,13 +170,13 @@ is_test() {
170170
[[ $(is_port_used $2) && ! $is_cant_test_port ]] && echo ok
171171
;;
172172
domain)
173-
echo $2 | egrep -i '^\w(\w|\-|\.)?+\.\w+$'
173+
echo $2 | grep -E -i '^\w(\w|\-|\.)?+\.\w+$'
174174
;;
175175
path)
176-
echo $2 | egrep -i '^\/\w(\w|\-|\/)?+\w$'
176+
echo $2 | grep -E -i '^\/\w(\w|\-|\/)?+\w$'
177177
;;
178178
uuid)
179-
echo $2 | egrep -i '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
179+
echo $2 | grep -E -i '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
180180
;;
181181
esac
182182

@@ -781,7 +781,7 @@ add() {
781781
;;
782782
*)
783783
for v in ${protocol_list[@]}; do
784-
[[ $(egrep -i "^$is_lower$" <<<$v) ]] && is_new_protocol=$v && break
784+
[[ $(grep -E -i "^$is_lower$" <<<$v) ]] && is_new_protocol=$v && break
785785
done
786786

787787
[[ ! $is_new_protocol ]] && err "无法识别 ($1), 请使用: $is_core add [protocol] [args... | auto]"
@@ -905,7 +905,7 @@ add() {
905905
is_tmp_use_name=加密方式
906906
is_tmp_list=${ss_method_list[@]}
907907
for v in ${is_tmp_list[@]}; do
908-
[[ $(egrep -i "^${is_use_method}$" <<<$v) ]] && is_tmp_use_type=$v && break
908+
[[ $(grep -E -i "^${is_use_method}$" <<<$v) ]] && is_tmp_use_type=$v && break
909909
done
910910
[[ ! ${is_tmp_use_type} ]] && {
911911
warn "(${is_use_method}) 不是一个可用的${is_tmp_use_name}."
@@ -1033,8 +1033,8 @@ get() {
10331033
file)
10341034
is_file_str=$2
10351035
[[ ! $is_file_str ]] && is_file_str='.json$'
1036-
# is_all_json=("$(ls $is_conf_dir | egrep $is_file_str)")
1037-
readarray -t is_all_json <<<"$(ls $is_conf_dir | egrep -i "$is_file_str" | sed '/dynamic-port-.*-link/d' | head -233)" # limit max 233 lines for show.
1036+
# is_all_json=("$(ls $is_conf_dir | grep -E $is_file_str)")
1037+
readarray -t is_all_json <<<"$(ls $is_conf_dir | grep -E -i "$is_file_str" | sed '/dynamic-port-.*-link/d' | head -233)" # limit max 233 lines for show.
10381038
[[ ! $is_all_json ]] && err "无法找到相关的配置文件: $2"
10391039
[[ ${#is_all_json[@]} -eq 1 ]] && is_config_file=$is_all_json && is_auto_get_config=1
10401040
[[ ! $is_config_file ]] && {
@@ -1071,7 +1071,7 @@ get() {
10711071
is_config_name=$is_config_file
10721072
10731073
if [[ $is_caddy && $host && -f $is_caddy_conf/$host.conf ]]; then
1074-
is_tmp_https_port=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
1074+
is_tmp_https_port=$(grep -E -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
10751075
fi
10761076
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
10771077
[[ $is_client && $host ]] && port=$is_https_port
@@ -1206,11 +1206,6 @@ get() {
12061206
[[ $(grep ":" <<<$ip) ]] && is_dns_type="aaaa"
12071207
is_host_dns=$(_wget -qO- --header="accept: application/dns-json" "https://one.one.one.one/dns-query?name=$host&type=$is_dns_type")
12081208
;;
1209-
log | logerr)
1210-
msg "\n 提醒: 按 $(_green Ctrl + C) 退出\n"
1211-
[[ $1 == 'log' ]] && tail -f $is_log_dir/access.log
1212-
[[ $1 == 'logerr' ]] && tail -f $is_log_dir/error.log
1213-
;;
12141209
install-caddy)
12151210
_green "\n安装 Caddy 实现自动配置 TLS.\n"
12161211
load download.sh
@@ -1652,7 +1647,8 @@ main() {
16521647
load import.sh
16531648
;;
16541649
log)
1655-
get $@
1650+
load log.sh
1651+
log_set $2
16561652
;;
16571653
url | qr)
16581654
url_qr $@

src/download.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ get_latest_version() {
1313
url="https://api.github.com/repos/$is_caddy_repo/releases/latest?v=$RANDOM"
1414
;;
1515
esac
16-
latest_ver=$(_wget -qO- $url | grep tag_name | egrep -o 'v([0-9.]+)')
16+
latest_ver=$(_wget -qO- $url | grep tag_name | grep -E -o 'v([0-9.]+)')
1717
[[ ! $latest_ver ]] && {
1818
err "获取 ${name} 最新版本失败."
1919
}

src/import.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ in_conf() {
1919
[[ ! $uuid ]] && uuid=$trojan_password
2020
if [[ $host ]]; then
2121
if [[ $is_caddy && -f $is_caddy_conf/$host.conf ]]; then
22-
tmp_tlsport=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
22+
tmp_tlsport=$(grep -E -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
2323
fi
2424
[[ $tmp_tlsport ]] && https_port=$tmp_tlsport
2525
add $is_protocol-$net-tls
@@ -53,10 +53,10 @@ is_change=1
5353
is_dont_auto_exit=1
5454
is_dont_test_host=1
5555
if [[ -f $is_xray_sh && -d $is_xray_conf ]]; then
56-
is_list=($(ls $is_xray_conf | grep .json | egrep -iv 'kcp|grpc|dynamic|quic' | sed "s#^#$is_xray_conf/#"))
56+
is_list=($(ls $is_xray_conf | grep .json | grep -E -iv 'kcp|grpc|dynamic|quic' | sed "s#^#$is_xray_conf/#"))
5757
fi
5858
if [[ -f $is_v2ray_sh && -d $is_v2ray_conf ]]; then
59-
is_list+=($(ls $is_v2ray_conf | grep .json | egrep -iv 'kcp|grpc|dynamic|quic' | sed "s#^#$is_v2ray_conf/#"))
59+
is_list+=($(ls $is_v2ray_conf | grep .json | grep -E -iv 'kcp|grpc|dynamic|quic' | sed "s#^#$is_v2ray_conf/#"))
6060
fi
6161
[[ ${is_list[@]} =~ "xray" ]] && is_xray_in=1
6262
[[ ${is_list[@]} =~ "v2ray" ]] && is_v2ray_in=1

src/init.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ if [[ -f $is_caddy_bin && -d $is_caddy_dir && $is_caddy_service ]]; then
124124
systemctl restart caddy &
125125
}
126126
is_caddy_ver=$($is_caddy_bin version | head -n1 | cut -d " " -f1)
127-
is_tmp_http_port=$(egrep '^ {2,}http_port|^http_port' $is_caddyfile | egrep -o [0-9]+)
128-
is_tmp_https_port=$(egrep '^ {2,}https_port|^https_port' $is_caddyfile | egrep -o [0-9]+)
127+
is_tmp_http_port=$(grep -E '^ {2,}http_port|^http_port' $is_caddyfile | grep -E -o [0-9]+)
128+
is_tmp_https_port=$(grep -E '^ {2,}https_port|^https_port' $is_caddyfile | grep -E -o [0-9]+)
129129
[[ $is_tmp_http_port ]] && is_http_port=$is_tmp_http_port
130130
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
131131
if [[ $(pgrep -f $is_caddy_bin) ]]; then

src/log.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
is_log_level_list=(
2+
trace
3+
debug
4+
info
5+
warn
6+
error
7+
fatal
8+
panic
9+
none
10+
del
11+
)
12+
log_set() {
13+
if [[ $1 ]]; then
14+
for v in ${is_log_level_list[@]}; do
15+
[[ $(grep -E -i "^${1,,}$" <<<$v) ]] && is_log_level_use=$v && break
16+
done
17+
[[ ! $is_log_level_use ]] && {
18+
err "无法识别 log 参数: $@ \n请使用 $is_core log [${is_log_level_list[@]}] 进行相关设定.\n备注: del 参数仅临时删除 log 文件; none 参数将不会生成 log 文件."
19+
}
20+
case $is_log_level_use in
21+
del)
22+
rm -rf $is_log_dir/*.log
23+
msg "\n $(_green 已临时删除 log 文件, 如果你想要完全禁止生成 log 文件请使用: $is_core log none)\n"
24+
;;
25+
none)
26+
rm -rf $is_log_dir/*.log
27+
cat <<<$(jq '.log={"disabled":true}' $is_config_json) >$is_config_json
28+
;;
29+
*)
30+
cat <<<$(jq '.log={output:"/var/log/'$is_core'/access.log",level:"'$is_log_level_use'","timestamp":true}' $is_config_json) >$is_config_json
31+
;;
32+
esac
33+
34+
manage restart &
35+
[[ $1 != 'del' ]] && msg "\n已更新 Log 设定为: $(_green $is_log_level_use)\n"
36+
else
37+
if [[ -f $is_log_dir/access.log ]]; then
38+
msg "\n 提醒: 按 $(_green Ctrl + C) 退出\n"
39+
tail -f $is_log_dir/access.log
40+
else
41+
err "无法找到 log 文件."
42+
fi
43+
fi
44+
}

0 commit comments

Comments
 (0)