From 0234d2207ed73954162834159eae9d37313dc41b Mon Sep 17 00:00:00 2001 From: lsy Date: Wed, 25 Sep 2024 18:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9acme=E5=92=8Cnginx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config/Web/acme.sh | 36 ++++++++++++++++++------------------ Config/Web/nginx.sh | 17 +++++------------ 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/Config/Web/acme.sh b/Config/Web/acme.sh index 0bee5bc..53f9286 100644 --- a/Config/Web/acme.sh +++ b/Config/Web/acme.sh @@ -1,9 +1,10 @@ #!/bin/bash declare pick_mode=$1 -declare domain_str=$2 +declare domain=$2 + if ! [[ $pick_mode == "nginx" ]]; then pick_mode="" - domain_str="" + domain="" fi if ! command -v socat &> /dev/null; then @@ -25,7 +26,6 @@ fi if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then rm -rf ${HOME}/.acme.sh declare mail - declare domain read -p "请输入用来申请域名的邮箱:" mail if [[ ! $mail =~ .*@.* ]];then echo "邮箱不合法" @@ -35,26 +35,27 @@ if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then curl https://get.acme.sh | sh -s "email=$mail" fi +declare domain_str -if [[ ! $domain_str ]];then +if [[ ! $domain ]];then echo "请输入需要申请SSL证书的域名" - while(true);do - read -p "不输入退出添加:" domain - if [[ -z $domain ]];then - break - elif [[ ! $domain =~ [\w+\.]+ ]];then + read -p "请输入要绑定的域名多个用 空格 隔开:" domain +fi + + +for i in ${domain} ; do + if [[ ! $i =~ [\w+\.]+ ]];then echo "域名不合法" exit else - domain_str="$domain_str -d $domain" + domain_str="$domain_str -d $i" fi - done - if [[ -z $domain_str ]]; then - echo "需要添加的域名不能为空" - exit - fi -fi +done +if [[ -z $domain_str ]]; then + echo "需要添加的域名不能为空" + exit +fi echo "1.http验证" echo "2.dns验证" @@ -87,7 +88,7 @@ EOF for (( i = 0; i < 6; i++ )); do 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 fi done @@ -109,7 +110,6 @@ EOF case ${mode_arr[$pick_mode]} in '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 -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}')) diff --git a/Config/Web/nginx.sh b/Config/Web/nginx.sh index acb70e2..3ace1c5 100644 --- a/Config/Web/nginx.sh +++ b/Config/Web/nginx.sh @@ -33,8 +33,8 @@ case $pick in declare ssl_certificate_key declare ssl_domain=$(echo "${domain}" | awk '{print $1}') - echo "ssl证书地址" - echo "1.自动申请" + echo "ssl证书" + echo "1.自动申请(默认)" echo "2.手动输入" read -p "请输入:" pick if [[ $pick == 2 ]]; then @@ -50,16 +50,9 @@ case $pick in ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key" fi else - echo "" - declare ssl_domain="" - for i in ${domain} ; do - if ! [[ $i =~ [\w\.]+ ]]; then - echo "域名输入错误" - exit - fi - ssl_domain="${ssl_domain} -d ${i}" - done - bash "${path_script}/Config/Web/acme.sh" "nginx" "${ssl_domain}" + echo "1.nginx(默认)" + read -p "请选择" pick + bash "${path_script}/Config/Web/acme.sh" "nginx" "${domain}" fi