From 5a7cc6c1b2088c39f067c517886561196effed1b Mon Sep 17 00:00:00 2001 From: Misaka No <96560028+misakano7545@users.noreply.github.com> Date: Fri, 27 May 2022 00:33:31 +0800 Subject: [PATCH] Optimize script (#401) --- install.sh | 57 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/install.sh b/install.sh index e982d3c..7f2a500 100644 --- a/install.sh +++ b/install.sh @@ -91,12 +91,12 @@ function system_check() { fi print_ok "当前系统为 Centos ${VERSION_ID} ${VERSION}" INS="yum install -y" - wget -N -P /etc/yum.repos.d/ https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/basic/nginx.repo + wget -N -P /etc/yum.repos.d/ https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/basic/nginx.repo elif [[ "${ID}" == "ol" ]]; then print_ok "当前系统为 Oracle Linux ${VERSION_ID} ${VERSION}" INS="yum install -y" compatible_nginx_conf="yes" - wget -N -P /etc/yum.repos.d/ https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/basic/nginx.repo + wget -N -P /etc/yum.repos.d/ https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/basic/nginx.repo elif [[ "${ID}" == "debian" && ${VERSION_ID} -ge 9 ]]; then if [[ ${VERSION_ID} -ge 10 ]]; then compatible_nginx_conf="no" @@ -213,7 +213,7 @@ function dependency_install() { ${INS} jq if ! command -v jq; then - wget -P /usr/bin https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/binary/jq && chmod +x /usr/bin/jq + wget -P /usr/bin https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/binary/jq && chmod +x /usr/bin/jq judge "安装 jq" fi @@ -234,20 +234,37 @@ function basic_optimization() { setenforce 0 fi } + function domain_check() { read -rp "请输入你的域名信息(eg: www.wulabing.com):" domain - domain_ip=$(ping "${domain}" -c 1 | sed '1{s/[^(]*(//;s/).*//;q}') + domain_ip=$(curl -sm8 ipget.net/?ip="${domain}") print_ok "正在获取 IP 地址信息,请耐心等待" - local_ip=$(curl -4L api64.ipify.org) + wgcfv4_status=$(curl -s4m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2) + wgcfv6_status=$(curl -s6m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2) + if [[ ${wgcfv4_status} =~ "on"|"plus" ]] || [[ ${wgcfv6_status} =~ "on"|"plus" ]]; then + # 关闭wgcf-warp,以防误判VPS IP情况 + wg-quick down wgcf >/dev/null 2>&1 + fi + local_ipv4=$(curl -s4m8 https://ip.gs) + local_ipv6=$(curl -s6m8 https://ip.gs) + if [[ -z ${local_ipv4} && -n ${local_ipv6} ]]; then + # 纯IPv6 VPS,自动添加DNS64服务器以备acme.sh申请证书使用 + echo -e nameserver 2a01:4f8:c2c:123f::1 > /etc/resolv.conf + judge "添加DNS64服务器" + fi echo -e "域名通过 DNS 解析的 IP 地址:${domain_ip}" - echo -e "本机公网 IP 地址: ${local_ip}" + echo -e "本机公网 IPv4 地址: ${local_ipv4}" + echo -e "本机公网 IPv6 地址: ${local_ipv6}" sleep 2 - if [[ ${domain_ip} == "${local_ip}" ]]; then - print_ok "域名通过 DNS 解析的 IP 地址与 本机 IP 地址匹配" + if [[ ${domain_ip} == "${local_ipv4}" ]]; then + print_ok "域名通过 DNS 解析的 IP 地址与 本机 IPv4 地址匹配" + sleep 2 + elif [[ ${domain_ip} == "${local_ipv6}" ]]; then + print_ok "域名通过 DNS 解析的 IP 地址与 本机 IPv6 地址匹配" sleep 2 else - print_error "请确保域名添加了正确的 A 记录,否则将无法正常使用 xray" - print_error "域名通过 DNS 解析的 IP 地址与 本机 IP 地址不匹配,是否继续安装?(y/n)" && read -r install + print_error "请确保域名添加了正确的 A / AAAA 记录,否则将无法正常使用 xray" + print_error "域名通过 DNS 解析的 IP 地址与 本机 IPv4 / IPv6 地址不匹配,是否继续安装?(y/n)" && read -r install case $install in [yY][eE][sS] | [yY]) print_ok "继续安装" @@ -276,13 +293,13 @@ function port_exist_check() { fi } function update_sh() { - ol_version=$(curl -L -s https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/install.sh | grep "shell_version=" | head -1 | awk -F '=|"' '{print $3}') + ol_version=$(curl -L -s https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/install.sh | grep "shell_version=" | head -1 | awk -F '=|"' '{print $3}') if [[ "$shell_version" != "$(echo -e "$shell_version\n$ol_version" | sort -rV | head -1)" ]]; then print_ok "存在新版本,是否更新 [Y/N]?" read -r update_confirm case $update_confirm in [yY][eE][sS] | [yY]) - wget -N --no-check-certificate https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/install.sh + wget -N --no-check-certificate https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/install.sh print_ok "更新完成" print_ok "您可以通过 bash $0 执行本程序" exit 0 @@ -348,7 +365,7 @@ function modify_port() { function configure_nginx_temp(){ nginx_conf="/etc/nginx/conf.d/${domain}.conf" cd /etc/nginx/conf.d/ && rm -f ${domain}.conf - wget -O ${domain}.conf https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/config/web_temp.conf + wget -O ${domain}.conf https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/config/web_temp.conf sed -i "s/xxx/${domain}/g" ${nginx_conf} } @@ -356,9 +373,9 @@ function configure_nginx() { nginx_conf="/etc/nginx/conf.d/${domain}.conf" cd /etc/nginx/conf.d/ && rm -f ${domain}.conf if [[ $compatible_nginx_conf == "yes" ]]; then - wget -O ${domain}.conf https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/config/web_compatible.conf + wget -O ${domain}.conf https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/config/web_compatible.conf elif [[ $compatible_nginx_conf == "no" ]]; then - wget -O ${domain}.conf https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/config/web.conf + wget -O ${domain}.conf https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/config/web.conf fi sed -i "s/xxx/${domain}/g" ${nginx_conf} modify_port @@ -375,7 +392,7 @@ function modify_inbound_port() { } function configure_xray_ws() { - cd /usr/local/etc/xray && rm -f config.json && wget -O config.json https://raw.githubusercontent.com/wulabing/Xray_onekey/${github_branch}/config/xray_tls_ws.json + cd /usr/local/etc/xray && rm -f config.json && wget -O config.json https://raw.githubusercontents.com/wulabing/Xray_onekey/${github_branch}/config/xray_tls_ws.json modify_UUID modify_ws modify_inbound_port @@ -415,10 +432,12 @@ function acme() { if "$HOME"/.acme.sh/acme.sh --installcert -d "${domain}" --fullchainpath /ssl/xray.crt --keypath /ssl/xray.key --reloadcmd "systemctl restart xray" --reloadcmd "systemctl restart nginx" --ecc --force; then print_ok "SSL 证书配置成功" sleep 2 + wg-quick up wgcf >/dev/null 2>&1 fi else print_error "SSL 证书生成失败" rm -rf "$HOME/.acme.sh/${domain}_ecc" + wg-quick up wgcf >/dev/null 2>&1 exit 1 fi @@ -461,7 +480,7 @@ function generate_certificate() { signedcert=$(xray tls cert -domain="$local_ip" -name="$local_ip" -org="$local_ip" -expire=87600h) echo $signedcert | jq '.certificate[]' | sed 's/\"//g' | tee $cert_dir/self_signed_cert.pem echo $signedcert | jq '.key[]' | sed 's/\"//g' >$cert_dir/self_signed_key.pem - openssl x509 -in $cert_dir/self_signed_cert.pem -noout || 'print_error "生成自签名证书失败" && exit 1' + openssl x509 -in $cert_dir/self_signed_cert.pem -noout || print_error "生成自签名证书失败" && exit 1 print_ok "生成自签名证书成功" chown nobody.$cert_group $cert_dir/self_signed_cert.pem chown nobody.$cert_group $cert_dir/self_signed_key.pem @@ -470,7 +489,7 @@ function generate_certificate() { function configure_web() { rm -rf /www/xray_web mkdir -p /www/xray_web - wget -O web.tar.gz https://raw.githubusercontent.com/wulabing/Xray_onekey/main/basic/web.tar.gz + wget -O web.tar.gz https://raw.githubusercontents.com/wulabing/Xray_onekey/main/basic/web.tar.gz tar xzf web.tar.gz -C /www/xray_web judge "站点伪装" rm -f web.tar.gz @@ -563,7 +582,7 @@ function show_error_log() { function bbr_boost_sh() { [ -f "tcp.sh" ] && rm -rf ./tcp.sh - wget -N --no-check-certificate "https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh + wget -N --no-check-certificate "https://raw.githubusercontents.com/ylx2016/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh } function mtproxy_sh() {