修改acme和nginx

This commit is contained in:
lsy 2024-09-25 18:17:48 +08:00
parent 2b367eb43a
commit 0234d2207e
2 changed files with 23 additions and 30 deletions

View File

@ -1,9 +1,10 @@
#!/bin/bash #!/bin/bash
declare pick_mode=$1 declare pick_mode=$1
declare domain_str=$2 declare domain=$2
if ! [[ $pick_mode == "nginx" ]]; then if ! [[ $pick_mode == "nginx" ]]; then
pick_mode="" pick_mode=""
domain_str="" domain=""
fi fi
if ! command -v socat &> /dev/null; then if ! command -v socat &> /dev/null; then
@ -25,7 +26,6 @@ fi
if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then
rm -rf ${HOME}/.acme.sh rm -rf ${HOME}/.acme.sh
declare mail declare mail
declare domain
read -p "请输入用来申请域名的邮箱:" mail read -p "请输入用来申请域名的邮箱:" mail
if [[ ! $mail =~ .*@.* ]];then if [[ ! $mail =~ .*@.* ]];then
echo "邮箱不合法" echo "邮箱不合法"
@ -35,26 +35,27 @@ if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then
curl https://get.acme.sh | sh -s "email=$mail" curl https://get.acme.sh | sh -s "email=$mail"
fi fi
declare domain_str
if [[ ! $domain_str ]];then if [[ ! $domain ]];then
echo "请输入需要申请SSL证书的域名" echo "请输入需要申请SSL证书的域名"
while(true);do read -p "请输入要绑定的域名多个用 空格 隔开:" domain
read -p "不输入退出添加:" domain fi
if [[ -z $domain ]];then
break
elif [[ ! $domain =~ [\w+\.]+ ]];then for i in ${domain} ; do
if [[ ! $i =~ [\w+\.]+ ]];then
echo "域名不合法" echo "域名不合法"
exit exit
else else
domain_str="$domain_str -d $domain" domain_str="$domain_str -d $i"
fi fi
done done
if [[ -z $domain_str ]]; then if [[ -z $domain_str ]]; then
echo "需要添加的域名不能为空" echo "需要添加的域名不能为空"
exit exit
fi fi
fi
echo "1.http验证" echo "1.http验证"
echo "2.dns验证" echo "2.dns验证"
@ -87,7 +88,7 @@ EOF
for (( i = 0; i < 6; i++ )); do for (( i = 0; i < 6; i++ )); do
sleep 15 sleep 15
if [[ -d "${HOME}/.acme.sh/$(echo "${domain_str}" | awk '{print $2}')_ecc/fullchain.cer" ]]; then if [[ -d "${HOME}/.acme.sh/$(echo "${domain}" | awk '{print $2}')_ecc/fullchain.cer" ]]; then
break break
fi fi
done done
@ -109,7 +110,6 @@ EOF
case ${mode_arr[$pick_mode]} in case ${mode_arr[$pick_mode]} in
'TXT记录') 'TXT记录')
declare domain
declare log_output=$(${HOME}/.acme.sh/acme.sh --issue --dns $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please) declare log_output=$(${HOME}/.acme.sh/acme.sh --issue --dns $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please)
declare -a domain=($( echo "$log_output" | grep "Domain:" | awk -F ": " '{print $2}')) declare -a domain=($( echo "$log_output" | grep "Domain:" | awk -F ": " '{print $2}'))
declare -a txt_value=($(echo "$log_output" | grep "TXT value:" | awk -F ": " '{print $2}')) declare -a txt_value=($(echo "$log_output" | grep "TXT value:" | awk -F ": " '{print $2}'))

View File

@ -33,8 +33,8 @@ case $pick in
declare ssl_certificate_key declare ssl_certificate_key
declare ssl_domain=$(echo "${domain}" | awk '{print $1}') declare ssl_domain=$(echo "${domain}" | awk '{print $1}')
echo "ssl证书地址" echo "ssl证书"
echo "1.自动申请" echo "1.自动申请(默认)"
echo "2.手动输入" echo "2.手动输入"
read -p "请输入:" pick read -p "请输入:" pick
if [[ $pick == 2 ]]; then if [[ $pick == 2 ]]; then
@ -50,16 +50,9 @@ case $pick in
ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key" ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
fi fi
else else
echo "" echo "1.nginx(默认)"
declare ssl_domain="" read -p "请选择" pick
for i in ${domain} ; do bash "${path_script}/Config/Web/acme.sh" "nginx" "${domain}"
if ! [[ $i =~ [\w\.]+ ]]; then
echo "域名输入错误"
exit
fi
ssl_domain="${ssl_domain} -d ${i}"
done
bash "${path_script}/Config/Web/acme.sh" "nginx" "${ssl_domain}"
fi fi