Skip to content

Commit f75e3f1

Browse files
committed
fix bug and add update dat file
1 parent 4d1279d commit f75e3f1

9 files changed

+74
-32
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
使用: `v2ray help`
5454

5555
```
56-
V2Ray script v4.0 by 233boy
56+
V2Ray script v4.21 by 233boy
5757
Usage: v2ray [options]... [args]...
5858
5959
基本:
@@ -95,17 +95,18 @@ Usage: v2ray [options]... [args]...
9595
9696
管理:
9797
un, uninstall 卸载
98-
u, update [core | sh | caddy] [ver] 更新
98+
u, update [core | sh | dat | caddy] [ver] 更新
9999
U, update.sh 更新脚本
100100
s, status 运行状态
101101
start, stop, restart [caddy] 启动, 停止, 重启
102102
t, test 测试运行
103103
reinstall 重装脚本
104104
105105
测试:
106-
client, genc [name] 显示用于客户端 JSON, 仅供参考
106+
client [name] 显示用于客户端 JSON, 仅供参考
107107
debug [name] 显示一些 debug 信息, 仅供参考
108108
gen [...] 同等于 add, 但只显示 JSON 内容, 不创建文件, 测试使用
109+
genc [name] 显示用于客户端部分 JSON, 仅供参考
109110
no-auto-tls [...] 同等于 add, 但禁止自动配置 TLS, 可用于 *TLS 相关协议
110111
xapi [...] 同等于 v2ray api, 但 API 后端使用当前运行的 V2Ray 服务
111112

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ download() {
174174
is_ok=$is_sh_ok
175175
;;
176176
jq)
177-
link=https://github.com/jqlang/jq/releases/download/jq-1.7rc1/jq-linux-$is_jq_arch
177+
link=https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-$is_jq_arch
178178
name="jq"
179179
tmpfile=$tmpjq
180180
is_ok=$is_jq_ok

src/caddy.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@ caddy_config() {
1111
# https://caddyserver.com/docs/caddyfile/options
1212
{
1313
admin off
14+
http_port $is_http_port
15+
https_port $is_https_port
1416
}
1517
import $is_caddy_conf/*.conf
1618
import $is_caddy_dir/sites/*.conf
1719
EOF
1820
;;
1921
*ws*)
2022
cat >${is_caddy_site_file} <<<"
21-
${host}:${tlsport} {
23+
${host}:${is_https_port} {
2224
reverse_proxy ${path} 127.0.0.1:${port}
2325
import ${is_caddy_site_file}.add
2426
}"
2527
;;
2628
*h2*)
2729
cat >${is_caddy_site_file} <<<"
28-
${host}:${tlsport} {
30+
${host}:${is_https_port} {
2931
reverse_proxy ${path} h2c://127.0.0.1:${port}
3032
import ${is_caddy_site_file}.add
3133
}"
3234
;;
3335
*grpc*)
3436
cat >${is_caddy_site_file} <<<"
35-
${host}:${tlsport} {
37+
${host}:${is_https_port} {
3638
reverse_proxy /${path}/* h2c://127.0.0.1:${port}
3739
import ${is_caddy_site_file}.add
3840
}"

src/core.sh

+38-14
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,13 @@ create() {
384384
get info $2
385385
[[ ! $is_client_id_json ]] && err "($is_config_name) 不支持生成客户端配置."
386386
is_new_json=$(jq '{outbounds:[{tag:'\"$is_config_name\"',protocol:'\"$is_protocol\"','"$is_client_id_json"','"$is_stream"'}]}' <<<{})
387+
if [[ $is_full_client ]]; then
388+
is_dns='dns:{servers:[{address:"223.5.5.5",domain:["geosite:cn","geosite:geolocation-cn"],expectIPs:["geoip:cn"]},"1.1.1.1","8.8.8.8"]}'
389+
is_route='routing:{rules:[{type:"field",outboundTag:"direct",ip:["geoip:cn","geoip:private"]},{type:"field",outboundTag:"direct",domain:["geosite:cn","geosite:geolocation-cn"]}]}'
390+
is_inbounds='inbounds:[{port:2333,listen:"127.0.0.1",protocol:"socks",settings:{udp:true},sniffing:{enabled:true,destOverride:["http","tls"]}}]'
391+
is_outbounds='outbounds:[{tag:'\"$is_config_name\"',protocol:'\"$is_protocol\"','"$is_client_id_json"','"$is_stream"'},{tag:"direct",protocol:"freedom"}]'
392+
is_new_json=$(jq '{'$is_dns,$is_route,$is_inbounds,$is_outbounds'}' <<<{})
393+
fi
387394
msg
388395
jq <<<$is_new_json
389396
msg
@@ -527,7 +534,7 @@ change() {
527534
[[ ! $is_new_port ]] && ask string is_new_port "请输入新端口:"
528535
if [[ $is_caddy && $host ]]; then
529536
net=$is_old_net
530-
tlsport=$is_new_port
537+
is_https_port=$is_new_port
531538
load caddy.sh
532539
caddy_config $net
533540
manage restart caddy &
@@ -978,7 +985,7 @@ add() {
978985
;;
979986
kcp | quic)
980987
kcp_seed=
981-
[[ $(grep tcp <<<$is_new_protocol) ]] && header_type=
988+
[[ $(grep -i tcp <<<$is_new_protocol) ]] && header_type=
982989
;;
983990
h2 | ws | grpc)
984991
old_host=$host
@@ -989,6 +996,7 @@ add() {
989996
path=/$path
990997
}
991998
fi
999+
[[ ! $(grep -i trojan <<<$is_new_protocol) ]] && is_trojan=
9921000
;;
9931001
reality)
9941002
[[ ! $(grep -i reality <<<$is_new_protocol) ]] && is_reality=
@@ -1001,7 +1009,7 @@ add() {
10011009
is_dynamic_port=
10021010
}
10031011

1004-
[[ $is_trojan && ! $(is_test uuid $trojan_password) ]] && uuid=
1012+
[[ ! $(is_test uuid $uuid) ]] && uuid=
10051013
fi
10061014

10071015
# no-auto-tls only use h2,ws,grpc
@@ -1079,9 +1087,15 @@ add() {
10791087
if [[ ! $is_no_auto_tls && ! $is_caddy && ! $is_gen ]]; then
10801088
# test auto tls
10811089
[[ $(is_test port_used 80) || $(is_test port_used 443) ]] && {
1082-
warn "端口 (80 或 443) 已经被占用, 无法完成自动配置 TLS. 请考虑使用 no-auto-tls"
1083-
msg "\e[41m帮助(help)\e[0m: $(msg_ul https://233boy.com/$is_core/no-auto-tls/)\n"
1084-
exit 1
1090+
get_port
1091+
is_http_port=$tmp_port
1092+
get_port
1093+
is_https_port=$tmp_port
1094+
warn "端口 (80 或 443) 已经被占用, 你也可以考虑使用 no-auto-tls"
1095+
msg "\e[41m no-auto-tls 帮助(help)\e[0m: $(msg_ul https://233boy.com/$is_core/no-auto-tls/)\n"
1096+
msg "\n Caddy 将使用非标准端口实现自动配置 TLS, HTTP:$is_http_port HTTPS:$is_https_port\n"
1097+
msg "请确定是否继续???"
1098+
pause
10851099
}
10861100
is_install_caddy=1
10871101
fi
@@ -1226,10 +1240,10 @@ get() {
12261240
[[ $? != 0 ]] && err "无法读取动态端口文件: $is_dynamic_port"
12271241
fi
12281242
if [[ $is_caddy && $host && -f $is_caddy_conf/$host.conf ]]; then
1229-
tmp_tlsport=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
1243+
is_tmp_https_port=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
12301244
fi
1231-
[[ $tmp_tlsport ]] && tlsport=$tmp_tlsport
1232-
[[ $is_client && $host ]] && port=$tlsport
1245+
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
1246+
[[ $is_client && $host ]] && port=$is_https_port
12331247
get protocol $is_protocol-$net
12341248
fi
12351249
;;
@@ -1501,19 +1515,18 @@ info() {
15011515
is_url_path=serviceName
15021516
}
15031517
[[ $is_protocol == 'vmess' ]] && {
1504-
is_vmess_url=$(jq -c '{v:2,ps:'\"233boy-$net-$host\"',add:'\"$is_addr\"',port:'\"$tlsport\"',id:'\"$uuid\"',aid:"0",net:'\"$net\"',host:'\"$host\"',path:'\"$path\"',tls:'\"tls\"'}' <<<{})
1518+
is_vmess_url=$(jq -c '{v:2,ps:'\"233boy-$net-$host\"',add:'\"$is_addr\"',port:'\"$is_https_port\"',id:'\"$uuid\"',aid:"0",net:'\"$net\"',host:'\"$host\"',path:'\"$path\"',tls:'\"tls\"'}' <<<{})
15051519
is_url=vmess://$(echo -n $is_vmess_url | base64 -w 0)
15061520
} || {
15071521
[[ $is_trojan ]] && {
15081522
uuid=$trojan_password
1509-
is_info_str=($is_protocol $is_addr $tlsport $trojan_password $net $host $path 'tls')
15101523
is_can_change=(0 1 2 3 4)
15111524
is_info_show=(0 1 2 10 4 6 7 8)
15121525
}
1513-
is_url="$is_protocol://$uuid@$host:$tlsport?encryption=none&security=tls&type=$net&host=$host&${is_url_path}=$(sed 's#/#%2F#g' <<<$path)#233boy-$net-$host"
1526+
is_url="$is_protocol://$uuid@$host:$is_https_port?encryption=none&security=tls&type=$net&host=$host&${is_url_path}=$(sed 's#/#%2F#g' <<<$path)#233boy-$net-$host"
15141527
}
15151528
[[ $is_caddy ]] && is_can_change+=(13)
1516-
is_info_str=($is_protocol $is_addr $tlsport $uuid $net $host $path 'tls')
1529+
is_info_str=($is_protocol $is_addr $is_https_port $uuid $net $host $path 'tls')
15171530
;;
15181531
reality)
15191532
is_color=41
@@ -1550,6 +1563,9 @@ info() {
15501563
fi
15511564
msg "$a $tt= \e[${is_color}m${is_info_str[$i]}\e[0m"
15521565
done
1566+
if [[ $is_new_install ]]; then
1567+
warn "首次安装请查看脚本帮助文档: $(msg_ul https://233boy.com/$is_core/$is_core-script/)"
1568+
fi
15531569
if [[ $is_url ]]; then
15541570
msg "------------- ${info_list[12]} -------------"
15551571
msg "\e[4;${is_color}m${is_url}\e[0m"
@@ -1760,6 +1776,7 @@ main() {
17601776
change ${@:2}
17611777
;;
17621778
client | genc)
1779+
[[ $1 == 'client' ]] && is_full_client=1
17631780
create client $2
17641781
;;
17651782
d | del | rm)
@@ -1845,7 +1862,14 @@ main() {
18451862
is_update_name=sh
18461863
is_update_ver=
18471864
}
1848-
update $is_update_name $is_update_ver
1865+
if [[ $2 == 'dat' ]]; then
1866+
load download.sh
1867+
download dat
1868+
msg "$(_green 更新 geoip.dat geosite.dat 成功.)\n"
1869+
manage restart &
1870+
else
1871+
update $is_update_name $is_update_ver
1872+
fi
18491873
;;
18501874
ssss | ss2022)
18511875
get $@

src/dns.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,16 @@ dns_set() {
4141
esac
4242
else
4343
is_tmp_list=(${is_dns_list[@]})
44-
ask list dns_pick
45-
is_dns_use=${is_dns_list[$REPLY - 1]}
44+
ask list is_dns_use null "\n请选择 DNS:\n"
4645
if [[ $is_dns_use == "set" ]]; then
4746
ask string is_dns_use "请输入 DNS: "
4847
fi
4948
fi
50-
is_new_dns=$(sed s/https/https+local/ <<<$is_dns_use)
51-
if [[ $is_new_dns == "none" ]]; then
49+
if [[ $is_dns_use == "none" ]]; then
5250
cat <<<$(jq '.dns={}' $is_config_json) >$is_config_json
5351
else
54-
cat <<<$(jq '.dns.servers=["'$is_new_dns'"]' $is_config_json) >$is_config_json
52+
cat <<<$(jq '.dns.servers=["'${is_dns_use/https/https+local}'"]' $is_config_json) >$is_config_json
5553
fi
5654
manage restart &
57-
msg "\n已更新 DNS 为: $(_green $is_new_dns)\n"
55+
msg "\n已更新 DNS 为: $(_green $is_dns_use)\n"
5856
}

src/download.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ get_latest_version() {
2121
}
2222
download() {
2323
latest_ver=$2
24-
[[ ! $latest_ver ]] && get_latest_version $1
24+
[[ ! $latest_ver && $1 != 'dat' ]] && get_latest_version $1
2525
# tmp dir
2626
tmpdir=$(mktemp -u)
2727
[[ ! $tmpdir ]] && {
@@ -45,6 +45,17 @@ download() {
4545
unzip -qo $tmpfile -d $is_sh_dir
4646
chmod +x $is_sh_bin
4747
;;
48+
dat)
49+
name="geoip.dat"
50+
tmpfile=$tmpdir/geoip.dat
51+
link="https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
52+
download_file
53+
name="geosite.dat"
54+
tmpfile=$tmpdir/geosite.dat
55+
link="https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
56+
download_file
57+
cp -f $tmpdir/*.dat $is_core_dir/bin/
58+
;;
4859
caddy)
4960
name="Caddy"
5061
tmpfile=$tmpdir/caddy.tar.gz

src/help.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ show_help() {
4848
" fix-config.json 修复 config.json\n"
4949
"管理:"
5050
" un, uninstall 卸载"
51-
" u, update [core | sh | caddy] [ver] 更新"
51+
" u, update [core | sh | dat | caddy] [ver] 更新"
5252
" U, update.sh 更新脚本"
5353
" s, status 运行状态"
5454
" start, stop, restart [caddy] 启动, 停止, 重启"
5555
" t, test 测试运行"
5656
" reinstall 重装脚本\n"
5757
"测试:"
58-
" client, genc [name] 显示用于客户端 JSON, 仅供参考"
58+
" client [name] 显示用于客户端 JSON, 仅供参考"
5959
" debug [name] 显示一些 debug 信息, 仅供参考"
6060
" gen [...] 同等于 add, 但只显示 JSON 内容, 不创建文件, 测试使用"
61+
" genc [name] 显示用于客户端部分 JSON, 仅供参考"
6162
" no-auto-tls [...] 同等于 add, 但禁止自动配置 TLS, 可用于 *TLS 相关协议"
6263
" xapi [...] 同等于 $is_core api, 但 API 后端使用当前运行的 $is_core_name 服务\n"
6364
"其他:"

src/init.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ is_caddy_repo=caddyserver/caddy
9494
is_caddyfile=$is_caddy_dir/Caddyfile
9595
is_caddy_conf=$is_caddy_dir/$author
9696
is_caddy_service=$(systemctl list-units --full -all | grep caddy.service)
97-
tlsport=443
97+
is_http_port=80
98+
is_https_port=443
9899

99100
# core ver
100101
is_core_ver=$($is_core_bin version | head -n1 | cut -d " " -f1-2)
@@ -129,6 +130,10 @@ if [[ -f $is_caddy_bin && -d $is_caddy_dir && $is_caddy_service ]]; then
129130
systemctl restart caddy &
130131
}
131132
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]+)
135+
[[ $is_tmp_http_port ]] && is_http_port=$is_tmp_http_port
136+
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
132137
if [[ $(pgrep -f $is_caddy_bin) ]]; then
133138
is_caddy_status=$(_green running)
134139
else

v2ray.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
args=$@
4-
is_sh_ver=v4.20
4+
is_sh_ver=v4.21
55

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

0 commit comments

Comments
 (0)