Skip to content

Commit

Permalink
Support qtun #84
Browse files Browse the repository at this point in the history
  • Loading branch information
loyess committed Dec 15, 2021
1 parent b04be19 commit fac0b06
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 103 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Available Options:
1. ws
2. wss
3. quic
11. qtun

注意:
kcptun仅用于加速。
Expand Down Expand Up @@ -195,7 +196,7 @@ Available Options:

本脚本改自于各路大神,水平马马虎虎,方便自用。

这里只对 linux-amd64 处理器架构做了支持,其它的就不要尝试了,支持 CentOS6+ | Ubuntu16.04+ | Debian9+ ,其它更低版本是否支持,请自行尝试。推荐使用最新版。
支持 linux-amd64,部分支持 linux-arm64 (aarch64),其它的就不要尝试了,支持 CentOS6+ | Ubuntu16.04+ | Debian9+ ,其它更低版本是否支持,请自行尝试。推荐使用最新版。

~~v2ray-plugin 所要用到的域名,可以从 [freenom.com](https://www.freenom.com) 获取免费域名, 申请需要挂代理,代理是哪国ip 就填写哪国的资料,不然会导致无法申请。~~ (似乎失效了,有账号的仍能注册)

Expand Down Expand Up @@ -233,3 +234,4 @@ Available Options:
- [gost-plugin-android](https://github.com/maskedeken/gost-plugin-android)
- [xray-plugin](https://github.com/teddysun/xray-plugin)
- [xray-plugin-android](https://github.com/teddysun/xray-plugin-android)
- [qtun](https://github.com/shadowsocks/qtun)
18 changes: 18 additions & 0 deletions plugins/qtun_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
install_qtun(){
cd ${CUR_DIR}
tar xf ${qtun_file}.tar.xz
if [ ! -d ${QTUN_INSTALL_PATH} ]; then
mkdir -p ${QTUN_INSTALL_PATH}
fi
mv qtun-server ${QTUN_BIN_PATH}
if [ $? -eq 0 ]; then
[ -f ${QTUN_BIN_PATH} ] && ln -fs ${QTUN_BIN_PATH} /usr/bin
echo -e "${Info} qtun安装成功."
else
echo
echo -e "${Error} qtun安装失败."
echo
install_cleanup
exit 1
fi
}
69 changes: 69 additions & 0 deletions prepare/qtun_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
improt_package "utils" "gen_certificates.sh"


print_domain_info(){
domainType=$1

echo
echo -e "${Red} host = ${domain}${suffix} ${Green}(${domainType})${suffix}"
echo
}

get_input_domain(){
while true
do
echo
read -e -p "请输入一个域名(CDN 或 DNS-Only):" domain

if [ -z "$domain" ]; then
echo
echo -e "${Error} 无默认参数,不能为空,请重新输入."
echo
continue
fi

if ! get_domain_ip ${domain}; then
echo
echo -e "${Error} 请输入一个正确有效的域名."
echo
continue
fi

if is_cdn_proxied ${domain_ip}; then
print_domain_info "CDN"
break
elif is_dns_only ${domain_ip}; then
print_domain_info "DNS-Only"
break
else
echo
echo -e "${Error} 请输入一个正确有效的域名."
echo
continue
fi
done
}

qtun_prot_reset(){
shadowsocksport=$1

if check_port_occupy ${shadowsocksport}; then
echo -e "${Error} 检测到${shadowsocksport}端口被占用,请排查后重新运行."
exit 1
fi

echo
echo -e "${Tip} Shadowsocks端口已被重置为${Green}${shadowsocksport}${suffix}"
echo
}

install_prepare_libev_qtun(){
get_input_domain
qtun_prot_reset 443

if [[ ${domainType} = DNS-Only ]]; then
acme_get_certificate_by_force "${domain}" "RSA"
elif [[ ${domainType} = CDN ]]; then
acme_get_certificate_by_api_or_manual "${domain}" "RSA"
fi
}
14 changes: 12 additions & 2 deletions service/go-shadowsocks2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ get_config_args(){
[ -z "$Password" ] && echo -e "Configuration option 'password' acquisition failed" && exit 1
Method=$(cat ${JsonFilePath} | jq -r .method)
[ -z "$Method" ] && echo -e "Configuration option 'method' acquisition failed" && exit 1
Mode=$(cat ${JsonFilePath} | jq -r .mode)
[ -z "$Mode" ] && echo -e "Configuration option 'Mode' acquisition failed" && exit 1

if [[ ${Method} == "aes-128-gcm" ]]; then
Method="AEAD_AES_128_GCM"
Expand All @@ -88,6 +90,14 @@ get_config_args(){
Method="AEAD_CHACHA20_POLY1305"
fi

if [[ ${Mode} == "tcp_only" ]]; then
Mode="-tcp"
elif [[ ${Mode} == "udp_only" ]]; then
Mode="-udp"
elif [[ ${Mode} == "tcp_and_udp" ]]; then
Mode="-tcp -udp"
fi

if $(cat ${JsonFilePath} | grep -qE 'plugin|plugin_opts'); then
Plugin=$(cat ${JsonFilePath} | jq -r .plugin)
[ -z "$Plugin" ] && echo -e "Configuration option 'plugin' acquisition failed" && exit 1
Expand Down Expand Up @@ -139,9 +149,9 @@ do_start() {
fi
ulimit -n 51200
if $(cat ${CONF} | grep -qE 'plugin|plugin_opts'); then
nohup $DAEMON -s "ss:https://${Method}:${Password}@:${ServerPort}" -verbose -plugin ${Plugin} -plugin-opts "${PluginOpts}" > $LOG 2>&1 &
nohup $DAEMON -s "ss:https://${Method}:${Password}@:${ServerPort}" ${Mode} -verbose -plugin ${Plugin} -plugin-opts "${PluginOpts}" > $LOG 2>&1 &
else
nohup $DAEMON -s "ss:https://${Method}:${Password}@:${ServerPort}" -verbose > $LOG 2>&1 &
nohup $DAEMON -s "ss:https://${Method}:${Password}@:${ServerPort}" ${Mode} -verbose > $LOG 2>&1 &
fi
check_pid "${DAEMON}"
echo $GET_PID > $PID_FILE
Expand Down
34 changes: 32 additions & 2 deletions ss-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export PATH

# shell version
# ====================
SHELL_VERSION="2.7.3"
SHELL_VERSION="2.7.4"
# ====================


Expand Down Expand Up @@ -127,6 +127,12 @@ XRAY_PLUGIN_BIN_PATH="/usr/local/bin/xray-plugin"
XRAY_PLUGIN_VERSION_FILE="/etc/shadowsocks/xray-plugin.v"


# qtun
QTUN_INSTALL_PATH="/usr/local/bin"
QTUN_BIN_PATH="/usr/local/bin/qtun-server"
QTUN_VERSION_FILE="/etc/shadowsocks/qtun.v"


# caddy
CADDY_INSTALL_PATH="/usr/local/caddy"
CADDY_BIN_PATH="/usr/local/caddy/caddy"
Expand Down Expand Up @@ -250,6 +256,10 @@ status_init(){
pluginName="Xray-plugin"
pluginPath=${XRAY_PLUGIN_BIN_PATH}
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep xray-plugin | awk '{print $2}'`
elif [[ -e ${QTUN_BIN_PATH} ]]; then
pluginName="qtun"
pluginPath=${QTUN_BIN_PATH}
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep qtun-server | awk '{print $2}'`
fi

if [[ -e ${CADDY_BIN_PATH} ]]; then
Expand Down Expand Up @@ -659,6 +669,9 @@ config_ss(){
elif [[ ${plugin_num} == "10" ]]; then
improt_package "templates/config" "xray_plugin_config.sh"
config_ss_xray_plugin
elif [[ ${plugin_num} == "11" ]]; then
improt_package "templates/config" "qtun_config.sh"
config_ss_qtun
else
improt_package "templates/config" "ss_original_config.sh"
ss_config_standalone
Expand Down Expand Up @@ -696,6 +709,9 @@ gen_ss_links(){
elif [[ ${plugin_num} == "10" ]]; then
improt_package "templates/links" "xray_plugin_link.sh"
gen_ss_xray_plugin_link
elif [[ ${plugin_num} == "11" ]]; then
improt_package "templates/links" "qtun_link.sh"
gen_ss_qtun_link
else
improt_package "templates/links" "ss_original_link.sh"
ss_link
Expand Down Expand Up @@ -742,6 +758,9 @@ install_completed(){
elif [[ ${plugin_num} == "10" ]]; then
improt_package "templates/visible" "xray_plugin_visible.sh"
ss_xray_plugin_visible
elif [[ ${plugin_num} == "11" ]]; then
improt_package "templates/visible" "qtun_visible.sh"
ss_qtun_visible
else
improt_package "templates/visible" "ss_original_visible.sh"
ss_show
Expand All @@ -761,6 +780,7 @@ install_prepare(){
simple-tls
gost-plugin
xray-plugin
qtun
)

check_script_update "notShow"
Expand Down Expand Up @@ -812,10 +832,13 @@ install_prepare(){
elif [[ ${plugin_num} == "10" ]]; then
improt_package "prepare" "xray_plugin_prepare.sh"
install_prepare_libev_xray_plugin
elif [[ ${plugin_num} == "11" ]]; then
improt_package "prepare" "qtun_prepare.sh"
install_prepare_libev_qtun
elif [[ ${plugin_num} == "" ]]; then
:
else
echo -e "${Error} 请输入正确的数字 [1-8]" && exit 1
echo -e "${Error} 请输入正确的数字 [1-${#pluginName[@]}]" && exit 1
fi

echo
Expand Down Expand Up @@ -912,6 +935,10 @@ install_main(){
install_nginx
fi
plugin_client_name="xray-plugin"
elif [ "${plugin_num}" == "11" ]; then
improt_package "plugins" "qtun_install.sh"
install_qtun
plugin_client_name="qtun-client"
fi
}

Expand Down Expand Up @@ -980,6 +1007,9 @@ install_cleanup(){

# xray-plugin
rm -rf ${xray_plugin_file}.tar.gz

# qtun
rm -rf qtun-client ${qtun_file}.tar.xz
}

do_uid(){
Expand Down
21 changes: 21 additions & 0 deletions templates/config/qtun_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ss + qtun config
ss_qtun_config(){
cat > ${SHADOWSOCKS_CONFIG}<<-EOF
{
"server":${server_value},
"server_port":${shadowsocksport},
"password":"${shadowsockspwd}",
"timeout":300,
"user":"nobody",
"method":"${shadowsockscipher}",
"nameserver":"8.8.8.8",
"mode":"tcp_only",
"plugin":"qtun-server",
"plugin_opts":"cert=${cerPath};key=${keyPath}"
}
EOF
}

config_ss_qtun(){
ss_qtun_config
}
12 changes: 12 additions & 0 deletions templates/links/qtun_link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ss + qtun link
ss_qtun_link(){
local link_head="ss:https://"
local cipher_pwd=$(get_str_base64_encode "${shadowsockscipher}:${shadowsockspwd}")
local ip_port_plugin="@${domain}:${shadowsocksport}/?plugin=${plugin_client_name}"
local plugin_opts=$(get_str_replace ";host=${domain}")
ss_link="${link_head}${cipher_pwd}${ip_port_plugin}${plugin_opts}"
}

gen_ss_qtun_link(){
ss_qtun_link
}
26 changes: 26 additions & 0 deletions templates/visible/qtun_visible.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ss + qtun show
ss_qtun_show(){
echo >> ${HUMAN_CONFIG}
echo -e " Shadowsocks的配置信息:" >> ${HUMAN_CONFIG}
echo >> ${HUMAN_CONFIG}
echo -e " 地址 : ${Red}${domain}${suffix}" >> ${HUMAN_CONFIG}
echo -e " 端口 : ${Red}${shadowsocksport}${suffix}" >> ${HUMAN_CONFIG}
echo -e " 密码 : ${Red}${shadowsockspwd}${suffix}" >> ${HUMAN_CONFIG}
echo -e " 加密 : ${Red}${shadowsockscipher}${suffix}" >> ${HUMAN_CONFIG}
echo -e " 插件程序 : ${Red}${plugin_client_name}${suffix}" >> ${HUMAN_CONFIG}
echo -e " 插件选项 : ${Red}host=${domain}${suffix}" >> ${HUMAN_CONFIG}
echo -e " 插件参数 : " >> ${HUMAN_CONFIG}
echo >> ${HUMAN_CONFIG}
echo -e " SS 链接 : ${Green}${ss_link}${suffix}" >> ${HUMAN_CONFIG}
echo -e " SS二维码 : ./ss-plugins.sh scan < A link at the beginning of ss:https:// >" >> ${HUMAN_CONFIG}
echo >> ${HUMAN_CONFIG}
echo >> ${HUMAN_CONFIG}
echo -e " ${Tip} SS链接${Red}不支持插件参数${suffix}导入,请手动填写。使用${Red}kcptun${suffix}插件时,该链接仅支持${Red}手机${suffix}导入." >> ${HUMAN_CONFIG}
echo -e " 插件程序下载:https://github.com/shadowsocks/qtun/releases 下载 x86_64-pc-windows 版本" >> ${HUMAN_CONFIG}
echo -e " 请解压将插件重命名为 ${plugin_client_name}.exe 并移动至 SS-Windows 客户端-安装目录的${Red}根目录${suffix}." >> ${HUMAN_CONFIG}
echo >> ${HUMAN_CONFIG}
}

ss_qtun_visible(){
ss_qtun_show
}
17 changes: 17 additions & 0 deletions utils/downloads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,22 @@ download_plugins_file(){
xray_plugin_file="xray-plugin-linux-${ARCH}-v${xray_plugin_ver}"
xray_plugin_url="https://github.com/teddysun/xray-plugin/releases/download/v${xray_plugin_ver}/xray-plugin-linux-${ARCH}-v${xray_plugin_ver}.tar.gz"
download "${xray_plugin_file}.tar.gz" "${xray_plugin_url}"
elif [[ "${plugin_num}" == "11" ]]; then
# Download qtun
qtun_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/qtun/releases | grep -o '"tag_name": ".*"' | head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${qtun_ver} ] && echo -e "${Error} 获取 qtun 最新版本失败." && exit 1
# wriet version num
if [ ! -d "$(dirname ${QTUN_VERSION_FILE})" ]; then
mkdir -p $(dirname ${QTUN_VERSION_FILE})
fi
echo ${qtun_ver} > ${QTUN_VERSION_FILE}
if [[ ${ARCH} = "amd64" ]]; then
local MACHINE="x86_64"
else
local MACHINE="aarch64"
fi
qtun_file="qtun-v${qtun_ver}.${MACHINE}-unknown-linux-musl"
qtun_url="https://github.com/shadowsocks/qtun/releases/download/v${qtun_ver}/qtun-v${qtun_ver}.${MACHINE}-unknown-linux-musl.tar.xz"
download "${qtun_file}.tar.xz" "${qtun_url}"
fi
}
Loading

0 comments on commit fac0b06

Please sign in to comment.