Browse Source

Added ee site delete functions

old-stable
gau1991 11 years ago
parent
commit
27d94acd13
  1. 48
      bin/ee
  2. 42
      src/modules/site/delete/ee_mod_delete_database.sh
  3. 22
      src/modules/site/delete/ee_mod_delete_nginxconf.sh
  4. 22
      src/modules/site/delete/ee_mod_delete_webroot.sh

48
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

42
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
}

22
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
}

22
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
}
Loading…
Cancel
Save