mirror of https://github.com/mack-a/v2ray-agent
feat(脚本): 完善定时更新证书
parent
1c35bb52d3
commit
40d65411c3
36
install.sh
36
install.sh
|
@ -258,34 +258,42 @@ installTLS(){
|
||||||
|
|
||||||
# 重新安装&更新tls证书
|
# 重新安装&更新tls证书
|
||||||
reInstallTLS(){
|
reInstallTLS(){
|
||||||
echoContent yellow "添加定时维护证书"
|
# echoContent yellow "添加定时维护证书"
|
||||||
touch /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
touch /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
|
echo '' > /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
touch /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
touch /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
||||||
# 定时任务
|
# 定时任务
|
||||||
echo "40 0 * * * bash /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh" > /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
echo "40 0 * * * bash /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh" > /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
||||||
# 备份
|
# 备份
|
||||||
crontab -l > /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
crontab -l > /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
||||||
|
domain=$1
|
||||||
echo "#!/usr/bin/env bash" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "#!/usr/bin/env bash" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "domain=$1" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "domain=\"${domain}\"" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
|
echo "eccPath=\`find ~/.acme.sh -name \"\${domain}_ecc\"|head -1\`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "modifyTime=`stat $1.key|sed -n '6,6p'|awk '{print $2" "$3" "$4" "$5}'`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "if [[ ! -z \${eccPath} ]]" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "modifyTime=`date +%s -d "${modifyTime}"`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "then" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "currentTime=`date +%s`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "modifyTime=\`stat \${eccPath}/\${domain}.key|sed -n '6,6p'|awk '{print \$2\" \"\$3\" \"\$4\" \"\$5}'\`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "stampDiff=`expr ${currentTime} - ${modifyTime}`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "modifyTime=\`date +%s -d \"\${modifyTime}\"\`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "minutes=`expr ${stampDiff} / 60`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "currentTime=\`date +%s\`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "if [[ ! -z ${modifyTime} ]] && [[ ! -z ${currentTime} ]] && [[ ! -z ${stampDiff} ]] && [[ ! -z ${minutes} ]] && [[ ${minutes} -lt '120' ]]" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "stampDiff=\`expr \${currentTime} - \${modifyTime}\`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
|
echo "minutes=\`expr \${stampDiff} / 60\`" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
|
echo "if [[ ! -z \${modifyTime} ]] && [[ ! -z \${currentTime} ]] && [[ ! -z \${stampDiff} ]] && [[ ! -z \${minutes} ]] && [[ \${minutes} -lt '120' ]]" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "then" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "then" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "nginx -s stop" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "nginx -s stop" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "~/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /etc/nginx/v2ray-agent-https/${domain}.crt --keypath /etc/nginx/v2ray-agent-https/${domain}.key --ecc >/dev/null" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "~/.acme.sh/acme.sh --installcert -d \${domain} --fullchainpath /etc/nginx/v2ray-agent-https/\${domain}.crt --keypath /etc/nginx/v2ray-agent-https/\${domain}.key --ecc >/dev/null" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "nginx" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "nginx" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
echo "fi" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo "fi" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
crontab /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
echo "fi" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
||||||
crontabResult=`crontab -l`
|
|
||||||
|
# crontab /etc/nginx/v2ray-agent-https/backup_crontab.cron
|
||||||
|
# crontabResult=\`crontab -l\`
|
||||||
if [[ -z `crontab -l|grep -v grep|grep 'reloadInstallTLS'` ]]
|
if [[ -z `crontab -l|grep -v grep|grep 'reloadInstallTLS'` ]]
|
||||||
then
|
then
|
||||||
echoContent green "添加定时维护证书"
|
echo
|
||||||
|
# echoContent green "添加定时维护证书"
|
||||||
else
|
else
|
||||||
echoContent red "添加定时维护证书失败"
|
echo
|
||||||
|
# echoContent red "添加定时维护证书失败"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
48
test.sh
48
test.sh
|
@ -1,23 +1,27 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
touch /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
domain="test1.am1z.xyz"
|
||||||
echo '' > /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
eccPath=`find ~/.acme.sh -name "${domain}_ecc"|head -1`
|
||||||
echo '#!/usr/bin/env bash' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
echo ${eccPath}
|
||||||
echo 'domain=$1' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
mkdir -p /tmp/tls
|
||||||
echo 'if [[ ! -z `find ~/.acme.sh/ -name ${domain}.key` ]]' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
touch /tmp/tls/tls.log
|
||||||
echo 'then' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
touch /tmp/tls/acme.log
|
||||||
echo ' key=`find ~/.acme.sh/ -name ${domain}.key|head -1`' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
if [[ ! -z ${eccPath} ]]
|
||||||
echo ' echo ${key}' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
then
|
||||||
echo ' modifyTime=`stat ${key}|sed -n '\'6,6p\''|awk '{print \$2\" \"\$3\" \"\$4\" \"\$5}'`' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
modifyTime=`stat ${eccPath}/${domain}.key|sed -n '6,6p'|awk '{print $2" "$3" "$4" "$5}'`
|
||||||
echo ' modifyTime=`date +%s -d "${modifyTime}"`' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
modifyTime=`date +%s -d "${modifyTime}"`
|
||||||
echo ' currentTime=`date +%s`' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
currentTime=`date +%s`
|
||||||
echo ' stampDiff=`expr ${currentTime} - ${modifyTime}`' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
stampDiff=`expr ${currentTime} - ${modifyTime}`
|
||||||
echo ' minutes=`expr ${stampDiff} / 60`' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
minutes=`expr ${stampDiff} / 60`
|
||||||
echo ' echo ${minutes}' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
status="正常"
|
||||||
echo ' if [[ ! -z ${modifyTime} ]] && [[ ! -z ${currentTime} ]] && [[ ! -z ${stampDiff} ]] && [[ ! -z ${minutes} ]] && [[ ${minutes} -lt '\'200000\'' ]]' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
reloadTime="暂无"
|
||||||
echo ' then' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
if [[ ! -z ${modifyTime} ]] && [[ ! -z ${currentTime} ]] && [[ ! -z ${stampDiff} ]] && [[ ! -z ${minutes} ]] && [[ ${minutes} -lt '120' ]]
|
||||||
echo ' echo "符合条件"' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
then
|
||||||
#echo ' nginx -s stop' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
nginx -s stop
|
||||||
#echo ' ~/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /etc/nginx/v2ray-agent-https/${domain}.crt --keypath /etc/nginx/v2ray-agent-https/${domain}.key --ecc' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
~/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /etc/nginx/v2ray-agent-https/${domain}.crt --keypath /etc/nginx/v2ray-agent-https/${domain}.key --ecc >> /tmp/tls/acme.log
|
||||||
echo ' fi' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
nginx
|
||||||
echo 'fi' >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
reloadTime=`date -d @${currentTime} +"%F %H:%M:%S"`
|
||||||
echo "exit 0" >> /etc/nginx/v2ray-agent-https/reloadInstallTLS.sh
|
fi
|
||||||
|
echo "域名:${domain},modifyTime:"`date -d @${modifyTime} +"%F %H:%M:%S"`,"定时任务执行时间:"`date -d @${currentTime} +"%F %H:%M:%S"`,"上次生成证书的时:"`expr ${minutes} / 1440`"天前","证书状态:"${status},"重新生成日期:"${reloadTime} >> /tmp/tls/tls.log
|
||||||
|
else
|
||||||
|
echo '无法找到证书路径' >> /tmp/tls/tls.log
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue