diff --git a/install.sh b/install.sh index 415ed6a..7c7698f 100644 --- a/install.sh +++ b/install.sh @@ -4,47 +4,65 @@ installType='yum -y install' removeType='yum -y remove' upgrade="yum -y update" echoType='echo -e' +centosVersion=0 +installProgress=0 +totalProgress=20 iplc=$1 - +trap 'onCtrlC' INT +function onCtrlC () { + echo + killSleep > /dev/null 2>&1 + exit; +} # echo颜色方法 echoContent(){ + printN='\n' + if [[ ! -z "$3" ]] + then + printN='' + fi case $1 in # 红色 "red") - ${echoType} "\033[31m$2 \033[0m" + ${echoType} "\033[31m${printN}$2 \033[0m" ;; # 天蓝色 "skyBlue") - ${echoType} "\033[36m$2 \033[0m" + ${echoType} "\033[36m${printN}$2 \033[0m" ;; # 绿色 "green") - ${echoType} "\033[32m$2 \033[0m" + ${echoType} "\033[32m${printN}$2 \033[0m" ;; # 白色 "white") - ${echoType} "\033[37m$2 \033[0m" + ${echoType} "\033[37m${printN}$2 \033[0m" ;; "magenta") - ${echoType} "\033[31m$2 \033[0m" + ${echoType} "\033[31m${printN}$2 \033[0m" ;; "skyBlue") - ${echoType} "\033[36m$2 \033[0m" + ${echoType} "\033[36m${printN}$2 \033[0m" ;; # 黄色 "yellow") - ${echoType} "\033[33m$2 \033[0m" + ${echoType} "\033[33m${printN}$2 \033[0m" ;; esac } +# 修复bug fixBug(){ - if [[ "${release}" = "ubuntu" ]] - then - cd /var/lib/dpkg/ - - fi + echo +} +# 新建目录 +mkdirTools(){ + mkdir -p /etc/v2ray/ + mkdir -p /etc/systemd/system/ + mkdir -p /etc/nginx/v2ray-agent-https/ + mkdir -p /usr/bin/v2ray/ + mkdir -p /tmp/v2ray/ + mkdir -p /tmp/tls/ } - # 安装工具包 installTools(){ # echo "export LC_ALL=en_US.UTF-8" >> /etc/profile @@ -52,18 +70,37 @@ installTools(){ # kill lock if [[ "${release}" = "centos" ]] then + progressTools "yellow" "检查安装jq、nginx epel源、yum-utils--->" 0 # jq epel源 rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm > /dev/null 2>&1 + + nginxEpel="" + if [[ ! -z `rpm -qa|grep -v grep|grep nginx` ]] + then + rpm -qa|grep -v grep|grep nginx|xargs rpm -e > /dev/null 2>&1 + fi + if [[ "${centosVersion}" = "6" ]] + then + nginxEpel="http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.18.0-1.el6.ngx.x86_64.rpm" + elif [[ "${centosVersion}" = "7" ]] + then + nginxEpel="http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm" + elif [[ "${centosVersion}" = "8" ]] + then + nginxEpel="http://nginx.org/packages/centos/8/x86_64/RPMS/nginx-1.18.0-1.el8.ngx.x86_64.rpm" + fi # nginx epel源 - rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm > /dev/null 2>&1 + rpm -ivh ${nginxEpel} > /dev/null 2>&1 + # yum-utils + yum install yum-utils -y > /dev/null 2>&1 fi if [[ ! -z `ps -ef|grep -v grep|grep apt` ]] then ps -ef|grep -v grep|grep apt|awk '{print $2}'|xargs kill -9 fi - - echoContent yellow "删除Nginx、V2Ray,请等待--->" + progressTools "yellow" "卸载Nginx--->" 1 +# echoContent yellow "删除Nginx、V2Ray,请等待--->" if [[ ! -z `find /usr/sbin/ -name nginx` ]] then if [[ ! -z `ps -ef|grep nginx|grep -v grep` ]] @@ -81,6 +118,7 @@ installTools(){ rm -rf /usr/share/nginx/html.zip fi + progressTools "yellow" "卸载V2Ray--->" 2 if [[ ! -z `find /usr/bin/ -name "v2ray*"` ]] then if [[ ! -z `ps -ef|grep v2ray|grep -v grep` ]] @@ -90,52 +128,51 @@ installTools(){ rm -rf /usr/bin/v2ray fi - if [[ ! -z `cat /root/.bashrc|grep -n acme` ]] - then - acmeBashrcLine=`cat /root/.bashrc|grep -n acme|awk -F "[:]" '{print $1}'|head -1` - sed -i "${acmeBashrcLine}d" /root/.bashrc - fi + progressTools "yellow" "卸载V2Ray开机自启--->" 3 rm -rf /etc/systemd/system/v2ray.service if [[ ! -z `find /bin /usr/bin -name "systemctl"` ]] then systemctl daemon-reload else - echo 'Centos6' + echo fi - # rm -rf ~/.acme.sh > /dev/null - echoContent green " 删除完成" + progressTools "yellow" "卸载acme.sh--->" 4 + rm -rf ~/.acme.sh > /dev/null + if [[ ! -z `cat /root/.bashrc|grep -n acme` ]] + then + acmeBashrcLine=`cat /root/.bashrc|grep -n acme|awk -F "[:]" '{print $1}'|head -1` + sed -i "${acmeBashrcLine}d" /root/.bashrc + fi - echoContent skyBlue "检查、安装工具包:" - echoContent green " 更新中,等耐心等待,时间可能比较久" + progressTools "yellow" "检查、安装更新【新机器会很慢,耐心等待】--->" 5 # if [[ "${release}" = "centos" ]] # then # yum-complete-transaction --cleanup-only # fi ${upgrade} > /dev/null + # yum要删除pid rm -rf /var/run/yum.pid - echoContent green "更新完毕" - echoContent yellow "检查、安装wget--->" - progressTool wget & + progressTools "yellow" "检查、安装wget--->" 6 ${installType} wget > /dev/null - echoContent yellow "检查、安装unzip--->" - progressTool unzip & + progressTools "yellow" "检查、安装unzip--->" 7 ${installType} unzip > /dev/null # echoContent yellow "检查、安装qrencode--->" - # progressTool qrencode & + # # progressTool qrencode & # ${installType} qrencode > /dev/null - echoContent yellow "检查、安装socat--->" - progressTool socat & + progressTools "yellow" "检查、安装socat--->" 8 ${installType} socat > /dev/null - echoContent yellow "检查、安装crontabs--->" - progressTool crontabs & + progressTools "yellow" "检查、安装tar--->" 9 + ${installType} tar > /dev/null + + progressTools "yellow" "检查、安装crontabs--->" 10 if [[ "${release}" = "ubuntu" ]] || [[ "${release}" = "debian" ]] then ${installType} cron > /dev/null @@ -143,45 +180,48 @@ installTools(){ ${installType} crontabs > /dev/null fi - echoContent yellow "检查、安装jq--->" - progressTool jq & + progressTools "yellow" "检查、安装jq--->" 11 ${installType} jq > /dev/null - killSleep > /dev/null 2>&1 + # echoContent skyBlue "检查、安装bind-utils--->" - # progressTool bind-utils + # # progressTool bind-utils # 关闭防火墙 + # 安装nginx + progressTools "yellow" "检查、安装Nginx--->" 12 + # progressTool nginx & + ${installType} nginx > /dev/null + if [[ ! -z `ps -ef|grep -v grep|grep nginx` ]] + then + nginx -s stop + fi + progressTools "yellow" "检查、安装acme--->" 13 + curl -s https://get.acme.sh | sh > /tmp/tls/acme.log + if [[ -z `find ~/.acme.sh -name "acme.sh"` ]] + then + echoContent red " acme安装失败--->" + echoContent yellow "错误排查:" + echoContent red " 1.获取Github文件失败,请等待GitHub恢复后尝试,恢复进度可查看 [https://www.githubstatus.com/]" + echoContent red " 2.acme.sh脚本出现bug,可查看[https://github.com/acmesh-official/acme.sh] issues" + echoContent red " 3.反馈给开发者[私聊:https://t.me/mack_a] 或 [提issues]" + killSleep > /dev/null 2>&1 + exit 0 + fi } # 安装Nginx tls证书 installNginx(){ - echoContent skyBlue "检查、安装Nginx、TLS:" + killSleep > /dev/null 2>&1 + killSleep > /dev/null 2>&1 echoContent yellow "请输入要配置的域名 例:worker.v2ray-agent.com --->" - rm -rf /etc/nginx/nginx.conf read domain if [[ -z ${domain} ]] then echoContent red " 域名不可为空--->" installNginx else - # 安装nginx - echoContent yellow " 检查、安装Nginx--->" - progressTool nginx & - ${installType} nginx > /dev/null - - if [[ ! -z `ps -ef|grep -v grep|grep nginx` ]] - then - nginx -s stop - # ps -ef|grep -v grep|grep nginx|awk '{print $2}'|xargs kill -9 - fi - # 修改配置 - echoContent yellow "修改配置文件--->" - - + progressTools "yellow" "配置Nginx--->" 14 touch /etc/nginx/conf.d/alone.conf - # installLine=`cat /etc/nginx/nginx.conf|grep -n root|awk -F "[:]" '{print $1+1}'|head -1` - # ${installLine} - # ${domain} echo "server {listen 80;server_name ${domain};root /usr/share/nginx/html;location ~ /.well-known {allow all;}location /test {return 200 'fjkvymb6len';}}" > /etc/nginx/conf.d/alone.conf # sed -i "1i 1" /etc/nginx/conf.d/alone.conf # installLine=`expr ${installLine} + 1` @@ -190,13 +230,12 @@ installNginx(){ nginx # 测试nginx - echoContent yellow "检查Nginx是否正常访问,请等待--->" - # ${domain} + progressTools "yellow" "检查Nginx是否正常访问--->" 15 domainResult=`curl -s ${domain}/test|grep fjkvymb6len` if [[ ! -z ${domainResult} ]] then - echoContent green " Nginx访问成功--->\n" ps -ef|grep nginx|grep -v grep|awk '{print $2}'|xargs kill -9 + progressTools "green" "Nginx配置成功--->" installTLS ${domain} else echoContent red " 无法正常访问服务器,请检测域名是否正确、域名的DNS解析以及防火墙设置是否正确--->" @@ -209,64 +248,49 @@ installNginx(){ installTLS(){ mkdir -p /etc/nginx/v2ray-agent-https/ touch /etc/nginx/v2ray-agent-https/config - mkdir -p /tmp/tls + if [[ -z `find /tmp -name "$1*"` ]] then + progressTools "yellow" "检查、安装TLS证书--->" 16 - echoContent yellow "安装TLS证书--->" - echoContent yellow " 安装acme--->" - curl -s https://get.acme.sh | sh >> /tmp/tls/acme.log - if [[ -z `find ~/.acme.sh -name "acme.sh"` ]] - then - echoContent red " acme安装失败--->" - echoContent yellow "错误排查:" - echoContent red " 1.获取Github文件失败,请等待GitHub恢复后尝试,恢复进度可查看 [https://www.githubstatus.com/]" - echoContent red " 2.acme.sh脚本出现bug,可查看[https://github.com/acmesh-official/acme.sh] issues" - echoContent red " 3.反馈给开发者[私聊:https://t.me/mack_a] 或 [提issues]" - killSleep > /dev/null 2>&1 - exit 0 - fi - echoContent green " acme安装完毕--->" - echoContent yellow "生成TLS证书中,请等待--->" sudo ~/.acme.sh/acme.sh --issue -d $1 --standalone -k ec-256 >/dev/null ~/.acme.sh/acme.sh --installcert -d $1 --fullchainpath /etc/nginx/v2ray-agent-https/$1.crt --keypath /etc/nginx/v2ray-agent-https/$1.key --ecc >/dev/null if [[ -z `cat /etc/nginx/v2ray-agent-https/$1.crt` ]] then - echoContent red " TLS安装失败,请检查acme日志--->" - killSleep > /dev/null 2>&1 + progressTools "yellow" " TLS安装失败,请检查acme日志--->" exit 0 elif [[ -z `cat /etc/nginx/v2ray-agent-https/$1.key` ]] then - echoContent red " TLS安装失败,请检查acme日志--->" - killSleep > /dev/null 2>&1 + progressTools "yellow" " TLS安装失败,请检查acme日志--->" exit 0 fi - echoContent green " TLS生成成功--->" + progressTools "green" " TLS生成成功--->>" + echo $1 `date +%s` > /etc/nginx/v2ray-agent-https/config cp -R /etc/nginx/v2ray-agent-https/config /tmp/tls/config cp -R /etc/nginx/v2ray-agent-https/$1.crt /tmp/tls/$1.crt cp -R /etc/nginx/v2ray-agent-https/$1.key /tmp/tls/$1.key - echoContent green " TLS证书备份成功,证书位置:/tmp/tls--->" + progressTools "yellow" " TLS证书备份成功,证书位置:/tmp/tls--->" elif [[ -z `cat /tmp/tls/$1.crt` ]] || [[ -z `cat /tmp/tls/$1.key` ]] then - echoContent red " 检测到错误证书,需重新生成,重新生成中--->" + progressTools "red" " 检测到错误证书,需重新生成,重新生成中--->" 17 rm -rf /tmp/tls installTLS $1 else - echoContent yellow "检测到备份证书,使用--->" + progressTools "yellow" "检测到备份证书,使用--->" cp -R /tmp/tls/$1.crt /etc/nginx/v2ray-agent-https/$1.crt cp -R /tmp/tls/$1.key /etc/nginx/v2ray-agent-https/$1.key cp -R /tmp/tls/config /etc/nginx/v2ray-agent-https/config fi - # nginxInstallLine=`cat /etc/nginx/nginx.conf|grep -n "}"|awk -F "[:]" 'END{print $1-1}'` # sed -i "${nginxInstallLine}i server {listen 443 ssl;server_name $1;root /usr/share/nginx/html;ssl_certificate /etc/nginx/$1.crt;ssl_certificate_key /etc/nginx/$1.key;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_prefer_server_ciphers on;location / {} location /alone { proxy_redirect off;proxy_pass http://127.0.0.1:31299;proxy_http_version 1.1;proxy_set_header Upgrade \$http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header X-Real-IP \$remote_addr;proxy_set_header Host \$host;proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;}}" /etc/nginx/nginx.conf echo "server {listen 443 ssl;server_name $1;root /usr/share/nginx/html;ssl_certificate /etc/nginx/v2ray-agent-https/$1.crt;ssl_certificate_key /etc/nginx/v2ray-agent-https/$1.key;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_prefer_server_ciphers on;location / {} location /alone { proxy_redirect off;proxy_pass http://127.0.0.1:31299;proxy_http_version 1.1;proxy_set_header Upgrade \$http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header X-Real-IP \$remote_addr;proxy_set_header Host \$host;proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;}}" > /etc/nginx/conf.d/alone.conf # 自定义路径 - echoContent yellow "请输入自定义路径[例: alone],不需要斜杠,[回车]默认路径" + # todo 随机路径 + progressTools "yellow" "请输入自定义路径[例: alone],不需要斜杠,[回车]默认路径" read customPath if [[ ! -z "${customPath}" ]] @@ -280,11 +304,10 @@ installTLS(){ nginx if [[ -z `ps -ef|grep -v grep|grep nginx` ]] then - echoContent red " Nginx启动失败,请检查日志--->" - killSleep > /dev/null 2>&1 + progressTools "red" " Nginx启动失败,请检查日志--->" exit 0 fi - echoContent green " Nginx启动成功,TLS配置成功--->\n" + # 增加定时任务定时维护证书 reInstallTLS $1 installV2Ray $1 ${customPath} @@ -292,19 +315,12 @@ installTLS(){ # 重新安装&更新tls证书 reInstallTLS(){ - echoContent yellow "添加定时维护证书,请等待--->" + progressTools "yellow" "检查、添加定时维护证书--->" 18 touch /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh - -# echo '' > /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh -# echo '' > /etc/nginx/v2ray-agent-https/backup_crontab.cron - touch /etc/nginx/v2ray-agent-https/backup_crontab.cron - - mkdir -p /tmp/tls touch /tmp/tls/tls.log if [[ -z `crontab -l|grep -v grep|grep 'reloadInstallTLS'` ]] then - echoContent yellow " 未添加定时更新tls证书,添加中,请等待--->" crontab -l >> /etc/nginx/v2ray-agent-https/backup_crontab.cron # 定时任务 echo "30 1 * * * /bin/bash /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh" >> /etc/nginx/v2ray-agent-https/backup_crontab.cron @@ -342,37 +358,36 @@ reInstallTLS(){ if [[ ! -z `crontab -l|grep -v grep|grep 'reloadInstallTLS'` ]] then - echoContent green " 添加定时维护证书成功" + progressTools "green" " 添加定时维护证书成功" else crontab -l >> /etc/nginx/v2ray-agent-https/backup_crontab.cron # 定时任务 crontab /etc/nginx/v2ray-agent-https/backup_crontab.cron - echoContent green " 检测到已添加定时任务,继续使用" + progressTools "green" " 检测到已添加定时任务" fi } # V2Ray installV2Ray(){ - if [[ -z `find /tmp -name "v2ray"` ]] && [[ -z `find /tmp -name "v2ctl"` ]] +# ls -F /usr/bin/v2ray/|grep "v2ray" + mkdir -p /usr/bin/v2ray/ + if [[ -z `ls -F /tmp/v2ray/|grep "v2ray"` ]] || [[ -z `ls -F /tmp/v2ray/|grep "v2ctl"` ]] then - if [[ -z `find /usr/bin/ -name "v2ray*"` ]] + if [[ -z `ls -F /usr/bin/v2ray/|grep "v2ray"` ]] || [[ -z `ls -F /usr/bin/v2ray/|grep "v2ctl"` ]] then - echoContent yellow "\n安装V2Ray--->" + progressTools "yellow" "检查、安装V2Ray--->" 19 version=`curl -s https://github.com/v2ray/v2ray-core/releases|grep /v2ray/v2ray-core/releases/tag/|head -1|awk -F "[/]" '{print $6}'|awk -F "[>]" '{print $2}'|awk -F "[<]" '{print $1}'` - echoContent green " v2ray-core版本:${version}" - mkdir -p /tmp/v2ray - mkdir -p /usr/bin/v2ray/ + progressTools "green" " v2ray-core版本:${version}" + wget -q -P /tmp/v2ray https://github.com/v2fly/v2ray-core/releases/download/${version}/v2ray-linux-64.zip unzip /tmp/v2ray/v2ray-linux-64.zip -d /tmp/v2ray > /dev/null - cp /tmp/v2ray/v2ray /usr/bin/v2ray/ - cp /tmp/v2ray/v2ctl /usr/bin/v2ray/ + cp /tmp/v2ray/v2ray /usr/bin/v2ray/v2ray && cp /tmp/v2ray/v2ctl /usr/bin/v2ray/v2ctl rm -rf /tmp/v2ray/v2ray-linux-64.zip fi - echoContent green " V2Ray安装成功--->" else - echoContent yellow "\n检测到V2Ray安装程序,使用--->\n" - mkdir -p /usr/bin/v2ray/ - cp /tmp/v2ray/v2ray /usr/bin/v2ray/ && cp /tmp/v2ray/v2ctl /usr/bin/v2ray/ + progressTools "green" " v2ray-core版本:`/tmp/v2ray/v2ray --version|awk '{print $2}'|head -1`" + cp /tmp/v2ray/v2ray /usr/bin/v2ray/v2ray && cp /tmp/v2ray/v2ctl /usr/bin/v2ray/v2ctl fi + if [[ ! -z `find /bin /usr/bin -name "systemctl"` ]] then installV2RayService @@ -385,50 +400,49 @@ installV2Ray(){ systemctl enable v2ray.service systemctl start v2ray.service else - /usr/bin/v2ray/v2ray -config /etc/v2ray/config.json & + /usr/bin/v2ray/v2ray -config /etc/v2ray/config.json & > /dev/null 2>&1 fi - + sleep 0.5 if [[ -z `ps -ef|grep v2ray|grep -v grep` ]] then - echoContent red " V2Ray启动失败,请检查日志后,重新执行脚本--->" - killSleep > /dev/null 2>&1 + progressTools "red" " V2Ray启动失败,请检查日志后,重新执行脚本--->" exit 0; fi - echoContent green " V2Ray启动成功--->\n" +# echoContent green " V2Ray启动成功--->\n" echoContent yellow "V2Ray日志目录:" echoContent green " access: /etc/v2ray/v2ray_access_ws_tls.log" echoContent green " error: /etc/v2ray/v2ray_error_ws_tls.log" # 验证整个服务是否可用 - echoContent yellow "验证服务是否可用--->" - sleep 0.5 + progressTools "yellow" "验证服务是否可用--->" nginxPath=$2; if [[ -z "${nginxPath}" ]] then nginxPath="alone" fi - echo "https://$1/${nginxPath}" if [[ ! -z `curl -s -L https://$1/${nginxPath}|grep -v grep|grep "Bad Request"` ]] then - echoContent green " 服务可用--->\n" + progressTools "green" " 服务可用--->" else - - echoContent red " 服务不可用,请检查Cloudflare->域名->SSL/TLS->Overview->Your SSL/TLS encryption mode is 是否是Full--->" - echoContent red " 错误日志:`curl -s -L https://$1/${nginxPath}`" - killSleep > /dev/null 2>&1 + progressTools "red" " 服务不可用,请检查Cloudflare->域名->SSL/TLS->Overview->Your SSL/TLS encryption mode is 是否是Full--->" + progressTools "red" " 错误日志:`curl -s -L https://$1/${nginxPath}`" exit 0 fi qrEncode $1 - echoContent yellow "监听V2Ray日志中,请使用上方生成的vmess访问,如有日志出现则证明线路可用,退出监听也无妨,Ctrl+c退出监听日志,--->" + progressTools "yellow" "安装完毕[100%]--->" + echoContent yellow "============================成功分界线=============================" + + progressTools "yellow" "监听V2Ray日志中,请使用上方生成的vmess访问,如有日志出现则证明线路可用,退出监听也无妨,Ctrl+c退出监听日志,--->" echo '' > /etc/v2ray/v2ray_access_ws_tls.log + killSleep > /dev/null 2>&1 tail -f /etc/v2ray/v2ray_access_ws_tls.log } # 开机自启 installV2RayService(){ - echoContent skyBlue " 配置V2Ray开机自启--->" - mkdir -p /etc/systemd/system/ + progressTools "yellow" " 配置V2Ray开机自启--->" + rm -rf /etc/systemd/system/v2ray.service touch /etc/systemd/system/v2ray.service @@ -450,12 +464,12 @@ installV2RayService(){ echo '' >> /etc/systemd/system/v2ray.service echo '[Install]' >> /etc/systemd/system/v2ray.service echo 'WantedBy=multi-user.target' >> /etc/systemd/system/v2ray.service - echoContent green " 配置V2Ray开机自启成功--->" + progressTools "green" " 配置V2Ray开机自启成功--->" } # 初始化V2Ray 配置文件 initV2RayConfig(){ - mkdir -p /etc/v2ray/ + touch /etc/v2ray/config.json uuid=`/usr/bin/v2ray/v2ctl uuid` @@ -473,7 +487,7 @@ initV2RayConfig(){ else sed -i "s/654765fe-5fb1-271f-7c3f-18ed82827f72/${uuid}/g" `grep 654765fe-5fb1-271f-7c3f-18ed82827f72 -rl /etc/v2ray/config.json` fi - + # todo 这里需要修改 } qrEncode(){ user=`cat /etc/v2ray/config.json|jq .inbounds[0]` @@ -483,38 +497,39 @@ qrEncode(){ host="$1" add="$1" path=`echo ${user}|jq .streamSettings.wsSettings.path` - echoContent green '是否使用DNS智能解析进行自定义CDN IP?' - echoContent yellow " 智能DNS提供一下自定义CDN IP,会根据运营商自动切换ip,测试结果请查看[https://github.com/mack-a/v2ray-agent/blob/master/optimize_V2Ray.md]" - echoContent yellow " 移动:1.0.0.1" - echoContent yellow " 联通:www.digitalocean.com" - echoContent yellow " 电信:www.digitalocean.com" - echoContent yellow '输入[y]使用,[任意]不使用' + echoContent green "是否使用DNS智能解析进行自定义CDN IP?" + + echoContent yellow " 智能DNS提供一下自定义CDN IP,会根据运营商自动切换ip,测试结果请查看[https://github.com/mack-a/v2ray-agent/blob/master/optimize_V2Ray.md]" "no" + echoContent yellow " 移动:1.0.0.83" "no" + echoContent yellow " 联通:104.16.160.136" "no" + echoContent yellow " 电信CNAME:www.digitalocean.com" "no" + echoContent green "输入[y]使用,[任意]不使用" "no" read dnsProxy if [[ "${dnsProxy}" = "y" ]] then - add="domain07.qiu4.ml" + add="domain08.qiu4.ml" fi echoContent yellow "客户端链接--->\n" qrCodeBase64Default=`echo -n '{"port":"443","ps":"'${ps}'","tls":"tls","id":'"${id}"',"aid":"64","v":"2","host":"'${host}'","type":"none","path":'${path}',"net":"ws","add":"'${add}'"}'|sed 's#/#\\\/#g'|base64` qrCodeBase64Default=`echo ${qrCodeBase64Default}|sed 's/ //g'` # 通用Vmess - echoContent red "通用vmess链接--->" + echoContent red "通用vmess链接--->" "no" echoContent green " vmess://${qrCodeBase64Default}\n" echo "通用vmess链接: " > /etc/v2ray/usersv2ray.conf echo " vmess://${qrCodeBase64Default}" >> /etc/v2ray/usersv2ray.conf - echoContent red "通用json--->" + echoContent red "通用json--->" "no" echoContent green ' {"port":"443","ps":"'${ps}'","tls":"tls","id":'"${id}"',"aid":"64","v":"2","host":"'${host}'","type":"none","path":'${path}',"net":"ws","add":"'${add}'"}\n' # Quantumult qrCodeBase64Quanmult=`echo -n ''${ps}' = vmess, '${add}', 443, aes-128-cfb, '${id}', over-tls=true, tls-host='${host}', certificate=1, obfs=ws, obfs-path='${path}', obfs-header="Host: '${host}'[Rr][Nn]User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Mobile/15D100"'|base64` qrCodeBase64Quanmult=`echo ${qrCodeBase64Quanmult}|sed 's/ //g'` - echoContent red "Quantumult vmess--->" + echoContent red "Quantumult vmess--->" "no" echoContent green " vmess://${qrCodeBase64Quanmult}\n" echo '' >> /etc/v2ray/usersv2ray.conf echo "Quantumult:" >> /etc/v2ray/usersv2ray.conf echo " vmess://${qrCodeBase64Quanmult}" >> /etc/v2ray/usersv2ray.conf - echoContent red "Quantumult 明文--->" + echoContent red "Quantumult 明文--->" "no" echoContent green ' '${ps}' = vmess, '${add}', 443, aes-128-cfb, '${id}', over-tls=true, tls-host='${host}', certificate=1, obfs=ws, obfs-path='${path}', obfs-header="Host: '${host}'[Rr][Nn]User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Mobile/15D100"' # | qrencode -t UTF8 # echo ${qrCodeBase64} @@ -547,7 +562,7 @@ progressTool(){ status= if [[ -z `find /usr/bin/ -name ${toolName}` ]] && [[ -z `find /usr/sbin/ -name ${toolName}` ]] then - printf '\b%s' "${sp:i++%n:1}" + printf '\b%s' "${sp:i++%n:1}" > /dev/null else break; fi @@ -555,6 +570,43 @@ progressTool(){ done echoContent green " $1已安装--->" } +# 进度条工具 +progressTools(){ + color=$1 + content=$2 + installProgress=$3 +# echo ${color},${content},${installProgress} + echoContent ${color} "${content}" + killSleep > /dev/null 2>&1 + if [[ ! -z "${installProgress}" ]] + then + installProgressFunction ${installProgress} ${totalProgress} & + fi + + sleep 0.5 +} +installProgressFunction(){ + installProgress=$1 + totalProgress=$2 + currentProgress=0 + i=0 + sp='/-\|' + n=${#sp} + + progressNum=`awk 'BEGIN{printf "%.0f\n",('${installProgress}'/'${totalProgress}')*100}'` +# echoContent red ${progressNum} + printf '\b%s' "[${progressNum}%] " + while true; do + if [[ ${installProgress} -gt ${currentProgress} ]] && [[ ${installProgress} -lt ${totalProgress} ]] + then + printf '\b%s' "${sp:i++%n:1}" + else + break + fi + sleep 0.1 + done +} + # 卸载安装的内容 removeInstall(){ rm -rf /tmp/v2ray @@ -565,6 +617,8 @@ removeInstall(){ `${removeType} nginx` > /dev/null 2>&1 } init(){ + # 新建所需目录 + mkdirTools cd echoContent red "==============================================================" echoContent red "脚本概述" @@ -589,8 +643,7 @@ init(){ echoContent yellow " 暂无配置" fi echoContent green "\nV2Ray信息:" - mkdir -p /usr/bin/v2ray - mkdir -p /etc/v2ray/ + v2rayStatus=0 if [[ ! -z `ls -F /usr/bin/v2ray/|grep "v2ray"` ]] && [[ ! -z `find /etc/v2ray/ -name "config.json"` ]] then @@ -607,7 +660,7 @@ init(){ fi tlsStatus=0 echoContent green "\nTLS证书状态:" - mkdir -p /etc/nginx/v2ray-agent-https/ + if [[ ! -z `find /etc/nginx/v2ray-agent-https/ -name config` ]] && [[ ! -z `cat /etc/nginx/v2ray-agent-https/config` ]] then tlsStatus=1 @@ -658,36 +711,36 @@ init(){ fi - echoContent red "==============================================================" + echoContent red "==============================================================" "no" echoContent red "注意事项:" echoContent green " 1.脚本会检查并安装工具包" - echoContent green " 2.如果使用此脚本生成过TLS证书、V2Ray,会继续使用上次生成、安装的内容。" - echoContent green " 3.会删除、卸载已经安装的应用,包括V2Ray、Nginx。" - echoContent green " 4.如果显示Nginx不可用,请检查防火墙端口是否开放。" - echoContent green " 5.证书会在每天的1点30分检查更新" - echoContent green " 6.重启机器后,日志、缓存文件会被删除,不影响正常使用【tls更新日志、缓存|V2Ray执行文件、日志】" - echoContent red "==============================================================" - echoContent red "错误处理【这里请仔细阅读】" - echoContent yellow "Debian:" - echoContent green " 错误1:WARNING: apt does not have a stable CLI interface. Use with caution in scripts.【这个错误无需处理】" - echoContent green " 错误2:如果错误很多,且安装失败,则需要重启vps,无需重新安装OS。这种情况是在安装过程中意外断开导致。" - echoContent red "==============================================================" + echoContent green " 2.如果使用此脚本生成过TLS证书、V2Ray,会继续使用上次生成、安装的内容。" "no" + echoContent green " 3.会删除、卸载已经安装的应用,包括V2Ray、Nginx。" "no" + echoContent green " 4.如果显示Nginx不可用,请检查防火墙端口是否开放。" "no" + echoContent green " 5.证书会在每天的1点30分检查更新" "no" + echoContent green " 6.重启机器后,日志、缓存文件会被删除,不影响正常使用【tls更新日志、缓存|V2Ray执行文件、日志】" "no" + echoContent red "==============================================================" "no" + echoContent red "错误处理【这里请仔细阅读】" "no" + echoContent yellow "Debian:" "no" + echoContent green " 错误1:WARNING: apt does not have a stable CLI interface. Use with caution in scripts.【这个错误无需处理】" "no" + echoContent green " 错误2:如果错误很多,且安装失败,则需要重启vps,无需重新安装OS。这种情况是在安装过程中意外断开导致。" "no" + echoContent red "==============================================================" "no" installSelect=0 if [[ ${tlsStatus} = "1" ]] && [[ ${v2rayStatus} = "1" ]] then - echoContent green "检测到已使用本脚本安装" - echoContent yellow " 1.重新安装【使用缓存的文件(TLS证书、V2Ray)】" - echoContent yellow " 2.完全重装【会清理tmp缓存文件(TLS证书、V2Ray)】" + echoContent green "检测到已使用本脚本安装" "no" + echoContent yellow " 1.重新安装【使用缓存的文件(TLS证书、V2Ray)】" "no" + echoContent yellow " 2.完全重装【会清理tmp缓存文件(TLS证书、V2Ray)】" "no" else - echoContent green "未监测到使用本脚本安装" - echoContent yellow " 1.安装【未安装】" - echoContent yellow " 2.完全安装【会清理tmp缓存文件(TLS证书、V2Ray)】" + echoContent green "未监测到使用本脚本安装" "no" + echoContent yellow " 1.安装【未安装】" "no" + echoContent yellow " 2.完全安装【会清理tmp缓存文件(TLS证书、V2Ray)】" "no" fi - echoContent yellow " 3.BBR安装[推荐BBR+FQ 或者 BBR+Cake]" - echoContent yellow " 4.完全卸载[清理Nginx、TLS证书、V2Ray、acme.sh]" - echoContent red "==============================================================" - echoContent green "请输入上列数字,[任意]结束:" + echoContent yellow " 3.BBR安装[推荐BBR+FQ 或者 BBR+Cake]" "no" + echoContent yellow " 4.完全卸载[清理Nginx、TLS证书、V2Ray、acme.sh]" "no" + echoContent red "==============================================================" "no" + echoContent green "请输入上列数字,[任意]结束:" "no" read installStatus if [[ "${installStatus}" = "1" ]] @@ -705,12 +758,12 @@ init(){ installNginx elif [[ "${installStatus}" = "3" ]] then - echoContent red "==============================================================" - echoContent green "BBR脚本用的[ylx2016]的成熟作品,地址[https://github.com/ylx2016/Linux-NetSpeed/releases/download/sh/tcp.sh],请熟知" - echoContent red " 1.安装" - echoContent red " 2.回退主目录" - echoContent red "==============================================================" - echoContent green "请输入[1]安装,[2]回到上层目录" + echoContent red "==============================================================" "no" + echoContent green "BBR脚本用的[ylx2016]的成熟作品,地址[https://github.com/ylx2016/Linux-NetSpeed/releases/download/sh/tcp.sh],请熟知" "no" + echoContent red " 1.安装" "no" + echoContent red " 2.回退主目录" "no" + echoContent red "==============================================================" "no" + echoContent green "请输入[1]安装,[2]回到上层目录" "no" read installBBRStatus if [[ "${installBBRStatus}" = "1" ]] then @@ -721,11 +774,11 @@ init(){ elif [[ "${installStatus}" = "4" ]] then removeInstall - echoContent yellow "卸载完成" + echoContent yellow "卸载完成" "no" killSleep > /dev/null 2>&1 exit 0; else - echoContent yellow "欢迎下次使用--->" + echoContent yellow "欢迎下次使用--->" "no" killSleep > /dev/null 2>&1 exit 0; fi @@ -742,6 +795,7 @@ checkSystem(){ if [[ ! -z `find /etc -name "redhat-release"` ]] || [[ ! -z `cat /proc/version | grep -i "centos" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "red hat" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "redhat" | grep -v grep ` ]] then + centosVersion=`rpm -q centos-release|awk -F "[-]" '{print $3}'` release="centos" installType='yum -y install' removeType='yum -y remove' diff --git a/progress.sh b/progress.sh new file mode 100755 index 0000000..66b3147 --- /dev/null +++ b/progress.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +installProgress=3 +totalProgress=10 + + + +init(){ + progress 1 2 +} +init + +# ps -ef|grep -v grep|grep sleep|awk '{print $3}'|xargs kill -9