fix(脚本): 修改定时检查证书

pull/534/merge
mack-a 2020-09-11 23:26:55 +08:00
parent aabdaaa926
commit dac6e4a3f0
1 changed files with 32 additions and 32 deletions

View File

@ -375,69 +375,69 @@ installCronTLS(){
cat << EOF > /etc/v2ray-agent/reloadInstallTLS.sh cat << EOF > /etc/v2ray-agent/reloadInstallTLS.sh
#!/usr/bin/env bash #!/usr/bin/env bash
echoContent(){ echoContent(){
case $1 in case \$1 in
# 红色 # 红色
"red") "red")
echo -e "\033[31m${printN}$2 \033[0m" echo -e "\033[31m\${printN}\$2 \033[0m"
;; ;;
# 天蓝色 # 天蓝色
"skyBlue") "skyBlue")
echo -e "\033[1;36m${printN}$2 \033[0m" echo -e "\033[1;36m\${printN}\$2 \033[0m"
;; ;;
# 绿色 # 绿色
"green") "green")
echo -e "\033[32m${printN}$2 \033[0m" echo -e "\033[32m\${printN}\$2 \033[0m"
;; ;;
# 白色 # 白色
"white") "white")
echo -e "\033[37m${printN}$2 \033[0m" echo -e "\033[37m\${printN}\$2 \033[0m"
;; ;;
"magenta") "magenta")
echo -e "\033[31m${printN}$2 \033[0m" echo -e "\033[31m\${printN}\$2 \033[0m"
;; ;;
"skyBlue") "skyBlue")
echo -e "\033[36m${printN}$2 \033[0m" echo -e "\033[36m\${printN}\$2 \033[0m"
;; ;;
# 黄色 # 黄色
"yellow") "yellow")
echo -e "\033[33m${printN}$2 \033[0m" echo -e "\033[33m\${printN}\$2 \033[0m"
;; ;;
esac esac
} }
echoContent skyBlue "\n进度 1/1 : 更新证书" echoContent skyBlue "\n进度 1/1 : 更新证书"
if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] && [[ -d "/etc/v2ray-agent/tls" ]] && [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] && [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] && [[ -d "/root/.acme.sh" ]] if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] && [[ -d "/etc/v2ray-agent/tls" ]] && [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] && [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] && [[ -d "/root/.acme.sh" ]]
then then
tcp=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[0]` tcp=\`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[0]\`
host=`echo ${tcp}|jq .streamSettings.tlsSettings.certificates[0].certificateFile|awk -F '[t][l][s][/]' '{print $2}'|awk -F '["]' '{print $1}'|awk -F '[.][c][r][t]' '{print $1}'` host=\`echo \${tcp}|jq .streamSettings.tlsSettings.certificates[0].certificateFile|awk -F '[t][l][s][/]' '{print \$2}'|awk -F '["]' '{print \$1}'|awk -F '[.][c][r][t]' '{print \$1}'\`
if [[ -d "/root/.acme.sh/${host}_ecc" ]] && [[ -f "/root/.acme.sh/${host}_ecc/${host}.key" ]] && [[ -f "/root/.acme.sh/${host}_ecc/${host}.cer" ]] if [[ -d "/root/.acme.sh/\${host}_ecc" ]] && [[ -f "/root/.acme.sh/\${host}_ecc/\${host}.key" ]] && [[ -f "/root/.acme.sh/\${host}_ecc/\${host}.cer" ]]
then then
modifyTime=`stat /root/.acme.sh/${host}_ecc/${host}.key|sed -n '6,6p'|awk '{print $2" "$3" "$4" "$5}'` modifyTime=\`stat /root/.acme.sh/\${host}_ecc/\${host}.key|sed -n '6,6p'|awk '{print \$2" "\$3" "\$4" "\$5}'\`
modifyTime=`date +%s -d "${modifyTime}"` modifyTime=\`date +%s -d "\${modifyTime}"\`
currentTime=`date +%s` currentTime=\`date +%s\`
# currentTime=`date +%s -d "2021-09-04 02:15:56.438105732 +0000"` # currentTime=\`date +%s -d "2021-09-04 02:15:56.438105732 +0000"\`
# currentTIme=1609459200 # currentTIme=1609459200
stampDiff=`expr ${currentTime} - ${modifyTime}` stampDiff=\`expr \${currentTime} - \${modifyTime}\`
days=`expr ${stampDiff} / 86400` days=\`expr \${stampDiff} / 86400\`
remainingDays=`expr 90 - ${days}` remainingDays=\`expr 90 - \${days}\`
tlsStatus=${remainingDays} tlsStatus=\${remainingDays}
if [[ ${remainingDays} -le 0 ]] if [[ \${remainingDays} -le 0 ]]
then then
tlsStatus="已过期" tlsStatus="已过期"
fi fi
echoContent skyBlue " ---> 证书生成日期:"`date -d @${modifyTime} +"%F %H:%M:%S"` echoContent skyBlue " ---> 证书生成日期:"\`date -d @\${modifyTime} +"%F %H:%M:%S"\`
echoContent skyBlue " ---> 证书生成天数:"${days} echoContent skyBlue " ---> 证书生成天数:"\${days}
echoContent skyBlue " ---> 证书剩余天数:"${tlsStatus} echoContent skyBlue " ---> 证书剩余天数:"\${tlsStatus}
if [[ ${remainingDays} -le 1 ]] if [[ \${remainingDays} -le 1 ]]
then then
echoContent yellow " ---> 重新生成证书" echoContent yellow " ---> 重新生成证书"
if [[ `ps -ef|grep -v grep|grep nginx` ]] if [[ \`ps -ef|grep -v grep|grep nginx\` ]]
then then
nginx -s stop nginx -s stop
fi fi
sudo ~/.acme.sh/acme.sh --installcert -d ${host} --fullchainpath /etc/v2ray-agent/tls/${host}.crt --keypath /etc/v2ray-agent/tls/${host}.key --ecc >> /etc/v2ray-agent/tls/acme.log sudo ~/.acme.sh/acme.sh --installcert -d \${host} --fullchainpath /etc/v2ray-agent/tls/\${host}.crt --keypath /etc/v2ray-agent/tls/\${host}.key --ecc >> /etc/v2ray-agent/tls/acme.log
nginx nginx
if [[ `ps -ef|grep -v grep|grep nginx` ]] if [[ \`ps -ef|grep -v grep|grep nginx\` ]]
then then
echoContent green " ---> nginx启动成功" echoContent green " ---> nginx启动成功"
else else
@ -1608,12 +1608,12 @@ installV2RayVLESSTCPWSTLS(){
handleNginx stop handleNginx stop
initNginxConfig vlesstcpws 5 initNginxConfig vlesstcpws 5
randomPathFunction 6 randomPathFunction 6
installCronTLS 7
# 安装V2Ray # 安装V2Ray
installV2Ray 8 installV2Ray 7
installV2RayService 9 installV2RayService 8
customCDNIP 10 customCDNIP 9
initV2RayConfig vlesstcpws 11 initV2RayConfig vlesstcpws 10
installCronTLS 11
nginxBlog 12 nginxBlog 12
handleV2Ray stop handleV2Ray stop
handleV2Ray start handleV2Ray start