Skip to content

Commit 6669cbd

Browse files
committed
fix bug and add update dat file
1 parent 26caca0 commit 6669cbd

9 files changed

+74
-32
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
使用:`xray help`
5151

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

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 &
@@ -974,7 +981,7 @@ add() {
974981
;;
975982
kcp | quic)
976983
kcp_seed=
977-
[[ $(grep tcp <<<$is_new_protocol) ]] && header_type=
984+
[[ $(grep -i tcp <<<$is_new_protocol) ]] && header_type=
978985
;;
979986
h2 | ws | grpc)
980987
old_host=$host
@@ -985,6 +992,7 @@ add() {
985992
path=/$path
986993
}
987994
fi
995+
[[ ! $(grep -i trojan <<<$is_new_protocol) ]] && is_trojan=
988996
;;
989997
reality)
990998
[[ ! $(grep -i reality <<<$is_new_protocol) ]] && is_reality=
@@ -997,7 +1005,7 @@ add() {
9971005
is_dynamic_port=
9981006
}
9991007

1000-
[[ $is_trojan && ! $(is_test uuid $trojan_password) ]] && uuid=
1008+
[[ ! $(is_test uuid $uuid) ]] && uuid=
10011009
fi
10021010

10031011
# no-auto-tls only use h2,ws,grpc
@@ -1075,9 +1083,15 @@ add() {
10751083
if [[ ! $is_no_auto_tls && ! $is_caddy && ! $is_gen ]]; then
10761084
# test auto tls
10771085
[[ $(is_test port_used 80) || $(is_test port_used 443) ]] && {
1078-
warn "端口 (80 或 443) 已经被占用, 无法完成自动配置 TLS. 请考虑使用 no-auto-tls"
1079-
msg "\e[41m帮助(help)\e[0m: $(msg_ul https://233boy.com/$is_core/no-auto-tls/)\n"
1080-
exit 1
1086+
get_port
1087+
is_http_port=$tmp_port
1088+
get_port
1089+
is_https_port=$tmp_port
1090+
warn "端口 (80 或 443) 已经被占用, 你也可以考虑使用 no-auto-tls"
1091+
msg "\e[41m no-auto-tls 帮助(help)\e[0m: $(msg_ul https://233boy.com/$is_core/no-auto-tls/)\n"
1092+
msg "\n Caddy 将使用非标准端口实现自动配置 TLS, HTTP:$is_http_port HTTPS:$is_https_port\n"
1093+
msg "请确定是否继续???"
1094+
pause
10811095
}
10821096
is_install_caddy=1
10831097
fi
@@ -1222,10 +1236,10 @@ get() {
12221236
[[ $? != 0 ]] && err "无法读取动态端口文件: $is_dynamic_port"
12231237
fi
12241238
if [[ $is_caddy && $host && -f $is_caddy_conf/$host.conf ]]; then
1225-
tmp_tlsport=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
1239+
is_tmp_https_port=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
12261240
fi
1227-
[[ $tmp_tlsport ]] && tlsport=$tmp_tlsport
1228-
[[ $is_client && $host ]] && port=$tlsport
1241+
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
1242+
[[ $is_client && $host ]] && port=$is_https_port
12291243
get protocol $is_protocol-$net
12301244
fi
12311245
;;
@@ -1497,19 +1511,18 @@ info() {
14971511
is_url_path=serviceName
14981512
}
14991513
[[ $is_protocol == 'vmess' ]] && {
1500-
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\"'}' <<<{})
1514+
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\"'}' <<<{})
15011515
is_url=vmess://$(echo -n $is_vmess_url | base64 -w 0)
15021516
} || {
15031517
[[ $is_trojan ]] && {
15041518
uuid=$trojan_password
1505-
is_info_str=($is_protocol $is_addr $tlsport $trojan_password $net $host $path 'tls')
15061519
is_can_change=(0 1 2 3 4)
15071520
is_info_show=(0 1 2 10 4 6 7 8)
15081521
}
1509-
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"
1522+
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"
15101523
}
15111524
[[ $is_caddy ]] && is_can_change+=(13)
1512-
is_info_str=($is_protocol $is_addr $tlsport $uuid $net $host $path 'tls')
1525+
is_info_str=($is_protocol $is_addr $is_https_port $uuid $net $host $path 'tls')
15131526
;;
15141527
reality)
15151528
is_color=41
@@ -1546,6 +1559,9 @@ info() {
15461559
fi
15471560
msg "$a $tt= \e[${is_color}m${is_info_str[$i]}\e[0m"
15481561
done
1562+
if [[ $is_new_install ]]; then
1563+
warn "首次安装请查看脚本帮助文档: $(msg_ul https://233boy.com/$is_core/$is_core-script/)"
1564+
fi
15491565
if [[ $is_url ]]; then
15501566
msg "------------- ${info_list[12]} -------------"
15511567
msg "\e[4;${is_color}m${is_url}\e[0m"
@@ -1751,6 +1767,7 @@ main() {
17511767
change ${@:2}
17521768
;;
17531769
client | genc)
1770+
[[ $1 == 'client' ]] && is_full_client=1
17541771
create client $2
17551772
;;
17561773
d | del | rm)
@@ -1836,7 +1853,14 @@ main() {
18361853
is_update_name=sh
18371854
is_update_ver=
18381855
}
1839-
update $is_update_name $is_update_ver
1856+
if [[ $2 == 'dat' ]]; then
1857+
load download.sh
1858+
download dat
1859+
msg "$(_green 更新 geoip.dat geosite.dat 成功.)\n"
1860+
manage restart &
1861+
else
1862+
update $is_update_name $is_update_ver
1863+
fi
18401864
;;
18411865
ssss | ss2022)
18421866
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)
@@ -114,6 +115,10 @@ if [[ -f $is_caddy_bin && -d $is_caddy_dir && $is_caddy_service ]]; then
114115
systemctl restart caddy &
115116
}
116117
is_caddy_ver=$($is_caddy_bin version | head -n1 | cut -d " " -f1)
118+
is_tmp_http_port=$(egrep '^ {2,}http_port|^http_port' $is_caddyfile | egrep -o [0-9]+)
119+
is_tmp_https_port=$(egrep '^ {2,}https_port|^https_port' $is_caddyfile | egrep -o [0-9]+)
120+
[[ $is_tmp_http_port ]] && is_http_port=$is_tmp_http_port
121+
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
117122
if [[ $(pgrep -f $is_caddy_bin) ]]; then
118123
is_caddy_status=$(_green running)
119124
else

xray.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=v1.20
4+
is_sh_ver=v1.21
55

66
. /etc/xray/sh/src/init.sh

0 commit comments

Comments
 (0)