2024-09-23 01:19:11 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-09-23 01:55:26 +08:00
|
|
|
|
if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then
|
|
|
|
|
rm -rf ${HOME}/.acme.sh
|
2024-09-23 01:23:05 +08:00
|
|
|
|
declare mail
|
|
|
|
|
declare domain
|
|
|
|
|
read -p "请输入用来申请域名的邮箱:" mail
|
2024-09-23 01:56:58 +08:00
|
|
|
|
if [[ ! $mail =~ \b[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,6}\b ]];then
|
2024-09-23 01:23:05 +08:00
|
|
|
|
echo "邮箱不合法"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
curl https://get.acme.sh | sh -s "email=$mail"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
declare domain_str=''
|
2024-09-23 01:23:56 +08:00
|
|
|
|
echo "请输入需要申请SSL证书的域名"
|
2024-09-23 01:29:04 +08:00
|
|
|
|
while(true);do
|
2024-09-23 01:23:56 +08:00
|
|
|
|
read -p "不输入退出添加:" domain
|
|
|
|
|
if [[ -z $domain ]];then
|
|
|
|
|
break
|
2024-09-23 01:41:11 +08:00
|
|
|
|
elif [[ ! $domain =~ [\w+\.]+ ]];then
|
2024-09-23 01:23:56 +08:00
|
|
|
|
echo "域名不合法"
|
|
|
|
|
exit
|
2024-09-23 01:41:11 +08:00
|
|
|
|
else
|
|
|
|
|
domain_str="$domain_str -d $domain"
|
2024-09-23 01:23:56 +08:00
|
|
|
|
fi
|
|
|
|
|
done
|
2024-09-23 01:19:11 +08:00
|
|
|
|
if [[ -z $domain_str ]]; then
|
|
|
|
|
echo "需要添加的域名不能为空"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
declare pick_mode
|
2024-09-23 01:41:11 +08:00
|
|
|
|
echo "1.http验证"
|
|
|
|
|
echo "2.dns验证"
|
2024-09-23 01:52:03 +08:00
|
|
|
|
read -p "请选择验证模式:" pick_mode
|
2024-09-23 01:19:11 +08:00
|
|
|
|
|
|
|
|
|
case $pick_mode in
|
|
|
|
|
'1')
|
|
|
|
|
declare pick_start
|
|
|
|
|
echo "请到服务器将80和443端口开启,将域名解析到本机"
|
|
|
|
|
read -p "解析完成请输入 y:" pick_start
|
|
|
|
|
if [[ ! $pick_start =~ [Yy] ]];then
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
eval "${HOME}/.acme.sh/acme.sh --issue $domain_str --standalone"
|
|
|
|
|
;;
|
|
|
|
|
'2')
|
|
|
|
|
declare pick=0
|
|
|
|
|
declare -a mode_arr
|
|
|
|
|
mode_arr[1]="TXT记录"
|
|
|
|
|
mode_arr[2]='cloudflare'
|
2024-09-23 01:52:03 +08:00
|
|
|
|
for i in "${!mode_arr[@]}"; do
|
|
|
|
|
((pick++))
|
|
|
|
|
echo "${pick}. ${mode_arr[$i]}"
|
2024-09-23 01:19:11 +08:00
|
|
|
|
done
|
2024-09-23 01:52:03 +08:00
|
|
|
|
read -p "请选择验证模式:" pick_mode
|
2024-09-23 01:29:04 +08:00
|
|
|
|
if [[ ! $pick_mode =~ [1-${pick}] ]]; then
|
2024-09-23 01:19:11 +08:00
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
case ${mode_arr[$pick_mode]} in
|
|
|
|
|
'TXT记录')
|
2024-09-23 01:23:05 +08:00
|
|
|
|
declare domain
|
2024-09-23 01:53:07 +08:00
|
|
|
|
declare log_output=$(${HOME}/.acme.sh/acme.sh --issue --dns $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please)
|
2024-09-23 01:19:11 +08:00
|
|
|
|
declare domain=$( echo "$log_output" | grep "Domain:" | awk -F ": " '{print $2}')
|
|
|
|
|
declare txt_value=$(echo "$log_output" | grep "TXT value:" | awk -F ": " '{print $2}')
|
|
|
|
|
echo "请到dns系统解析TXT记录"
|
|
|
|
|
echo "域名: $domain"
|
|
|
|
|
echo "文本记录: $txt_value"
|
|
|
|
|
read -p "解析完成请输入 y:" pick
|
|
|
|
|
if [[ $pick =~ [Yy] ]]; then
|
|
|
|
|
eval "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please"
|
|
|
|
|
else
|
|
|
|
|
echo "解析完成后请输入下面的命令完成验证"
|
|
|
|
|
echo "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
'cloudflare')
|
|
|
|
|
declare CF_Key
|
|
|
|
|
declare CF_Email
|
|
|
|
|
read -p "请输入cloudflare的邮箱:" CF_Email
|
2024-09-23 01:56:58 +08:00
|
|
|
|
if [[ ! $CF_Email =~ \b[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,6}\b ]];then
|
2024-09-23 01:19:11 +08:00
|
|
|
|
echo "邮箱不合法"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
read -p "请输入cloudflare的密钥:" CF_Key
|
2024-09-23 01:37:10 +08:00
|
|
|
|
if [[ ! $CF_Key =~ \w+ ]];then
|
2024-09-23 01:19:11 +08:00
|
|
|
|
echo "密钥不合法"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
export CF_Key=$CF_Key
|
|
|
|
|
export CF_Email=$CF_Email
|
|
|
|
|
eval "${HOME}/.acme.sh/acme.sh --issue $domain_str --dns dns_cf"
|
|
|
|
|
esac
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|