From 48f21340e496e7d35ce254f46857cabcc64230bc Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 11 Feb 2019 16:35:13 -0600 Subject: [PATCH] Update nodemgmt-scripts.sh --- nodemgmt-scripts.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index 0cb8e5fe..37d4e572 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -452,7 +452,6 @@ NEWCERT(){ yes | cp -rfH ${FOLDER}/cert-request.lastrun /etc/letsencrypt/cert-request.lastrun DIVIDER true echo -e "Since this certificate is tied to a site in NGINX, we will reload NGINX across the nodes." - echo echo -en "${idsCL[LightYellow]}Waiting for certificate replication across the nodes... ${idsCL[Default]}" checked=false timeout=`date --date='2 minutes' +%s` @@ -503,6 +502,66 @@ NEWCERT(){ fi } +DELSSL()){ + DEL_SSL=${2} + if [ -z ${DEL_SSL+x} ]; then + echo -e -n "${idsCL[LightCyan]}Delete what SSL site address: ${idsCL[Default]}" + read DEL_SSL + echo "" + fi + if [ ! -z ${DEL_SSL+x} ] && [ "${DEL_SSL}" != "" ]; then + echo -e "${idsCL[LightRed]}Deleting theb certificates for '${idsCL[Red]}${DEL_SSL}${idsCL[LightRed]}'...${idsCL[Default]}" + echo "" + + echo -en "${idsCL[LightRed]}Removing Files and Folders... ${idsCL[Default]}" + rm -rf /etc/letsencrypt/archive/${DEL_SITE} + rm -rf /etc/letsencrypt/live/${DEL_SITE} + rm -f /etc/letsencrypt/renewal/${DEL_SITE}.conf + echo -e "${idsCL[Green]}OK${idsCL[Default]}" + echo "" + echo -en "${idsCL[LightYellow]}Waiting for certificate replication between the nodes... ${idsCL[Default]}" + checked=false + timeout=`date --date='2 minutes' +%s` + until [ "${checked}" = "" ]; do + tchecked='' + for nip in "${NODE_HOSTS[@]}"; do + if [[ $(/sbin/ip -o -4 addr list ens192 | awk '{print $4}' | cut -d/ -f1) == *"${nip}"* ]]; then NCMD='' + else NCMD="ssh root@${nip}" + fi + if [ "${NCMD}" != "" ]; then + if ${NCMD} "[ -d /etc/letsencrypt/live/${DEL_SITE} ]"; then + tchecked+=false + else + tchecked+='' + fi + fi + done + checked=${tchecked} + if [ "`date +%s`" -gt "$timeout" ]; then + echo -e "${idsCL[Red]}Timeout${idsCL[Default]}" + timeout=true + break + fi + done + if [ "${timeout}" != "true" ]; then + echo -e "${idsCL[Green]}Completed${idsCL[Default]}" + fi + echo + SERVICE nginx reload + echo -e "${idsCL[LightRed]}The SSL certificate has been removed fromt be nodes.${idsCL[Default]}" + else + echo "Missing arguments" + echo "" + echo -e "Usage: ${idsCL[Yellow]}nodemgmt delsite${idsCL[Default]} {" + width=33 + printf "%-${width}s- %s\n" " -site {FQDN address}" "Site to delete" + printf "%-${width}s- %s\n" " -ssl {yes or [no]}" "Delete SSL certs as well" + printf "%-${width}s- %s\n" " -list" "List sites (same as running nodemgmt delsites)" + echo "}" + exit 1 + fi +} + CERTRENEW(){ echo -e "${idsCL[LightGreen]}Renewing Certificates...${idsCL[Default]}" echo @@ -1281,6 +1340,7 @@ if [ ${action-x} ]; then case $action in newcert) NEWCERT ${2};; certrenew) CERTRENEW;; + delssl) DELSSL ${2};; listcerts) LISTCERTS;; checkcerts) CHECK-CERTS;; nightlyrenew) NIGHTLYRENEW;;