From a0a8981f0c3798f8f3f2deea3093f080e41c707b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristhian=20Mart=C3=ADnez=20Ochoa?= Date: Wed, 4 Apr 2018 13:49:24 -0500 Subject: [PATCH] delete site w ext-db unattended Delete site with external database now is unattended. --- lib/general | 18 ++++++++++++------ lib/sites | 11 +++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/general b/lib/general index a29f59c..c80a244 100644 --- a/lib/general +++ b/lib/general @@ -56,13 +56,19 @@ db_delete() { echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}" fi else - echo "" - echo "${gre}External DB found in $domain (Press 'Enter' key twice to skip and not delete)" - read -p "${blu}External DB root username [root]: " uroot - uroot=${uroot:-root} - read -p "External DB root password: " proot + if [[ $dbdatadel == "true" ]]; then + local dbdatauser=$(echo "${dbdata}" | cut -d',' -f 3 -s) + local dbdatapass=$(echo "${dbdata}" | cut -d',' -f 4 -s) + fi + if [[ -z $dbdatauser || -z $dbdatapass ]]; then + echo "" + echo "${gre}External DB found in $domain (Press 'Enter' key twice to skip and not delete)" + read -p "${blu}External DB root username [root]: " uroot + uroot=${uroot:-root} + read -p "External DB root password: " proot + fi if [[ $uroot == "root" && -z $proot ]]; then - echo "${red} Action aborted!" + echo "${red} Action aborted, database not deteted!" continue 1; else sudo mysql --connect-timeout=10 -h "$url" -P "$port" -u"$uroot" -p"$proot" -e "$dbsetup" diff --git a/lib/sites b/lib/sites index 5e42997..857565b 100644 --- a/lib/sites +++ b/lib/sites @@ -415,16 +415,23 @@ _EOF_ deletesite() { + if [[ -n $value ]]; then + dbdata=${value:1:-1} + local dbdatahost=$(echo "${dbdata}" | cut -d',' -f 1 -s) + [[ $dbdatahost == "external" ]] && dbdatadel=$(echo "${dbdata}" | cut -d',' -f 2 -s) + [[ $dbdatadel =~ ^(true|false)$ || $value == "force" ]] && local skip="true" + fi + # Determine if site is WP, so you should delete the DB too. if [[ -a /var/www/$domain/wp-config.php || -a /var/www/$domain/htdocs/wp-config.php ]]; then - if [[ $value != "force" ]]; then + if [[ $skip != "true" ]]; then echo "${blu}Delete Database [Y/n]?${end}" while read -r -n 1 -s dbdel; do local dbdel=${dbdel:-y} [[ $dbdel = [YyNn] ]] && break done else - dbdel="Y" + [[ $dbdatadel != "false" ]] && dbdel="Y" fi fi