Skip to content

Commit

Permalink
Support gun
Browse files Browse the repository at this point in the history
  • Loading branch information
loyess committed Dec 20, 2021
1 parent e6616c0 commit ee4f969
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ Available Options:
2. wss
3. quic
11. qtun
12. gun
1. grpc-with-tls
2. grpc-without-tls

注意:
kcptun仅用于加速。
Expand Down Expand Up @@ -235,3 +238,4 @@ Available Options:
- [xray-plugin](https://github.com/teddysun/xray-plugin)
- [xray-plugin-android](https://github.com/teddysun/xray-plugin-android)
- [qtun](https://github.com/shadowsocks/qtun)
- [gun](https://github.com/Qv2ray/gun)
15 changes: 15 additions & 0 deletions plugins/gun_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
install_gun(){
cd ${CUR_DIR}
chmod +x ${gun_file}
mv ${gun_file} ${GUN_BIN_PATH}
if [ $? -eq 0 ]; then
[ -f ${GUN_BIN_PATH} ] && ln -fs ${GUN_BIN_PATH} /usr/bin
echo -e "${Info} gun安装成功."
else
echo
echo -e "${Error} gun安装失败."
echo
install_cleanup
exit 1
fi
}
118 changes: 118 additions & 0 deletions prepare/gun_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
improt_package "utils" "gen_certificates.sh"


# gun Transport mode
GUN_TRANSPORT_MODE=(
grpc-with-tls
grpc-without-tls
)


transport_mode_menu(){
while true
do
echo && echo -e "请为gun选择 Transport mode\n"
for ((i=1;i<=${#GUN_TRANSPORT_MODE[@]};i++ )); do
hint="${GUN_TRANSPORT_MODE[$i-1]}"
echo -e "${Green} ${i}.${suffix} ${hint}"
done
echo
read -e -p "(默认: ${GUN_TRANSPORT_MODE[0]}):" libev_gun
[ -z "$libev_gun" ] && libev_gun=1
expr ${libev_gun} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo
echo -e "${Error} 请输入一个数字"
echo
continue
fi
if [[ "$libev_gun" -lt 1 || "$libev_gun" -gt ${#GUN_TRANSPORT_MODE[@]} ]]; then
echo
echo -e "${Error} 请输入一个数字在 [1-${#GUN_TRANSPORT_MODE[@]}] 之间"
echo
continue
fi

shadowsocklibev_gun=${GUN_TRANSPORT_MODE[$libev_gun-1]}
echo
echo -e "${Red} over = ${shadowsocklibev_gun}${suffix}"
echo

break
done
}

print_domain_info(){
domainType=$1

echo
echo -e "${Red} domain = ${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
}

gun_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
}

grpc_with_tls_mode_logic(){
get_input_domain
gun_prot_reset 443

if [[ ${domainType} = DNS-Only ]]; then
acme_get_certificate_by_force "${domain}"
elif [[ ${domainType} = CDN ]]; then
acme_get_certificate_by_api_or_manual "${domain}"
fi
}

install_prepare_libev_gun(){
transport_mode_menu

if [[ ${libev_gun} = "1" ]]; then
grpc_with_tls_mode_logic
fi
}
29 changes: 28 additions & 1 deletion 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.5"
SHELL_VERSION="2.7.6"
# ====================


Expand Down Expand Up @@ -133,6 +133,12 @@ QTUN_BIN_PATH="/usr/local/bin/qtun-server"
QTUN_VERSION_FILE="/etc/shadowsocks/qtun.v"


# gun
GUN_INSTALL_PATH="/usr/local/bin"
GUN_BIN_PATH="/usr/local/bin/gun-server"
GUN_VERSION_FILE="/etc/shadowsocks/gun.v"


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

if [[ -e ${CADDY_BIN_PATH} ]]; then
Expand Down Expand Up @@ -672,6 +682,9 @@ config_ss(){
elif [[ ${plugin_num} == "11" ]]; then
improt_package "templates/config" "qtun_config.sh"
config_ss_qtun
elif [[ ${plugin_num} == "12" ]]; then
improt_package "templates/config" "gun_config.sh"
config_ss_gun
else
improt_package "templates/config" "ss_original_config.sh"
ss_config_standalone
Expand Down Expand Up @@ -712,6 +725,9 @@ gen_ss_links(){
elif [[ ${plugin_num} == "11" ]]; then
improt_package "templates/links" "qtun_link.sh"
gen_ss_qtun_link
elif [[ ${plugin_num} == "12" ]]; then
improt_package "templates/links" "gun_link.sh"
gen_ss_gun_link
else
improt_package "templates/links" "ss_original_link.sh"
ss_link
Expand Down Expand Up @@ -761,6 +777,9 @@ install_completed(){
elif [[ ${plugin_num} == "11" ]]; then
improt_package "templates/visible" "qtun_visible.sh"
ss_qtun_visible
elif [[ ${plugin_num} == "12" ]]; then
improt_package "templates/visible" "gun_visible.sh"
ss_gun_visible
else
improt_package "templates/visible" "ss_original_visible.sh"
ss_show
Expand All @@ -781,6 +800,7 @@ install_prepare(){
gost-plugin
xray-plugin
qtun
gun
)

check_script_update "notShow"
Expand Down Expand Up @@ -835,6 +855,9 @@ install_prepare(){
elif [[ ${plugin_num} == "11" ]]; then
improt_package "prepare" "qtun_prepare.sh"
install_prepare_libev_qtun
elif [[ ${plugin_num} == "12" ]]; then
improt_package "prepare" "gun_prepare.sh"
install_prepare_libev_gun
elif [[ ${plugin_num} == "" ]]; then
:
else
Expand Down Expand Up @@ -939,6 +962,10 @@ install_main(){
improt_package "plugins" "qtun_install.sh"
install_qtun
plugin_client_name="qtun-client"
elif [ "${plugin_num}" == "12" ]; then
improt_package "plugins" "gun_install.sh"
install_gun
plugin_client_name="gun-client"
fi
}

Expand Down
26 changes: 26 additions & 0 deletions templates/config/gun_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ss + gun config
ss_gun_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_and_udp",
"plugin":"gun-server",
"plugin_opts":"${gunPluginOption}"
}
EOF
}

config_ss_gun(){
if [[ ${libev_gun} = "1" ]]; then
gunPluginOption="server:${cerPath}:${keyPath}"
elif [[ ${libev_gun} = "2" ]]; then
gunPluginOption="server:cleartext"
fi
ss_gun_config
}
18 changes: 18 additions & 0 deletions templates/links/gun_link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ss + gun link
ss_gun_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 ";${clientGunPluginOpts}")
ss_link="${link_head}${cipher_pwd}${ip_port_plugin}${plugin_opts}"
}

gen_ss_gun_link(){
if [[ ${libev_gun} = "1" ]]; then
clientGunPluginOpts="client"
elif [[ ${libev_gun} = "2" ]]; then
domain="$(get_ip)"
clientGunPluginOpts="client:cleartext"
fi
ss_gun_link
}
26 changes: 26 additions & 0 deletions templates/visible/gun_visible.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ss + gun show
ss_gun_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}${clientGunPluginOpts}${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/Qv2ray/gun/releases 下载 sip003-windows-amd64 版本" >> ${HUMAN_CONFIG}
echo -e " 请解压将插件重命名为 ${plugin_client_name}.exe 并移动至 SS-Windows 客户端-安装目录的${Red}根目录${suffix}." >> ${HUMAN_CONFIG}
echo >> ${HUMAN_CONFIG}
}

ss_gun_visible(){
ss_gun_show
}
16 changes: 16 additions & 0 deletions utils/downloads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ get_plugins_version(){
get_version_by_github_api "teddysun" "${pluginName}"
elif [ ${pluginName} = "qtun" ]; then
get_version_by_github_api "shadowsocks" "${pluginName}"
elif [ ${pluginName} = "gun" ]; then
get_version_by_github_api "Qv2ray" "${pluginName}"
fi
}

Expand Down Expand Up @@ -268,5 +270,19 @@ download_plugins_file(){
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}"
elif [[ "${plugin_num}" == "12" ]]; then
local pluginName="gun"
gun_ver=$(get_plugins_version "${pluginName}")
judge_latest_version_num_is_none_and_output_error_info "${pluginName}" "${gun_ver}"

# wriet version num
if [ ! -d "$(dirname ${GUN_VERSION_FILE})" ]; then
mkdir -p $(dirname ${GUN_VERSION_FILE})
fi
echo ${gun_ver} > ${GUN_VERSION_FILE}

gun_file="gun-sip003-linux-${ARCH}"
gun_url="https://github.com/Qv2ray/gun/releases/download/${gun_ver}/gun-sip003-linux-${ARCH}"
download "${gun_file}" "${gun_url}"
fi
}
1 change: 1 addition & 0 deletions utils/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ start_services(){
sip003_way_start "gost-plugin" "gost-plugin"
sip003_way_start "xray-plugin" "xray-plugin"
sip003_way_start "qtun-server" "qtun"
sip003_way_start "gun-server" "gun"
nginx_start
}

Expand Down
1 change: 1 addition & 0 deletions utils/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ stop_services(){
kill_process "gost-plugin" "gost-plugin"
kill_process "xray-plugin" "xray-plugin"
kill_process "qtun-server" "qtun"
kill_process "gun-server" "gun"
kill_process "caddy" "caddy"
kill_process "nginx" "nginx"
}
Expand Down
9 changes: 9 additions & 0 deletions utils/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ qtun_uninstall(){
rm -f /usr/local/bin/qtun-server
}

gun_uninstall(){
ps -ef |grep -v grep | grep gun-server |awk '{print $2}' | xargs kill -9 > /dev/null 2>&1

# uninstall gun
rm -f /var/run/gun.pid
rm -f /usr/local/bin/gun-server
}

caddy_uninstall(){
if [[ -e ${CADDY_BIN_PATH} ]]; then
PID=`ps -ef |grep "caddy" |grep -v "grep" |grep -v "init.d" |grep -v "service" |grep -v "caddy_install" |awk '{print $2}'`
Expand Down Expand Up @@ -270,6 +278,7 @@ uninstall_services(){
gost_plugin_uninstall
xray_plugin_uninstall
qtun_uninstall
gun_uninstall
caddy_uninstall
nginx_uninstall
ipcalc_uninstall
Expand Down
Loading

0 comments on commit ee4f969

Please sign in to comment.