Browse Source

Update e-mail function

bryan 3 years ago
parent
commit
35c706eceb
1 changed files with 19 additions and 11 deletions
  1. 19 11
      acme-cpanel.sh

+ 19 - 11
acme-cpanel.sh

@@ -26,6 +26,8 @@ unset SITES_DIR USEREMAIL DOMAIN_FILES DOMAIN_GROUPS DEPLOY_CMD_PREFIX ISSUE_CMD
 
 DEBUG="true" # quote this line to stop DEBUG mode and issue certificates for real, or use --force in user options
 METHOD="dns" # set the default method
+CONF="$HOME/.acme.sh/account.conf"
+ACME_SH="$HOME/.acme.sh/acme.sh"
 
 parse_input() {
 
@@ -41,10 +43,6 @@ parse_input() {
                     shift
                     METHOD="${1,,}"
                     ;;
-                --email|-e)
-                    shift
-                    USEREMAIL="$1"
-                    ;;
                 --force|-f)
                     unset DEBUG
                     ;;
@@ -87,10 +85,9 @@ parse_input() {
 
 
 interactive_dns() {
-    local conf="$HOME/.acme.sh/account.conf"
-    if [[ -f "$conf" ]] && grep -q "CPANELDNS_AUTH_PASSWORD" "$conf"; then
+    if [[ -f "$CONF" ]] && grep -q "CPANELDNS_AUTH_PASSWORD" "$CONF"; then
         echo "cPanel credentials already present, skipping configuration..."
-        echo "To rerun the configuration, first run 'rm $conf'"
+        echo "To rerun the configuration, first run 'rm $CONF'"
     else
         read -rp 'Enter your cPanel username: ' CPANELDNS_AUTH_ID
         echo
@@ -107,22 +104,32 @@ interactive_dns() {
 
 get_acme() {
     curl https://get.acme.sh | sh
+    # shellcheck disable=SC1090
     source "$HOME/.bashrc"
-    "$HOME/.acme.sh/acme.sh" --upgrade --auto-upgrade
+    "$ACME_SH" --upgrade --auto-upgrade
     [[ "$METHOD" == "dns" ]] && \
         curl -o "$HOME/.acme.sh/dnsapi/dns_cpaneldns.sh" https://raw.githubusercontent.com/cryobry/dns_cpaneldns/master/dns_cpaneldns.sh
 }
 
 
-update_email() { [[ -v USEREMAIL ]] && "$HOME/.acme.sh/acme.sh" --update-account --accountemail "${USEREMAIL}"; }
+update_email() { 
+    if [[ ! -v USEREMAIL ]]; then
+        if [[ -f "$CONF" ]] && line=$(grep -q "ACCOUNT_EMAIL" "$CONF"); then
+            echo "Reusing existing contact e-mail: ${line#ACCOUNT_EMAIL=}"
+            return 0
+        fi
+        read -rp 'Enter your contact e-mail (in case of renewal failures): ' USEREMAIL
+    fi
+    "$ACME_SH" --update-account --accountemail "${USEREMAIL}"
+}
 
 
 command_prefixes() {
     declare -ag ISSUE_CMD_PREFIX DEPLOY_CMD_PREFIX
-    ISSUE_CMD_PREFIX=("$HOME/.acme.sh/acme.sh" "--issue")
+    ISSUE_CMD_PREFIX=("$ACME_SH" "--issue")
     [[ "$METHOD" == "dns" ]] && ISSUE_CMD_PREFIX=("${ISSUE_CMD_PREFIX[@]}" "--dns" "dns_cpaneldns")
     [[ -v DEBUG ]] && ISSUE_CMD_PREFIX=("${ISSUE_CMD_PREFIX[@]}" "--staging") || ISSUE_CMD_PREFIX=("${ISSUE_CMD_PREFIX[@]}" "--force")
-    DEPLOY_CMD_PREFIX=("$HOME/.acme.sh/acme.sh" "--deploy" "--deploy-hook" "cpanel_uapi")
+    DEPLOY_CMD_PREFIX=("$ACME_SH" "--deploy" "--deploy-hook" "cpanel_uapi")
 }
 
 
@@ -225,6 +232,7 @@ main() {
     command_prefixes
     load_domains
     [[ "$METHOD" == "dns" ]] && interactive_dns
+    sanity_check
     issue_and_deploy_certs
 }