fix error with "shellcheck"

pull/190/head
xiagw 2020-02-25 22:14:08 +08:00
parent 9a17d88fd2
commit a0c6740d1f
No known key found for this signature in database
GPG Key ID: AA79D99901C34E05
1 changed files with 352 additions and 370 deletions

View File

@ -2,7 +2,10 @@
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH export PATH
cd $(cd "$(dirname "$0")"; pwd) cd "$(
cd "$(dirname "$0")" || exit
pwd
)" || exit
#==================================================== #====================================================
# System Request:Debian 9+/Ubuntu 18.04+/Centos 7+ # System Request:Debian 9+/Ubuntu 18.04+/Centos 7+
# Author: wulabing # Author: wulabing
@ -15,13 +18,13 @@ cd $(cd "$(dirname "$0")"; pwd)
#fonts color #fonts color
Green="\033[32m" Green="\033[32m"
Red="\033[31m" Red="\033[31m"
Yellow="\033[33m" # Yellow="\033[33m"
GreenBG="\033[42;37m" GreenBG="\033[42;37m"
RedBG="\033[41;37m" RedBG="\033[41;37m"
Font="\033[0m" Font="\033[0m"
#notification information #notification information
Info="${Green}[信息]${Font}" # Info="${Green}[信息]${Font}"
OK="${Green}[OK]${Font}" OK="${Green}[OK]${Font}"
Error="${Red}[错误]${Font}" Error="${Red}[错误]${Font}"
@ -50,29 +53,29 @@ nginx_version="1.16.1"
openssl_version="1.1.1d" openssl_version="1.1.1d"
jemalloc_version="5.2.1" jemalloc_version="5.2.1"
old_config_status="off" old_config_status="off"
v2ray_plugin_version="$(wget -qO- "https://github.com/shadowsocks/v2ray-plugin/tags" |grep -E "/shadowsocks/v2ray-plugin/releases/tag/" |head -1|sed -r 's/.*tag\/v(.+)\">.*/\1/')" # v2ray_plugin_version="$(wget -qO- "https://github.com/shadowsocks/v2ray-plugin/tags" | grep -E "/shadowsocks/v2ray-plugin/releases/tag/" | head -1 | sed -r 's/.*tag\/v(.+)\">.*/\1/')"
#移动旧版本配置信息 对小于 1.1.0 版本适配 #移动旧版本配置信息 对小于 1.1.0 版本适配
[[ -f "/etc/v2ray/vmess_qr.json" ]] && mv /etc/v2ray/vmess_qr.json $v2ray_qr_config_file [[ -f "/etc/v2ray/vmess_qr.json" ]] && mv /etc/v2ray/vmess_qr.json $v2ray_qr_config_file
#生成伪装路径 #生成伪装路径
camouflage="/`cat /dev/urandom | head -n 10 | md5sum | head -c 8`/" camouflage="/$(head -n 10 /dev/urandom | md5sum | head -c 8)/"
source /etc/os-release source '/etc/os-release'
#从VERSION中提取发行版系统的英文名称为了在debian/ubuntu下添加相对应的Nginx apt源 #从VERSION中提取发行版系统的英文名称为了在debian/ubuntu下添加相对应的Nginx apt源
VERSION=`echo ${VERSION} | awk -F "[()]" '{print $2}'` VERSION=$(echo "${VERSION}" | awk -F "[()]" '{print $2}')
check_system(){ check_system() {
if [[ "${ID}" == "centos" && ${VERSION_ID} -ge 7 ]];then if [[ "${ID}" == "centos" && ${VERSION_ID} -ge 7 ]]; then
echo -e "${OK} ${GreenBG} 当前系统为 Centos ${VERSION_ID} ${VERSION} ${Font}" echo -e "${OK} ${GreenBG} 当前系统为 Centos ${VERSION_ID} ${VERSION} ${Font}"
INS="yum" INS="yum"
elif [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]];then elif [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]]; then
echo -e "${OK} ${GreenBG} 当前系统为 Debian ${VERSION_ID} ${VERSION} ${Font}" echo -e "${OK} ${GreenBG} 当前系统为 Debian ${VERSION_ID} ${VERSION} ${Font}"
INS="apt" INS="apt"
$INS update $INS update
## 添加 Nginx apt源 ## 添加 Nginx apt源
elif [[ "${ID}" == "ubuntu" && `echo "${VERSION_ID}" | cut -d '.' -f1` -ge 16 ]];then elif [[ "${ID}" == "ubuntu" && $(echo "${VERSION_ID}" | cut -d '.' -f1) -ge 16 ]]; then
echo -e "${OK} ${GreenBG} 当前系统为 Ubuntu ${VERSION_ID} ${UBUNTU_CODENAME} ${Font}" echo -e "${OK} ${GreenBG} 当前系统为 Ubuntu ${VERSION_ID} ${UBUNTU_CODENAME} ${Font}"
INS="apt" INS="apt"
$INS update $INS update
@ -92,17 +95,17 @@ check_system(){
echo -e "${OK} ${GreenBG} ufw 已关闭 ${Font}" echo -e "${OK} ${GreenBG} ufw 已关闭 ${Font}"
} }
is_root(){ is_root() {
if [ `id -u` == 0 ] if [ 0 == $UID ]; then
then echo -e "${OK} ${GreenBG} 当前用户是root用户进入安装流程 ${Font}" echo -e "${OK} ${GreenBG} 当前用户是root用户进入安装流程 ${Font}"
sleep 3 sleep 3
else else
echo -e "${Error} ${RedBG} 当前用户不是root用户请切换到root用户后重新执行脚本 ${Font}" echo -e "${Error} ${RedBG} 当前用户不是root用户请切换到root用户后重新执行脚本 ${Font}"
exit 1 exit 1
fi fi
} }
judge(){ judge() {
if [[ $? -eq 0 ]];then if [[ 0 -eq $? ]]; then
echo -e "${OK} ${GreenBG} $1 完成 ${Font}" echo -e "${OK} ${GreenBG} $1 完成 ${Font}"
sleep 1 sleep 1
else else
@ -110,13 +113,13 @@ judge(){
exit 1 exit 1
fi fi
} }
chrony_install(){ chrony_install() {
${INS} -y install chrony ${INS} -y install chrony
judge "安装 chrony 时间同步服务 " judge "安装 chrony 时间同步服务 "
timedatectl set-ntp true timedatectl set-ntp true
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
systemctl enable chronyd && systemctl restart chronyd systemctl enable chronyd && systemctl restart chronyd
else else
systemctl enable chrony && systemctl restart chrony systemctl enable chrony && systemctl restart chrony
@ -132,10 +135,10 @@ chrony_install(){
chronyc sourcestats -v chronyc sourcestats -v
chronyc tracking -v chronyc tracking -v
date date
read -p "请确认时间是否准确,误差范围±3分钟(Y/N): " chrony_install read -rp "请确认时间是否准确,误差范围±3分钟(Y/N): " chrony_install
[[ -z ${chrony_install} ]] && chrony_install="Y" [[ -z ${chrony_install} ]] && chrony_install="Y"
case $chrony_install in case $chrony_install in
[yY][eE][sS]|[yY]) [yY][eE][sS] | [yY])
echo -e "${GreenBG} 继续安装 ${Font}" echo -e "${GreenBG} 继续安装 ${Font}"
sleep 2 sleep 2
;; ;;
@ -146,17 +149,17 @@ chrony_install(){
esac esac
} }
dependency_install(){ dependency_install() {
${INS} install wget git lsof -y ${INS} install wget git lsof -y
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
${INS} -y install crontabs ${INS} -y install crontabs
else else
${INS} -y install cron ${INS} -y install cron
fi fi
judge "安装 crontab" judge "安装 crontab"
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
touch /var/spool/cron/root && chmod 600 /var/spool/cron/root touch /var/spool/cron/root && chmod 600 /var/spool/cron/root
systemctl start crond && systemctl enable crond systemctl start crond && systemctl enable crond
else else
@ -166,8 +169,6 @@ dependency_install(){
fi fi
judge "crontab 自启动配置 " judge "crontab 自启动配置 "
${INS} -y install bc ${INS} -y install bc
judge "安装 bc" judge "安装 bc"
@ -180,98 +181,92 @@ dependency_install(){
${INS} -y install curl ${INS} -y install curl
judge "安装 crul" judge "安装 crul"
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
${INS} -y groupinstall "Development tools" ${INS} -y groupinstall "Development tools"
else else
${INS} -y install build-essential ${INS} -y install build-essential
fi fi
judge "编译工具包 安装" judge "编译工具包 安装"
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
${INS} -y install pcre pcre-devel zlib-devel epel-release ${INS} -y install pcre pcre-devel zlib-devel epel-release
else else
${INS} -y install libpcre3 libpcre3-dev zlib1g-dev dbus ${INS} -y install libpcre3 libpcre3-dev zlib1g-dev dbus
fi fi
# ${INS} -y install rng-tools # ${INS} -y install rng-tools
# judge "rng-tools 安装" # judge "rng-tools 安装"
${INS} -y install haveged ${INS} -y install haveged
# judge "haveged 安装" # judge "haveged 安装"
# sed -i -r '/^HRNGDEVICE/d;/#HRNGDEVICE=\/dev\/null/a HRNGDEVICE=/dev/urandom' /etc/default/rng-tools # sed -i -r '/^HRNGDEVICE/d;/#HRNGDEVICE=\/dev\/null/a HRNGDEVICE=/dev/urandom' /etc/default/rng-tools
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
# systemctl start rngd && systemctl enable rngd # systemctl start rngd && systemctl enable rngd
# judge "rng-tools 启动" # judge "rng-tools 启动"
systemctl start haveged && systemctl enable haveged systemctl start haveged && systemctl enable haveged
# judge "haveged 启动" # judge "haveged 启动"
else else
# systemctl start rng-tools && systemctl enable rng-tools # systemctl start rng-tools && systemctl enable rng-tools
# judge "rng-tools 启动" # judge "rng-tools 启动"
systemctl start haveged && systemctl enable haveged systemctl start haveged && systemctl enable haveged
# judge "haveged 启动" # judge "haveged 启动"
fi fi
} }
basic_optimization(){ basic_optimization() {
# 最大文件打开数 # 最大文件打开数
sed -i '/^\*\ *soft\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf sed -i '/^\*\ *soft\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
sed -i '/^\*\ *hard\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf sed -i '/^\*\ *hard\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
echo '* soft nofile 65536' >> /etc/security/limits.conf echo '* soft nofile 65536' >>/etc/security/limits.conf
echo '* hard nofile 65536' >> /etc/security/limits.conf echo '* hard nofile 65536' >>/etc/security/limits.conf
# 关闭 Selinux # 关闭 Selinux
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0 setenforce 0
fi fi
} }
port_alterid_set(){ port_alterid_set() {
if [[ "on" != "$old_config_status" ]] if [[ "on" != "$old_config_status" ]]; then
then read -rp "请输入连接端口default:443:" port
read -p "请输入连接端口default:443:" port
[[ -z ${port} ]] && port="443" [[ -z ${port} ]] && port="443"
read -p "请输入alterIDdefault:2 仅允许填数字):" alterID read -rp "请输入alterIDdefault:2 仅允许填数字):" alterID
[[ -z ${alterID} ]] && alterID="2" [[ -z ${alterID} ]] && alterID="2"
fi fi
} }
modify_path(){ modify_path() {
if [[ "on" == "$old_config_status" ]] if [[ "on" == "$old_config_status" ]]; then
then camouflage="$(grep '\"path\"' $v2ray_qr_config_file | awk -F '"' '{print $4}')"
camouflage="$(cat $v2ray_qr_config_file | grep '\"path\"' | awk -F '"' '{print $4}')"
fi fi
sed -i "/\"path\"/c \\\t \"path\":\"${camouflage}\"" ${v2ray_conf} sed -i "/\"path\"/c \\\t \"path\":\"${camouflage}\"" ${v2ray_conf}
judge "V2ray 伪装路径 修改" judge "V2ray 伪装路径 修改"
} }
modify_alterid(){ modify_alterid() {
if [[ "on" == "$old_config_status" ]] if [[ "on" == "$old_config_status" ]]; then
then alterID="$(grep '\"aid\"' $v2ray_qr_config_file | awk -F '"' '{print $4}')"
alterID="$(cat $v2ray_qr_config_file | grep '\"aid\"' | awk -F '"' '{print $4}')"
fi fi
sed -i "/\"alterId\"/c \\\t \"alterId\":${alterID}" ${v2ray_conf} sed -i "/\"alterId\"/c \\\t \"alterId\":${alterID}" ${v2ray_conf}
judge "V2ray alterid 修改" judge "V2ray alterid 修改"
[ -f ${v2ray_qr_config_file} ] && sed -i "/\"aid\"/c \\ \"aid\": \"${alterID}\"," ${v2ray_qr_config_file} [ -f ${v2ray_qr_config_file} ] && sed -i "/\"aid\"/c \\ \"aid\": \"${alterID}\"," ${v2ray_qr_config_file}
echo -e "${OK} ${GreenBG} alterID:${alterID} ${Font}" echo -e "${OK} ${GreenBG} alterID:${alterID} ${Font}"
} }
modify_inbound_port(){ modify_inbound_port() {
if [[ "on" == "$old_config_status" ]] if [[ "on" == "$old_config_status" ]]; then
then
port="$(info_extraction '\"port\"')" port="$(info_extraction '\"port\"')"
fi fi
if [[ "$shell_mode" != "h2" ]] if [[ "$shell_mode" != "h2" ]]; then
then PORT=$((RANDOM + 10000))
let PORT=$RANDOM+10000
sed -i "/\"port\"/c \ \"port\":${PORT}," ${v2ray_conf} sed -i "/\"port\"/c \ \"port\":${PORT}," ${v2ray_conf}
else else
sed -i "/\"port\"/c \ \"port\":${port}," ${v2ray_conf} sed -i "/\"port\"/c \ \"port\":${port}," ${v2ray_conf}
fi fi
judge "V2ray inbound_port 修改" judge "V2ray inbound_port 修改"
} }
modify_UUID(){ modify_UUID() {
[ -z $UUID ] && UUID=$(cat /proc/sys/kernel/random/uuid) [ -z "$UUID" ] && UUID=$(cat /proc/sys/kernel/random/uuid)
if [[ "on" == "$old_config_status" ]] if [[ "on" == "$old_config_status" ]]; then
then
UUID="$(info_extraction '\"id\"')" UUID="$(info_extraction '\"id\"')"
fi fi
sed -i "/\"id\"/c \\\t \"id\":\"${UUID}\"," ${v2ray_conf} sed -i "/\"id\"/c \\\t \"id\":\"${UUID}\"," ${v2ray_conf}
@ -279,9 +274,8 @@ modify_UUID(){
[ -f ${v2ray_qr_config_file} ] && sed -i "/\"id\"/c \\ \"id\": \"${UUID}\"," ${v2ray_qr_config_file} [ -f ${v2ray_qr_config_file} ] && sed -i "/\"id\"/c \\ \"id\": \"${UUID}\"," ${v2ray_qr_config_file}
echo -e "${OK} ${GreenBG} UUID:${UUID} ${Font}" echo -e "${OK} ${GreenBG} UUID:${UUID} ${Font}"
} }
modify_nginx_port(){ modify_nginx_port() {
if [[ "on" == "$old_config_status" ]] if [[ "on" == "$old_config_status" ]]; then
then
port="$(info_extraction '\"port\"')" port="$(info_extraction '\"port\"')"
fi fi
sed -i "/ssl http2;$/c \\\tlisten ${port} ssl http2;" ${nginx_conf} sed -i "/ssl http2;$/c \\\tlisten ${port} ssl http2;" ${nginx_conf}
@ -289,32 +283,35 @@ modify_nginx_port(){
[ -f ${v2ray_qr_config_file} ] && sed -i "/\"port\"/c \\ \"port\": \"${port}\"," ${v2ray_qr_config_file} [ -f ${v2ray_qr_config_file} ] && sed -i "/\"port\"/c \\ \"port\": \"${port}\"," ${v2ray_qr_config_file}
echo -e "${OK} ${GreenBG} 端口号:${port} ${Font}" echo -e "${OK} ${GreenBG} 端口号:${port} ${Font}"
} }
modify_nginx_other(){ modify_nginx_other() {
sed -i "/server_name/c \\\tserver_name ${domain};" ${nginx_conf} sed -i "/server_name/c \\\tserver_name ${domain};" ${nginx_conf}
sed -i "/location/c \\\tlocation ${camouflage}" ${nginx_conf} sed -i "/location/c \\\tlocation ${camouflage}" ${nginx_conf}
sed -i "/proxy_pass/c \\\tproxy_pass http://127.0.0.1:${PORT};" ${nginx_conf} sed -i "/proxy_pass/c \\\tproxy_pass http://127.0.0.1:${PORT};" ${nginx_conf}
sed -i "/return/c \\\treturn 301 https://${domain}\$request_uri;" ${nginx_conf} sed -i "/return/c \\\treturn 301 https://${domain}\$request_uri;" ${nginx_conf}
#sed -i "27i \\\tproxy_intercept_errors on;" ${nginx_dir}/conf/nginx.conf #sed -i "27i \\\tproxy_intercept_errors on;" ${nginx_dir}/conf/nginx.conf
} }
web_camouflage(){ web_camouflage() {
##请注意 这里和LNMP脚本的默认路径冲突千万不要在安装了LNMP的环境下使用本脚本否则后果自负 ##请注意 这里和LNMP脚本的默认路径冲突千万不要在安装了LNMP的环境下使用本脚本否则后果自负
rm -rf /home/wwwroot && mkdir -p /home/wwwroot && cd /home/wwwroot rm -rf /home/wwwroot
mkdir -p /home/wwwroot
cd /home/wwwroot || exit
git clone https://github.com/wulabing/3DCEList.git git clone https://github.com/wulabing/3DCEList.git
judge "web 站点伪装" judge "web 站点伪装"
} }
v2ray_install(){ v2ray_install() {
if [[ -d /root/v2ray ]];then if [[ -d /root/v2ray ]]; then
rm -rf /root/v2ray rm -rf /root/v2ray
fi fi
if [[ -d /etc/v2ray ]];then if [[ -d /etc/v2ray ]]; then
rm -rf /etc/v2ray rm -rf /etc/v2ray
fi fi
mkdir -p /root/v2ray && cd /root/v2ray mkdir -p /root/v2ray
cd /root/v2ray || exit
wget -N --no-check-certificate https://install.direct/go.sh wget -N --no-check-certificate https://install.direct/go.sh
## wget http://install.direct/go.sh ## wget http://install.direct/go.sh
if [[ -f go.sh ]];then if [[ -f go.sh ]]; then
rm -rf $v2ray_systemd_file rm -rf $v2ray_systemd_file
systemctl daemon-reload systemctl daemon-reload
bash go.sh --force bash go.sh --force
@ -326,22 +323,21 @@ v2ray_install(){
# 清除临时文件 # 清除临时文件
rm -rf /root/v2ray rm -rf /root/v2ray
} }
nginx_exist_check(){ nginx_exist_check() {
if [[ -f "/etc/nginx/sbin/nginx" ]];then if [[ -f "/etc/nginx/sbin/nginx" ]]; then
echo -e "${OK} ${GreenBG} Nginx已存在跳过编译安装过程 ${Font}" echo -e "${OK} ${GreenBG} Nginx已存在跳过编译安装过程 ${Font}"
sleep 2 sleep 2
elif [[ -d "/usr/local/nginx/" ]] elif [[ -d "/usr/local/nginx/" ]]; then
then
echo -e "${OK} ${GreenBG} 检测到其他套件安装的Nginx继续安装会造成冲突请处理后安装${Font}" echo -e "${OK} ${GreenBG} 检测到其他套件安装的Nginx继续安装会造成冲突请处理后安装${Font}"
exit 1 exit 1
else else
nginx_install nginx_install
fi fi
} }
nginx_install(){ nginx_install() {
# if [[ -d "/etc/nginx" ]];then # if [[ -d "/etc/nginx" ]];then
# rm -rf /etc/nginx # rm -rf /etc/nginx
# fi # fi
wget -nc --no-check-certificate http://nginx.org/download/nginx-${nginx_version}.tar.gz -P ${nginx_openssl_src} wget -nc --no-check-certificate http://nginx.org/download/nginx-${nginx_version}.tar.gz -P ${nginx_openssl_src}
judge "Nginx 下载" judge "Nginx 下载"
@ -350,7 +346,7 @@ nginx_install(){
wget -nc --no-check-certificate https://github.com/jemalloc/jemalloc/releases/download/${jemalloc_version}/jemalloc-${jemalloc_version}.tar.bz2 -P ${nginx_openssl_src} wget -nc --no-check-certificate https://github.com/jemalloc/jemalloc/releases/download/${jemalloc_version}/jemalloc-${jemalloc_version}.tar.bz2 -P ${nginx_openssl_src}
judge "jemalloc 下载" judge "jemalloc 下载"
cd ${nginx_openssl_src} cd ${nginx_openssl_src} || exit
[[ -d nginx-"$nginx_version" ]] && rm -rf nginx-"$nginx_version" [[ -d nginx-"$nginx_version" ]] && rm -rf nginx-"$nginx_version"
tar -zxvf nginx-"$nginx_version".tar.gz tar -zxvf nginx-"$nginx_version".tar.gz
@ -363,22 +359,21 @@ nginx_install(){
[[ -d "$nginx_dir" ]] && rm -rf ${nginx_dir} [[ -d "$nginx_dir" ]] && rm -rf ${nginx_dir}
echo -e "${OK} ${GreenBG} 即将开始编译安装 jemalloc ${Font}" echo -e "${OK} ${GreenBG} 即将开始编译安装 jemalloc ${Font}"
sleep 2 sleep 2
cd jemalloc-${jemalloc_version} cd jemalloc-${jemalloc_version} || exit
./configure ./configure
judge "编译检查" judge "编译检查"
make && make install make && make install
judge "jemalloc 编译安装" judge "jemalloc 编译安装"
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf echo '/usr/local/lib' >/etc/ld.so.conf.d/local.conf
ldconfig ldconfig
echo -e "${OK} ${GreenBG} 即将开始编译安装 Nginx, 过程稍久,请耐心等待 ${Font}" echo -e "${OK} ${GreenBG} 即将开始编译安装 Nginx, 过程稍久,请耐心等待 ${Font}"
sleep 4 sleep 4
cd ../nginx-${nginx_version} cd ../nginx-${nginx_version} || exit
./configure --prefix="${nginx_dir}" \ ./configure --prefix="${nginx_dir}" \
--with-http_ssl_module \ --with-http_ssl_module \
@ -403,8 +398,6 @@ nginx_install(){
sed -i 's/ worker_connections 1024;/ worker_connections 4096;/' ${nginx_dir}/conf/nginx.conf sed -i 's/ worker_connections 1024;/ worker_connections 4096;/' ${nginx_dir}/conf/nginx.conf
sed -i '$i include conf.d/*.conf;' ${nginx_dir}/conf/nginx.conf sed -i '$i include conf.d/*.conf;' ${nginx_dir}/conf/nginx.conf
# 删除临时文件 # 删除临时文件
rm -rf ../nginx-"${nginx_version}" rm -rf ../nginx-"${nginx_version}"
rm -rf ../openssl-"${openssl_version}" rm -rf ../openssl-"${openssl_version}"
@ -414,8 +407,8 @@ nginx_install(){
# 添加配置文件夹,适配旧版脚本 # 添加配置文件夹,适配旧版脚本
mkdir ${nginx_dir}/conf/conf.d mkdir ${nginx_dir}/conf/conf.d
} }
ssl_install(){ ssl_install() {
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
${INS} install socat nc -y ${INS} install socat nc -y
else else
${INS} install socat netcat -y ${INS} install socat netcat -y
@ -425,22 +418,22 @@ ssl_install(){
curl https://get.acme.sh | sh curl https://get.acme.sh | sh
judge "安装 SSL 证书生成脚本" judge "安装 SSL 证书生成脚本"
} }
domain_check(){ domain_check() {
read -p "请输入你的域名信息(eg:www.wulabing.com):" domain read -rp "请输入你的域名信息(eg:www.wulabing.com):" domain
domain_ip=`ping ${domain} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'` domain_ip=$(ping "${domain}" -c 1 | sed '1{s/[^(]*(//;s/).*//;q}')
echo -e "${OK} ${GreenBG} 正在获取 公网ip 信息,请耐心等待 ${Font}" echo -e "${OK} ${GreenBG} 正在获取 公网ip 信息,请耐心等待 ${Font}"
local_ip=`curl -4 ip.sb` local_ip=$(curl -4 ip.sb)
echo -e "域名dns解析IP${domain_ip}" echo -e "域名dns解析IP${domain_ip}"
echo -e "本机IP: ${local_ip}" echo -e "本机IP: ${local_ip}"
sleep 2 sleep 2
if [[ $(echo ${local_ip}|tr '.' '+'|bc) -eq $(echo ${domain_ip}|tr '.' '+'|bc) ]];then if [[ $(echo "${local_ip}" | tr '.' '+' | bc) -eq $(echo "${domain_ip}" | tr '.' '+' | bc) ]]; then
echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}" echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}"
sleep 2 sleep 2
else else
echo -e "${Error} ${RedBG} 请确保域名添加了正确的 A 记录,否则将无法正常使用 V2ray ${Font}" echo -e "${Error} ${RedBG} 请确保域名添加了正确的 A 记录,否则将无法正常使用 V2ray ${Font}"
echo -e "${Error} ${RedBG} 域名dns解析IP 与 本机IP 不匹配 是否继续安装y/n${Font}" && read install echo -e "${Error} ${RedBG} 域名dns解析IP 与 本机IP 不匹配 是否继续安装y/n${Font}" && read -r install
case $install in case $install in
[yY][eE][sS]|[yY]) [yY][eE][sS] | [yY])
echo -e "${GreenBG} 继续安装 ${Font}" echo -e "${GreenBG} 继续安装 ${Font}"
sleep 2 sleep 2
;; ;;
@ -452,8 +445,8 @@ domain_check(){
fi fi
} }
port_exist_check(){ port_exist_check() {
if [[ 0 -eq `lsof -i:"$1" | grep -i "listen" | wc -l` ]];then if [[ 0 -eq $(lsof -i:"$1" | grep -i -c "listen") ]]; then
echo -e "${OK} ${GreenBG} $1 端口未被占用 ${Font}" echo -e "${OK} ${GreenBG} $1 端口未被占用 ${Font}"
sleep 1 sleep 1
else else
@ -461,14 +454,13 @@ port_exist_check(){
lsof -i:"$1" lsof -i:"$1"
echo -e "${OK} ${GreenBG} 5s 后将尝试自动 kill 占用进程 ${Font}" echo -e "${OK} ${GreenBG} 5s 后将尝试自动 kill 占用进程 ${Font}"
sleep 5 sleep 5
lsof -i:"$1" | awk '{print $2}'| grep -v "PID" | xargs kill -9 lsof -i:"$1" | awk '{print $2}' | grep -v "PID" | xargs kill -9
echo -e "${OK} ${GreenBG} kill 完成 ${Font}" echo -e "${OK} ${GreenBG} kill 完成 ${Font}"
sleep 1 sleep 1
fi fi
} }
acme(){ acme() {
$HOME/.acme.sh/acme.sh --issue -d ${domain} --standalone -k ec-256 --force --test if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone -k ec-256 --force --test; then
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} SSL 证书测试签发成功,开始正式签发 ${Font}" echo -e "${OK} ${GreenBG} SSL 证书测试签发成功,开始正式签发 ${Font}"
rm -rf "$HOME/.acme.sh/${domain}_ecc" rm -rf "$HOME/.acme.sh/${domain}_ecc"
sleep 2 sleep 2
@ -478,13 +470,11 @@ acme(){
exit 1 exit 1
fi fi
$HOME/.acme.sh/acme.sh --issue -d ${domain} --standalone -k ec-256 --force if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone -k ec-256 --force; then
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} SSL 证书生成成功 ${Font}" echo -e "${OK} ${GreenBG} SSL 证书生成成功 ${Font}"
sleep 2 sleep 2
mkdir /data mkdir /data
$HOME/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /data/v2ray.crt --keypath /data/v2ray.key --ecc --force if "$HOME"/.acme.sh/acme.sh --installcert -d "${domain}" --fullchainpath /data/v2ray.crt --keypath /data/v2ray.key --ecc --force; then
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} 证书配置成功 ${Font}" echo -e "${OK} ${GreenBG} 证书配置成功 ${Font}"
sleep 2 sleep 2
fi fi
@ -494,29 +484,28 @@ acme(){
exit 1 exit 1
fi fi
} }
v2ray_conf_add_tls(){ v2ray_conf_add_tls() {
cd /etc/v2ray cd /etc/v2ray || exit
wget --no-check-certificate https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/tls/config.json -O config.json wget --no-check-certificate https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/tls/config.json -O config.json
modify_path modify_path
modify_alterid modify_alterid
modify_inbound_port modify_inbound_port
modify_UUID modify_UUID
} }
v2ray_conf_add_h2(){ v2ray_conf_add_h2() {
cd /etc/v2ray cd /etc/v2ray || exit
wget --no-check-certificate https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/http2/config.json -O config.json wget --no-check-certificate https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/http2/config.json -O config.json
modify_path modify_path
modify_alterid modify_alterid
modify_inbound_port modify_inbound_port
modify_UUID modify_UUID
} }
old_config_exist_check(){ old_config_exist_check() {
if [[ -f $v2ray_qr_config_file ]] if [[ -f $v2ray_qr_config_file ]]; then
then
echo -e "${OK} ${GreenBG} 检测到旧配置文件,是否读取旧文件配置 [Y/N]? ${Font}" echo -e "${OK} ${GreenBG} 检测到旧配置文件,是否读取旧文件配置 [Y/N]? ${Font}"
read -r ssl_delete read -r ssl_delete
case $ssl_delete in case $ssl_delete in
[yY][eE][sS]|[yY]) [yY][eE][sS] | [yY])
echo -e "${OK} ${GreenBG} 已保留旧配置 ${Font}" echo -e "${OK} ${GreenBG} 已保留旧配置 ${Font}"
old_config_status="on" old_config_status="on"
port=$(info_extraction '\"port\"') port=$(info_extraction '\"port\"')
@ -528,9 +517,9 @@ old_config_exist_check(){
esac esac
fi fi
} }
nginx_conf_add(){ nginx_conf_add() {
touch ${nginx_conf_dir}/v2ray.conf touch ${nginx_conf_dir}/v2ray.conf
cat>${nginx_conf_dir}/v2ray.conf<<EOF cat >${nginx_conf_dir}/v2ray.conf <<EOF
server { server {
listen 443 ssl http2; listen 443 ssl http2;
ssl_certificate /data/v2ray.crt; ssl_certificate /data/v2ray.crt;
@ -560,16 +549,15 @@ nginx_conf_add(){
} }
EOF EOF
modify_nginx_port modify_nginx_port
modify_nginx_other modify_nginx_other
judge "Nginx 配置修改" judge "Nginx 配置修改"
} }
start_process_systemd(){ start_process_systemd() {
systemctl daemon-reload systemctl daemon-reload
if [[ "$shell_mode" != "h2" ]] if [[ "$shell_mode" != "h2" ]]; then
then
systemctl restart nginx systemctl restart nginx
judge "Nginx 启动" judge "Nginx 启动"
fi fi
@ -577,25 +565,23 @@ start_process_systemd(){
judge "V2ray 启动" judge "V2ray 启动"
} }
enable_process_systemd(){ enable_process_systemd() {
systemctl enable v2ray systemctl enable v2ray
judge "设置 v2ray 开机自启" judge "设置 v2ray 开机自启"
if [[ "$shell_mode" != "h2" ]] if [[ "$shell_mode" != "h2" ]]; then
then
systemctl enable nginx systemctl enable nginx
judge "设置 Nginx 开机自启" judge "设置 Nginx 开机自启"
fi fi
} }
stop_process_systemd(){ stop_process_systemd() {
if [[ "$shell_mode" != "h2" ]] if [[ "$shell_mode" != "h2" ]]; then
then
systemctl stop nginx systemctl stop nginx
fi fi
systemctl stop v2ray systemctl stop v2ray
} }
nginx_process_disabled(){ nginx_process_disabled() {
[ -f $nginx_systemd_file ] && systemctl stop nginx && systemctl disable nginx [ -f $nginx_systemd_file ] && systemctl stop nginx && systemctl disable nginx
} }
@ -611,22 +597,22 @@ nginx_process_disabled(){
# #
# judge "rc.local 配置" # judge "rc.local 配置"
#} #}
acme_cron_update(){ acme_cron_update() {
wget -N -P /usr/bin --no-check-certificate "https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/dev/ssl_update.sh" wget -N -P /usr/bin --no-check-certificate "https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/dev/ssl_update.sh"
if [[ "${ID}" == "centos" ]];then if [[ "${ID}" == "centos" ]]; then
# sed -i "/acme.sh/c 0 3 * * 0 \"/root/.acme.sh\"/acme.sh --cron --home \"/root/.acme.sh\" \ # sed -i "/acme.sh/c 0 3 * * 0 \"/root/.acme.sh\"/acme.sh --cron --home \"/root/.acme.sh\" \
# &> /dev/null" /var/spool/cron/root # &> /dev/null" /var/spool/cron/root
sed -i "/acme.sh/c 0 3 * * 0 bash ${ssl_update_file}" /var/spool/cron/root sed -i "/acme.sh/c 0 3 * * 0 bash ${ssl_update_file}" /var/spool/cron/root
else else
# sed -i "/acme.sh/c 0 3 * * 0 \"/root/.acme.sh\"/acme.sh --cron --home \"/root/.acme.sh\" \ # sed -i "/acme.sh/c 0 3 * * 0 \"/root/.acme.sh\"/acme.sh --cron --home \"/root/.acme.sh\" \
# &> /dev/null" /var/spool/cron/crontabs/root # &> /dev/null" /var/spool/cron/crontabs/root
sed -i "/acme.sh/c 0 3 * * 0 bash ${ssl_update_file}" /var/spool/cron/crontabs/root sed -i "/acme.sh/c 0 3 * * 0 bash ${ssl_update_file}" /var/spool/cron/crontabs/root
fi fi
judge "cron 计划任务更新" judge "cron 计划任务更新"
} }
vmess_qr_config_tls_ws(){ vmess_qr_config_tls_ws() {
cat > $v2ray_qr_config_file <<-EOF cat >$v2ray_qr_config_file <<-EOF
{ {
"v": "2", "v": "2",
"ps": "wulabing_${domain}", "ps": "wulabing_${domain}",
@ -643,8 +629,8 @@ vmess_qr_config_tls_ws(){
EOF EOF
} }
vmess_qr_config_h2(){ vmess_qr_config_h2() {
cat > $v2ray_qr_config_file <<-EOF cat >$v2ray_qr_config_file <<-EOF
{ {
"v": "2", "v": "2",
"ps": "wulabing_${domain}", "ps": "wulabing_${domain}",
@ -660,52 +646,56 @@ vmess_qr_config_h2(){
EOF EOF
} }
vmess_qr_link_image(){ vmess_qr_link_image() {
vmess_link="vmess://$(cat $v2ray_qr_config_file | base64 -w 0)" vmess_link="vmess://$(base64 -w 0 $v2ray_qr_config_file)"
echo -e "${Red} 二维码: ${Font}" >> ${v2ray_info_file} {
echo -n "${vmess_link}"| qrencode -o - -t utf8 >> ${v2ray_info_file} echo -e "$Red 二维码: $Font"
echo -e "${Red} URL导入链接:${vmess_link} ${Font}" >> ${v2ray_info_file} echo -n "${vmess_link}" | qrencode -o - -t utf8
echo -e "${Red} URL导入链接:${vmess_link} ${Font}"
} >>"${v2ray_info_file}"
} }
info_extraction(){ info_extraction() {
grep $1 $v2ray_qr_config_file | awk -F '"' '{print $4}' grep "$1" $v2ray_qr_config_file | awk -F '"' '{print $4}'
} }
basic_information(){ basic_information() {
echo -e "${OK} ${GreenBG} V2ray+ws+tls 安装成功" > ${v2ray_info_file} {
echo -e "${Red} V2ray 配置信息 ${Font}" >> ${v2ray_info_file} echo -e "${OK} ${GreenBG} V2ray+ws+tls 安装成功"
echo -e "${Red} 地址address:${Font} $(info_extraction '\"add\"') " >> ${v2ray_info_file} echo -e "${Red} V2ray 配置信息 ${Font}"
echo -e "${Red} 端口port${Font} $(info_extraction '\"port\"') " >> ${v2ray_info_file} echo -e "${Red} 地址address:${Font} $(info_extraction '\"add\"') "
echo -e "${Red} 用户idUUID${Font} $(info_extraction '\"id\"')" >> ${v2ray_info_file} echo -e "${Red} 端口port${Font} $(info_extraction '\"port\"') "
echo -e "${Red} 额外idalterId${Font} $(info_extraction '\"aid\"')" >> ${v2ray_info_file} echo -e "${Red} 用户idUUID${Font} $(info_extraction '\"id\"')"
echo -e "${Red} 加密方式security${Font} 自适应 " >> ${v2ray_info_file} echo -e "${Red} 额外idalterId${Font} $(info_extraction '\"aid\"')"
echo -e "${Red} 传输协议network${Font} $(info_extraction '\"net\"') " >> ${v2ray_info_file} echo -e "${Red} 加密方式security${Font} 自适应 "
echo -e "${Red} 伪装类型type${Font} none " >> ${v2ray_info_file} echo -e "${Red} 传输协议network${Font} $(info_extraction '\"net\"') "
echo -e "${Red} 路径(不要落下/${Font} $(info_extraction '\"path\"') " >> ${v2ray_info_file} echo -e "${Red} 伪装类型type${Font} none "
echo -e "${Red} 底层传输安全:${Font} tls " >> ${v2ray_info_file} echo -e "${Red} 路径(不要落下/${Font} $(info_extraction '\"path\"') "
echo -e "${Red} 底层传输安全:${Font} tls "
} >"${v2ray_info_file}"
} }
show_information(){ show_information() {
cat ${v2ray_info_file} cat "${v2ray_info_file}"
} }
ssl_judge_and_install(){ ssl_judge_and_install() {
if [[ -f "/data/v2ray.key" || -f "/data/v2ray.crt" ]];then if [[ -f "/data/v2ray.key" || -f "/data/v2ray.crt" ]]; then
echo "/data 目录下证书文件已存在" echo "/data 目录下证书文件已存在"
echo -e "${OK} ${GreenBG} 是否删除 [Y/N]? ${Font}" echo -e "${OK} ${GreenBG} 是否删除 [Y/N]? ${Font}"
read -r ssl_delete read -r ssl_delete
case $ssl_delete in case $ssl_delete in
[yY][eE][sS]|[yY]) [yY][eE][sS] | [yY])
rm -rf /data/* rm -rf /data/*
echo -e "${OK} ${GreenBG} 已删除 ${Font}" echo -e "${OK} ${GreenBG} 已删除 ${Font}"
;; ;;
*) *) ;;
;;
esac esac
fi fi
if [[ -f "/data/v2ray.key" || -f "/data/v2ray.crt" ]];then if [[ -f "/data/v2ray.key" || -f "/data/v2ray.crt" ]]; then
echo "证书文件已存在" echo "证书文件已存在"
elif [[ -f "$HOME/.acme.sh/${domain}_ecc/${domain}.key" && -f "$HOME/.acme.sh/${domain}_ecc/${domain}.cer" ]];then elif [[ -f "$HOME/.acme.sh/${domain}_ecc/${domain}.key" && -f "$HOME/.acme.sh/${domain}_ecc/${domain}.cer" ]]; then
echo "证书文件已存在" echo "证书文件已存在"
$HOME/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /data/v2ray.crt --keypath /data/v2ray.key --ecc "$HOME"/.acme.sh/acme.sh --installcert -d "${domain}" --fullchainpath /data/v2ray.crt --keypath /data/v2ray.key --ecc
judge "证书应用" judge "证书应用"
else else
ssl_install ssl_install
@ -713,8 +703,8 @@ ssl_judge_and_install(){
fi fi
} }
nginx_systemd(){ nginx_systemd() {
cat>$nginx_systemd_file<<EOF cat >$nginx_systemd_file <<EOF
[Unit] [Unit]
Description=The NGINX HTTP and reverse proxy server Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target After=syslog.target network.target remote-fs.target nss-lookup.target
@ -732,23 +722,23 @@ PrivateTmp=true
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
judge "Nginx systemd ServerFile 添加" judge "Nginx systemd ServerFile 添加"
systemctl daemon-reload systemctl daemon-reload
} }
tls_type(){ tls_type() {
if [[ -f "/etc/nginx/sbin/nginx" ]] && [[ -f "$nginx_conf" ]] && [[ "$shell_mode" == "ws" ]];then if [[ -f "/etc/nginx/sbin/nginx" ]] && [[ -f "$nginx_conf" ]] && [[ "$shell_mode" == "ws" ]]; then
echo "请选择支持的 TLS 版本default:3:" echo "请选择支持的 TLS 版本default:3:"
echo "请注意,如果你使用 Quantaumlt X / 路由器 / 旧版 Shadowrocket / 低于 4.18.1 版本的 V2ray core 请选择 兼容模式" echo "请注意,如果你使用 Quantaumlt X / 路由器 / 旧版 Shadowrocket / 低于 4.18.1 版本的 V2ray core 请选择 兼容模式"
echo "1: TLS1.1 TLS1.2 and TLS1.3(兼容模式)" echo "1: TLS1.1 TLS1.2 and TLS1.3(兼容模式)"
echo "2: TLS1.2 and TLS1.3 (兼容模式)" echo "2: TLS1.2 and TLS1.3 (兼容模式)"
echo "3: TLS1.3 only" echo "3: TLS1.3 only"
read -p "请输入:" tls_version read -rp "请输入:" tls_version
[[ -z ${tls_version} ]] && tls_version=3 [[ -z ${tls_version} ]] && tls_version=3
if [[ $tls_version == 3 ]];then if [[ $tls_version == 3 ]]; then
sed -i 's/ssl_protocols.*/ssl_protocols TLSv1.3;/' $nginx_conf sed -i 's/ssl_protocols.*/ssl_protocols TLSv1.3;/' $nginx_conf
echo -e "${OK} ${GreenBG} 已切换至 TLS1.3 only ${Font}" echo -e "${OK} ${GreenBG} 已切换至 TLS1.3 only ${Font}"
elif [[ $tls_version == 1 ]];then elif [[ $tls_version == 1 ]]; then
sed -i 's/ssl_protocols.*/ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;/' $nginx_conf sed -i 's/ssl_protocols.*/ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;/' $nginx_conf
echo -e "${OK} ${GreenBG} 已切换至 TLS1.1 TLS1.2 and TLS1.3 ${Font}" echo -e "${OK} ${GreenBG} 已切换至 TLS1.1 TLS1.2 and TLS1.3 ${Font}"
else else
@ -761,42 +751,41 @@ tls_type(){
echo -e "${Error} ${RedBG} Nginx 或 配置文件不存在 或当前安装版本为 h2 ,请正确安装脚本后执行${Font}" echo -e "${Error} ${RedBG} Nginx 或 配置文件不存在 或当前安装版本为 h2 ,请正确安装脚本后执行${Font}"
fi fi
} }
show_access_log(){ show_access_log() {
[ -f ${v2ray_access_log} ] && tail -f ${v2ray_access_log} || echo -e "${RedBG}log文件不存在${Font}" [ -f ${v2ray_access_log} ] && tail -f ${v2ray_access_log} || echo -e "${RedBG}log文件不存在${Font}"
} }
show_error_log(){ show_error_log() {
[ -f ${v2ray_error_log} ] && tail -f ${v2ray_error_log} || echo -e "${RedBG}log文件不存在${Font}" [ -f ${v2ray_error_log} ] && tail -f ${v2ray_error_log} || echo -e "${RedBG}log文件不存在${Font}"
} }
ssl_update_manuel(){ ssl_update_manuel() {
[ -f ${amce_sh_file} ] && "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" || echo -e "${RedBG}证书签发工具不存在,请确认你是否使用了自己的证书${Font}" [ -f ${amce_sh_file} ] && "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" || echo -e "${RedBG}证书签发工具不存在,请确认你是否使用了自己的证书${Font}"
domain="$(info_extraction '\"add\"')" domain="$(info_extraction '\"add\"')"
$HOME/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /data/v2ray.crt --keypath /data/v2ray.key --ecc "$HOME"/.acme.sh/acme.sh --installcert -d "${domain}" --fullchainpath /data/v2ray.crt --keypath /data/v2ray.key --ecc
} }
bbr_boost_sh(){ bbr_boost_sh() {
[ -f "tcp.sh" ] && rm -rf ./tcp.sh [ -f "tcp.sh" ] && rm -rf ./tcp.sh
wget -N --no-check-certificate "https://github.com/ylx2016/Linux-NetSpeed/releases/download/sh/tcp.sh" && chmod +x tcp.sh && ./tcp.sh wget -N --no-check-certificate "https://github.com/ylx2016/Linux-NetSpeed/releases/download/sh/tcp.sh" && chmod +x tcp.sh && ./tcp.sh
} }
mtproxy_sh(){ mtproxy_sh() {
[ -f "mtproxy_go.sh" ] && rm -rf ./mtproxy_go.sh [ -f "mtproxy_go.sh" ] && rm -rf ./mtproxy_go.sh
wget -N --no-check-certificate https://github.com/whunt1/onekeymakemtg/raw/master/mtproxy_go.sh && chmod +x mtproxy_go.sh && ./mtproxy_go.sh wget -N --no-check-certificate https://github.com/whunt1/onekeymakemtg/raw/master/mtproxy_go.sh && chmod +x mtproxy_go.sh && ./mtproxy_go.sh
} }
uninstall_all(){ uninstall_all() {
stop_process_systemd stop_process_systemd
[[ -f $nginx_systemd_file ]] && rm -f $nginx_systemd_file [[ -f $nginx_systemd_file ]] && rm -f $nginx_systemd_file
[[ -f $v2ray_systemd_file ]] && rm -f $v2ray_systemd_file [[ -f $v2ray_systemd_file ]] && rm -f $v2ray_systemd_file
[[ -d $v2ray_bin_dir ]] && rm -rf $v2ray_bin_dir [[ -d $v2ray_bin_dir ]] && rm -rf $v2ray_bin_dir
if [[ -d $nginx_dir ]] if [[ -d $nginx_dir ]]; then
then
echo -e "${OK} ${Green} 是否卸载 Nginx [Y/N]? ${Font}" echo -e "${OK} ${Green} 是否卸载 Nginx [Y/N]? ${Font}"
read -r uninstall_nginx read -r uninstall_nginx
case $uninstall_nginx in case $uninstall_nginx in
[yY][eE][sS]|[yY]) [yY][eE][sS] | [yY])
rm -rf $nginx_dir rm -rf $nginx_dir
echo -e "${OK} ${Green} 已卸载 Nginx ${Font}" echo -e "${OK} ${Green} 已卸载 Nginx ${Font}"
;; ;;
*) *) ;;
;;
esac esac
fi fi
[[ -d $v2ray_conf_dir ]] && rm -rf $v2ray_conf_dir [[ -d $v2ray_conf_dir ]] && rm -rf $v2ray_conf_dir
@ -804,24 +793,21 @@ uninstall_all(){
systemctl daemon-reload systemctl daemon-reload
echo -e "${OK} ${GreenBG} 已卸载SSL证书文件已保留 ${Font}" echo -e "${OK} ${GreenBG} 已卸载SSL证书文件已保留 ${Font}"
} }
delete_tls_key_and_crt(){ delete_tls_key_and_crt() {
[[ -f $HOME/.acme.sh/acme.sh ]] && /root/.acme.sh/acme.sh uninstall > /dev/null 2>&1 [[ -f $HOME/.acme.sh/acme.sh ]] && /root/.acme.sh/acme.sh uninstall >/dev/null 2>&1
[[ -d $HOME/.acme.sh ]] && rm -rf "$HOME/.acme.sh" [[ -d $HOME/.acme.sh ]] && rm -rf "$HOME/.acme.sh"
echo -e "${OK} ${GreenBG} 已清空证书遗留文件 ${Font}" echo -e "${OK} ${GreenBG} 已清空证书遗留文件 ${Font}"
} }
judge_mode(){ judge_mode() {
if [ -f $v2ray_bin_dir/v2ray ] if [ -f $v2ray_bin_dir/v2ray ]; then
then if grep -q "ws" $v2ray_qr_config_file; then
if [[ -n $(grep "ws" $v2ray_qr_config_file) ]]
then
shell_mode="ws" shell_mode="ws"
elif [[ -n $(grep "h2" $v2ray_qr_config_file) ]] elif grep -q "h2" $v2ray_qr_config_file; then
then
shell_mode="h2" shell_mode="h2"
fi fi
fi fi
} }
install_v2ray_ws_tls(){ install_v2ray_ws_tls() {
is_root is_root
check_system check_system
chrony_install chrony_install
@ -832,7 +818,7 @@ install_v2ray_ws_tls(){
port_alterid_set port_alterid_set
v2ray_install v2ray_install
port_exist_check 80 port_exist_check 80
port_exist_check ${port} port_exist_check "${port}"
nginx_exist_check nginx_exist_check
v2ray_conf_add_tls v2ray_conf_add_tls
nginx_conf_add nginx_conf_add
@ -848,7 +834,7 @@ install_v2ray_ws_tls(){
enable_process_systemd enable_process_systemd
acme_cron_update acme_cron_update
} }
install_v2_h2(){ install_v2_h2() {
is_root is_root
check_system check_system
chrony_install chrony_install
@ -859,7 +845,7 @@ install_v2_h2(){
port_alterid_set port_alterid_set
v2ray_install v2ray_install
port_exist_check 80 port_exist_check 80
port_exist_check ${port} port_exist_check "${port}"
v2ray_conf_add_h2 v2ray_conf_add_h2
ssl_judge_and_install ssl_judge_and_install
vmess_qr_config_h2 vmess_qr_config_h2
@ -870,34 +856,33 @@ install_v2_h2(){
enable_process_systemd enable_process_systemd
} }
update_sh(){ update_sh() {
ol_version=$(curl -L -s https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/install.sh | grep "shell_version=" | head -1 |awk -F '=|"' '{print $3}') ol_version=$(curl -L -s https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/install.sh | grep "shell_version=" | head -1 | awk -F '=|"' '{print $3}')
echo "$ol_version" > $version_cmp echo "$ol_version" >$version_cmp
echo "$shell_version" >> $version_cmp echo "$shell_version" >>$version_cmp
if [[ "$shell_version" < "$(sort -rV $version_cmp | head -1)" ]] if [[ "$shell_version" < "$(sort -rV $version_cmp | head -1)" ]]; then
then
echo -e "${OK} ${GreenBG} 存在新版本,是否更新 [Y/N]? ${Font}" echo -e "${OK} ${GreenBG} 存在新版本,是否更新 [Y/N]? ${Font}"
read -r update_confirm read -r update_confirm
case $update_confirm in case $update_confirm in
[yY][eE][sS]|[yY]) [yY][eE][sS] | [yY])
wget -N --no-check-certificate https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/install.sh wget -N --no-check-certificate https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/${github_branch}/install.sh
echo -e "${OK} ${GreenBG} 更新完成 ${Font}" echo -e "${OK} ${GreenBG} 更新完成 ${Font}"
exit 0 exit 0
;; ;;
*) *) ;;
;;
esac esac
else else
echo -e "${OK} ${GreenBG} 当前版本为最新版本 ${Font}" echo -e "${OK} ${GreenBG} 当前版本为最新版本 ${Font}"
fi fi
} }
maintain(){ maintain() {
echo -e "${RedBG}该选项暂时无法使用${Font}" echo -e "${RedBG}该选项暂时无法使用${Font}"
echo -e "${RedBG}$1${Font}" echo -e "${RedBG}$1${Font}"
exit 0 exit 0
} }
list(){ list() {
case $1 in case $1 in
tls_modify) tls_modify)
tls_type tls_type
@ -917,7 +902,7 @@ list(){
esac esac
} }
menu(){ menu() {
update_sh update_sh
echo -e "\t V2ray 安装管理脚本 ${Red}[${shell_version}]${Font}" echo -e "\t V2ray 安装管理脚本 ${Red}[${shell_version}]${Font}"
echo -e "\t---authored by wulabing---" echo -e "\t---authored by wulabing---"
@ -947,7 +932,7 @@ menu(){
echo -e "${Green}16.${Font} 清空 证书遗留文件" echo -e "${Green}16.${Font} 清空 证书遗留文件"
echo -e "${Green}17.${Font} 退出 \n" echo -e "${Green}17.${Font} 退出 \n"
read -p "请输入数字:" menu_num read -rp "请输入数字:" menu_num
case $menu_num in case $menu_num in
0) 0)
update_sh update_sh
@ -964,22 +949,20 @@ menu(){
bash <(curl -L -s https://install.direct/go.sh) bash <(curl -L -s https://install.direct/go.sh)
;; ;;
4) 4)
read -p "请输入UUID:" UUID read -rp "请输入UUID:" UUID
modify_UUID modify_UUID
start_process_systemd start_process_systemd
;; ;;
5) 5)
read -p "请输入alterID:" alterID read -rp "请输入alterID:" alterID
modify_alterid modify_alterid
start_process_systemd start_process_systemd
;; ;;
6) 6)
read -p "请输入连接端口:" port read -rp "请输入连接端口:" port
if [[ -n $(grep "ws" $v2ray_qr_config_file) ]] if grep -q "ws" $v2ray_qr_config_file; then
then
modify_nginx_port modify_nginx_port
elif [[ -n $(grep "h2" $v2ray_qr_config_file) ]] elif grep -q "h2" $v2ray_qr_config_file; then
then
modify_inbound_port modify_inbound_port
fi fi
start_process_systemd start_process_systemd
@ -1028,5 +1011,4 @@ menu(){
} }
judge_mode judge_mode
list $1 list "$1"