WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 15bab2b

Browse files
committed
support set log level
1 parent 0cac60d commit 15bab2b

File tree

6 files changed

+71
-16
lines changed

6 files changed

+71
-16
lines changed

src/core.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ show_list() {
167167
is_test() {
168168
case $1 in
169169
number)
170-
echo $2 | egrep '^[1-9][0-9]?+$'
170+
echo $2 | grep -E '^[1-9][0-9]?+$'
171171
;;
172172
port)
173173
if [[ $(is_test number $2) ]]; then
@@ -178,13 +178,13 @@ is_test() {
178178
[[ $(is_port_used $2) && ! $is_cant_test_port ]] && echo ok
179179
;;
180180
domain)
181-
echo $2 | egrep -i '^\w(\w|\-|\.)?+\.\w+$'
181+
echo $2 | grep -E -i '^\w(\w|\-|\.)?+\.\w+$'
182182
;;
183183
path)
184-
echo $2 | egrep -i '^\/\w(\w|\-|\/)?+\w$'
184+
echo $2 | grep -E -i '^\/\w(\w|\-|\/)?+\w$'
185185
;;
186186
uuid)
187-
echo $2 | egrep -i '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
187+
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}'
188188
;;
189189
esac
190190

@@ -911,7 +911,7 @@ add() {
911911
;;
912912
*)
913913
for v in ${protocol_list[@]}; do
914-
[[ $(egrep -i "^$is_lower$" <<<$v) ]] && is_new_protocol=$v && break
914+
[[ $(grep -E -i "^$is_lower$" <<<$v) ]] && is_new_protocol=$v && break
915915
done
916916

917917
[[ ! $is_new_protocol ]] && err "无法识别 ($1), 请使用: $is_core add [protocol] [args... | auto]"
@@ -1061,7 +1061,7 @@ add() {
10611061
ask set_header_type
10621062
}
10631063
for v in ${is_tmp_list[@]}; do
1064-
[[ $(egrep -i "^${is_use_header_type}${is_use_method}$" <<<$v) ]] && is_tmp_use_type=$v && break
1064+
[[ $(grep -E -i "^${is_use_header_type}${is_use_method}$" <<<$v) ]] && is_tmp_use_type=$v && break
10651065
done
10661066
[[ ! ${is_tmp_use_type} ]] && {
10671067
warn "(${is_use_header_type}${is_use_method}) 不是一个可用的${is_tmp_use_name}."
@@ -1198,8 +1198,8 @@ get() {
11981198
file)
11991199
is_file_str=$2
12001200
[[ ! $is_file_str ]] && is_file_str='.json$'
1201-
# is_all_json=("$(ls $is_conf_dir | egrep $is_file_str)")
1202-
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.
1201+
# is_all_json=("$(ls $is_conf_dir | grep -E $is_file_str)")
1202+
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.
12031203
[[ ! $is_all_json ]] && err "无法找到相关的配置文件: $2"
12041204
[[ ${#is_all_json[@]} -eq 1 ]] && is_config_file=$is_all_json && is_auto_get_config=1
12051205
[[ ! $is_config_file ]] && {
@@ -1244,7 +1244,7 @@ get() {
12441244
[[ $? != 0 ]] && err "无法读取动态端口文件: $is_dynamic_port"
12451245
fi
12461246
if [[ $is_caddy && $host && -f $is_caddy_conf/$host.conf ]]; then
1247-
is_tmp_https_port=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
1247+
is_tmp_https_port=$(grep -E -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
12481248
fi
12491249
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
12501250
[[ $is_client && $host ]] && port=$is_https_port
@@ -1849,8 +1849,9 @@ main() {
18491849
get_ip
18501850
msg $ip
18511851
;;
1852-
log | logerr)
1853-
get $@
1852+
log | logerr | errlog)
1853+
load log.sh
1854+
log_set $@
18541855
;;
18551856
url | qr)
18561857
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/init.sh

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

src/log.sh

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

src/old.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ if [[ $is_old_use ]]; then
100100
is_dont_show_info=1
101101
if [[ $shadowsocks ]]; then
102102
for v in ${ss_method_list[@]}; do
103-
[[ $(egrep -i "^${ssciphers}$" <<<$v) ]] && ss_method=$v && break
103+
[[ $(grep -E -i "^${ssciphers}$" <<<$v) ]] && ss_method=$v && break
104104
done
105105
if [[ $ss_method ]]; then
106106
add ss $ssport $sspass $ss_method

v2ray.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=v4.24
4+
is_sh_ver=v4.25
55

66
. /etc/v2ray/sh/src/init.sh

0 commit comments

Comments
 (0)