Files
common-server-public/certmgr/getcert.sh
2025-06-15 17:13:26 +08:00

35 lines
1015 B
Bash

#!/bin/bash
# 定义变量
DOMAIN="registry.deepseak.icu" # 请替换为你的域名
EMAIL="hpuzhagnwei@163.com" # 请替换为你的邮箱地址
# 检查 Certbot 是否安装
if ! command -v certbot &> /dev/null
then
echo "Certbot 未安装,开始安装..."
sudo dnf install epel-release -y
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
sudo dnf config-manager --set-enabled crb
sudo dnf update
sudo dnf install certbot python3-certbot-nginx -y
fi
# 申请证书
echo "开始申请证书..."
sudo certbot certonly --nginx -d $DOMAIN --email $EMAIL --agree-tos --no-eff-email
# 检查证书是否申请成功
if [ $? -eq 0 ]; then
echo "证书申请成功!"
else
echo "证书申请失败,请检查错误信息。"
exit 1
fi
# 安装自动续期任务
# echo "安装自动续期任务..."
# (crontab -l 2>/dev/null; echo "0 12 * * * /usr/bin/certbot renew --quiet") | crontab -
# echo "自动续期任务安装成功!"