From e63a9dc1d9746d1526d16788405db5ae38e49f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristhian=20Mart=C3=ADnez=20Ochoa?= Date: Sat, 27 Oct 2018 17:19:26 -0600 Subject: [PATCH] dbdelete improved - Errors when MySQL is not installed or not found and try to delete a DB. - Purge nginx now remove SSL Cronjobs. --- lib/general | 40 +++++++++++++++++----------------------- lib/sites | 4 ++-- plugins/site | 11 ++++++++--- plugins/stack | 5 +++++ 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/general b/lib/general index da64897..ae6def0 100644 --- a/lib/general +++ b/lib/general @@ -10,13 +10,6 @@ end=`tput sgr0` db_delete() { local domain="$1" - if [[ $(conf_read mysql-client) != "true" ]]; then - echo "${gre}MySQL Client is not installed and we need it to stablish a connection with your Database." - echo "Wait while we install MySQL Client... installing!!!${end}" - mysql_client_install > /dev/null 2>&1 & - echo "${gre}MySQL Client has been successfully installed!${end}" - fi - # Get dbname and dbuser of a WP site if [[ -a /var/www/$domain/wp-config.php ]]; then wpconfpath="/var/www/$domain/wp-config.php" @@ -39,8 +32,10 @@ db_delete() { done="1" if [[ $host == "localhost" ]]; then # Check if MySQL installed - if [[ ! -d /etc/mysql || $(conf_read mysql) != "true" ]]; then - echo "${red}[ERROR] Seems like MySQL is not installed or Webinoly can not detect it! ( $domain ) ${end}" + if [[ ! -d /etc/mysql || $(conf_read mysql) != "true" || $(conf_read mysql-client) != "true" ]]; then + echo "${red}[ERROR] Seems like MySQL is not installed or Webinoly can not detect it!" + echo " - Database can not be deleted -${blu} $domain ${end}" + exit 1 fi local ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt ) sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "$dbsetup" @@ -52,14 +47,10 @@ db_delete() { echo "" echo "${blu} Retry [Y/n]? " while read -r -n 1 -s answer; do - answer=${answer:-y} - if [[ $answer = [YyNn] ]]; then - break - fi + answer=${answer:-y} + [[ $answer = [YyNn] ]] && break done - if [[ $answer == [Nn] ]]; then - done="1" - fi + [[ $answer == [Nn] ]] && done="1" else echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}" fi @@ -79,6 +70,13 @@ db_delete() { echo "${red} Action aborted, database not deleted!" continue 1; else + if [[ $(conf_read mysql-client) != "true" ]]; then + echo "${gre}MySQL Client is not installed and we need it to stablish a connection with your Database." + echo "Wait while we install MySQL Client... installing!!!${end}" + mysql_client_install > /dev/null 2>&1 & + echo "${gre}MySQL Client has been successfully installed!${end}" + fi + sudo mysql --connect-timeout=10 -h "$url" -P "$port" -u"$uroot" -p"$proot" -e "$dbsetup" if [ $? != "0" ]; then done="0" @@ -88,14 +86,10 @@ db_delete() { echo "" echo "${blu} Retry [Y/n]? " while read -r -n 1 -s answer; do - answer=${answer:-y} - if [[ $answer = [YyNn] ]]; then - break - fi + answer=${answer:-y} + [[ $answer = [YyNn] ]] && break done - if [[ $answer == [Nn] ]]; then - done="1" - fi + [[ $answer == [Nn] ]] && done="1" else echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}" fi diff --git a/lib/sites b/lib/sites index c20d535..beba165 100644 --- a/lib/sites +++ b/lib/sites @@ -168,7 +168,7 @@ wpinstall() { if [[ $dbhost == "localhost" && $setupmysql == [yY] && $(conf_read mysql) != "true" ]]; then echo "${red} [ERROR] MySQL is not installed or localhost was not found!${blu}" done="0" - continue 1; + [[ $wp == 1 ]] && continue 1 || exit 1 fi # Check if localhost or external DB if [[ $dbhost != "localhost" && $setupmysql == [yY] ]]; then @@ -467,7 +467,7 @@ deletesite() { fi fi - [[ $dbdel == [yY] ]] && db_delete $domain + [[ $dbdel == [yY] ]] && db_delete $domain & # Delete site files sudo rm /etc/nginx/sites-available/$domain diff --git a/plugins/site b/plugins/site index f958578..218074f 100644 --- a/plugins/site +++ b/plugins/site @@ -141,11 +141,14 @@ elif [[ "$domain" == "-delete-all" && -z "$type" && -z "$cache" ]]; then domi=$(echo $site | cut -f 4 -d "/") # List sites then will be deleted if [[ $domi != "html" && $domi != $(conf_read tools-port) ]]; then + # Determina if site is WP (so has DB to delete) + [[ -a $site/wp-config.php || -a $site/htdocs/wp-config.php ]] && db_delete $domi & + sudo rm -rf /etc/nginx/sites-available/$domi + sudo rm -rf /etc/nginx/sites-enabled/$domi + sudo rm -rf /var/www/$domi echo "${gre}Your site ${blu}${domi}${gre} has been successfully deleted! ${end}" fi - # Determina if site is WP (so has DB to delete) - [[ -a $site/wp-config.php || -a $site/htdocs/wp-config.php ]] && db_delete $domi done # List all remaining sites (parked and proxy) @@ -153,11 +156,13 @@ elif [[ "$domain" == "-delete-all" && -z "$type" && -z "$cache" ]]; then do domi=$(echo $site | cut -f 5 -d "/") if [[ $domi != "html" && $domi != "default" && $domi != $(conf_read tools-port) ]]; then + sudo rm -rf /etc/nginx/sites-available/$domi + sudo rm -rf /etc/nginx/sites-enabled/$domi echo "${gre}Your site ${blu}${domi}${gre} has been successfully deleted! ${end}" fi done - # Delete all files + # Delete all files - double check! # -rf is necessary to not generate an error when is empty. sudo rm -rf /etc/nginx/sites-available/!(default|$(conf_read tools-port)) sudo rm -rf /etc/nginx/sites-enabled/!(default|$(conf_read tools-port)) diff --git a/plugins/stack b/plugins/stack index 1dadc7b..3a9f13e 100644 --- a/plugins/stack +++ b/plugins/stack @@ -100,6 +100,11 @@ elif [[ $arg == "-purge" && ( $opt == "-html" || $opt == "-nginx" ) ]]; then api-events_update pn5 sudo apt-get -y purge certbot python-boto duplicity duply echo | sudo add-apt-repository --remove 'ppa:certbot/certbot' + # Remove SSL Cron + if [[ -a /var/spool/cron/crontabs/root ]]; then + sudo sed -i '/MAILTO=/d' /var/spool/cron/crontabs/root + sudo sed -i '/certbot renew/d' /var/spool/cron/crontabs/root + fi sudo apt-get -y autoremove sudo rm $HOME/www sudo rm $HOME/sites-available