From 27d94acd13de925017569526c26456f265d5afa9 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 18 Jun 2014 12:34:07 +0530 Subject: [PATCH] Added ee site delete functions --- bin/ee | 48 +++++++++---------- .../site/delete/ee_mod_delete_database.sh | 42 ++++++++++++++++ .../site/delete/ee_mod_delete_nginxconf.sh | 22 +++++++++ .../site/delete/ee_mod_delete_webroot.sh | 22 +++++++++ 4 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 src/modules/site/delete/ee_mod_delete_database.sh create mode 100644 src/modules/site/delete/ee_mod_delete_nginxconf.sh create mode 100644 src/modules/site/delete/ee_mod_delete_webroot.sh diff --git a/bin/ee b/bin/ee index 3ced34e6..5e8febd3 100644 --- a/bin/ee +++ b/bin/ee @@ -439,7 +439,7 @@ SETUPWPNETWORK() # Remove Database -REMOVEDB() +ee_mod_delete_database() { # HTML & PHP Website Doesn't Have Database head -n1 /etc/nginx/sites-available/$EE_DOMAIN | egrep -e 'HTML|PHP' &>> $EE_COMMAND_LOG @@ -456,16 +456,16 @@ REMOVEDB() # Remove Database # For Proper read Command Output stty echo - if [ "$1" = "no-prompt" ] + if [ "$1" = "--no-prompt" ] then # Assume yes - ANSWER="y" + ee_prompt="y" else # Ask user for confirmation - read -p "Are You Sure To Drop $EE_DB_NAME Database (y/n): " ANSWER + read -p "Are You Sure To Drop $EE_DB_NAME Database (y/n): " ee_prompt fi - if [ "$ANSWER" = "y" ] + if [ "$ee_prompt" = "y" ] then # Remove Database mysql -h $EE_MYSQL_HOST -u $EE_MYSQL_USER -p$EE_MYSQL_PASS -e "drop database \`$EE_DB_NAME\`" \ @@ -489,21 +489,21 @@ REMOVEDB() fi } -REMOVEFILES() +ee_mod_delete_webroot() { # Remove Webroot # For Proper read Command Output stty echo - if [ "$1" = "no-prompt" ] + if [ "$1" = "--no-prompt" ] then # Assume yes - ANSWER="y" + ee_prompt="y" else # Ask user for confirmation - read -p "Are You Sure To Remove $EE_DOMAIN Webroot (y/n): " ANSWER + read -p "Are You Sure To Remove $EE_DOMAIN Webroot (y/n): " ee_prompt fi - if [ "$ANSWER" = "y" ] + if [ "$ee_prompt" = "y" ] then # Remove Webroot rm -rf /var/www/$EE_DOMAIN || ee_lib_error "Unable To Remove $EE_DOMAIN Webroot" @@ -513,20 +513,20 @@ REMOVEFILES() fi } -ee_mod_remove_nginxCONF() +ee_mod_delete_nginxconf() { # Remove Nginx Configuration # For Proper read Command Output stty echo - if [ "$1" = "no-prompt" ] + if [ "$1" = "--no-prompt" ] then # Assume yes - ANSWER="y" + ee_prompt="y" else # Ask user for confirmation - read -p "Are You Sure To Remove $EE_DOMAIN Nginx Configuration (y/n): " ANSWER + read -p "Are You Sure To Remove $EE_DOMAIN Nginx Configuration (y/n): " ee_prompt fi - if [ "$ANSWER" = "y" ] + if [ "$ee_prompt" = "y" ] then # Remove Webroot rm -rf /etc/nginx/sites-available/$EE_DOMAIN /etc/nginx/sites-enabled/$EE_DOMAIN \ @@ -1478,23 +1478,23 @@ then then # Remove Database - REMOVEDB + ee_mod_delete_database elif [ "$SITEDELETEARG" = "--files" ] then # Remove Webroot - REMOVEFILES + ee_mod_delete_webroot elif [ "$SITEDELETEARG" = "--all" ] then # Remove All Database And Webroot - REMOVEDB - REMOVEFILES + ee_mod_delete_database + ee_mod_delete_webroot # Remove Nginx Configuration - ee_mod_remove_nginxCONF + ee_mod_delete_nginxconf # Reload Nginx NGINXRELOAD @@ -1504,15 +1504,15 @@ then EE_GIT_MESSAGE="Delete Website With $SITEDELETEARG Option: $EE_DOMAIN" ee_lib_git_commit - elif [ "$SITEDELETEARG" = "--all-no-prompt" ] + elif [ "$SITEDELETEARG" = "--all---no-prompt" ] then # Remove All Database And Webroot - REMOVEDB "no-prompt" - REMOVEFILES "no-prompt" + ee_mod_delete_database "--no-prompt" + ee_mod_delete_webroot "--no-prompt" # Remove Nginx Configuration - ee_mod_remove_nginxCONF "no-prompt" + ee_mod_delete_nginxconf "--no-prompt" # Reload Nginx NGINXRELOAD diff --git a/src/modules/site/delete/ee_mod_delete_database.sh b/src/modules/site/delete/ee_mod_delete_database.sh new file mode 100644 index 00000000..ecfe861f --- /dev/null +++ b/src/modules/site/delete/ee_mod_delete_database.sh @@ -0,0 +1,42 @@ +# Delete MySQL database + +function ee_mod_delete_database() +{ + # HTML & PHP website doesn't have database + head -n1 /etc/nginx/sites-available/$EE_DOMAIN | egrep -e 'HTML|PHP' &>> $EE_COMMAND_LOG + if [ $? -ne 0 ]; then + # Database details + local ee_db_name=$(grep DB_NAME /var/www/$EE_DOMAIN/*-config.php | cut -d"'" -f4) + local ee_db_user=$(grep DB_USER /var/www/$EE_DOMAIN/*-config.php | cut -d"'" -f4) + local ee_db_pass=$(grep DB_PASS /var/www/$EE_DOMAIN/*-config.php | cut -d"'" -f4) + local ee_db_host=$(grep DB_HOST /var/www/$EE_DOMAIN/*-config.php | cut -d"'" -f4) + ee_lib_echo_escape " DB_NAME = $ee_db_name \n DB_USER = $ee_db_user \n DB_HOST = $ee_db_host" + + if [ "$1" = "--no-prompt" ];then + # Delete database without any prompt + local ee_prompt="y" + else + # Ask user to confirm + read -p "Are you sure to drop $ee_db_name database (y/n): " ee_prompt + fi + + if [ "$ee_prompt" = "y" ]; then + # Drop database + mysql -e "drop database \`$ee_db_name\`" \ + || ee_lib_error "Unable to drop $ee_db_name database, exit status = " $? + + # Never drop root user + if [ "$ee_db_user" != "root" ]; then + # Drop database user + mysql -e "drop user '$ee_db_user'@'$ee_db_host'" \ + || ee_lib_error "Unable to drop database user $ee_db_user, exit status = " $? + # Flush privileges + mysql -e "flush privileges" \ + || ee_lib_error "Unable to flush MySQL privileges, exit status = " $? + fi + else + # Deny message + ee_lib_echo_fail "User denied to drop $ee_db_name database" + fi + fi +} diff --git a/src/modules/site/delete/ee_mod_delete_nginxconf.sh b/src/modules/site/delete/ee_mod_delete_nginxconf.sh new file mode 100644 index 00000000..3c216b39 --- /dev/null +++ b/src/modules/site/delete/ee_mod_delete_nginxconf.sh @@ -0,0 +1,22 @@ +# Delete NGINX configuration file + +function ee_mod_delete_nginxconf() +{ + + if [ "$1" = "--no-prompt" ];then + # Delete NGINX configuration without any prompt + local ee_prompt="y" + else + # Ask user to confirm + read -p "Are you sure to remove $EE_DOMAIN NGINX configuration (y/n): " ee_prompt + fi + + if [ "$ee_prompt" = "y" ]; then + # Delete $EE_DOMAIN NGINX configuration + rm -rf /etc/nginx/sites-available/$EE_DOMAIN /etc/nginx/sites-enabled/$EE_DOMAIN \ + || ee_lib_error "Unable to remove $EE_DOMAIN NGINX configuration, exit status = " $? + else + # Deny message + ee_lib_echo_fail "User denied to remove $EE_DOMAIN NGINX configuration" + fi +} diff --git a/src/modules/site/delete/ee_mod_delete_webroot.sh b/src/modules/site/delete/ee_mod_delete_webroot.sh new file mode 100644 index 00000000..718f814c --- /dev/null +++ b/src/modules/site/delete/ee_mod_delete_webroot.sh @@ -0,0 +1,22 @@ +# Delete webroot + +function ee_mod_delete_webroot() +{ + + if [ "$1" = "--no-prompt" ];then + # Delete webroot without any prompt + local ee_prompt="y" + else + # Ask user to confirm + read -p "Are you sure to remove $EE_DOMAIN webroot (y/n): " ee_prompt + fi + + if [ "$ee_prompt" = "y" ]; then + # Delete $EE_DOMAIN webroot + rm -rf /var/www/$EE_DOMAIN \ + || ee_lib_error "Unable to remove $EE_DOMAIN webroot, exit status = " $? + else + # Deny message + ee_lib_echo_fail "User denied to remove $EE_DOMAIN webroot" + fi +}